Skip to content

Commit

Permalink
Add changes from upstream (#10)
Browse files Browse the repository at this point in the history
* Fix for AttributeError: 'TuyaMessage' object has no attribute 'release' error

* rospogrigio#711 Implemented m/p HVAC mode set

* Introduced pytuya with support for 3.4 protocol

* Introduced 3.4 protocol option in config flow

* Fixed HEARTBEAT command

* Added debugging

* Fixed requested DPs for type_0d devices

* Fixed negotiation and sequence numbers for protocol 3.4

* Fixed sequence numbering on status update

* Fixed tox issues

* Fixed tox issues

* Updated README.md and info.md

* Fixed tox issues

* Fix for version not being set yet when calling _setup_dispatcher

* Introduced the possibility to select which devices should have the pytuya debug enabled

* Introduced device debugging option in README.md and info.md

* Introduced pytuya with support for 3.4 protocol

* Introduced 3.4 protocol option in config flow

* Fixed HEARTBEAT command

* Added debugging

* Fixed requested DPs for type_0d devices

* Fixed negotiation and sequence numbers for protocol 3.4

* Fixed sequence numbering on status update

* Fixed tox issues

* Fixed tox issues

* Updated README.md and info.md

* Fixed tox issues

* Fix for version not being set yet when calling _setup_dispatcher

* Introduced abort in config flow if all entities are deselected when editing a device

* Introduced IT and PT translations

* Update manifest.json for 5.0.0

* New tuyadebug.tgz now supporting protocol 3.4

* Update bug_report.md

* Fix for unknown state of covers/shutters

* New tuyadebug.tgz now including a tinytuya test

* Force to int

* Adjust input to avoid putting a string into an int

* Adjust input to avoid putting a string into an int

* Swap to int

* Improved logging

* Improved stability and Fix local_key update to not be thwarted by retries

* Introduced update of local_key when editing a device

* Improved logging

* Tox fixes

* Tox fixes

* Tox fixes

* Fix for not reconnecting after 'giving up'

* Tox fixes

* Tox fixes, reduced to 3.9 only

* Add entities during 'Edit a device'

* revert the default region

* Fix depreciated async_get_registry

* Add HACS validation

* Remove extra key

* Update manifest.json

* Remove extra key

* Update hacs.json

* Add Hassfest validation

* Alphabetize manifest.json

Alphabetized manifest.json according to home assistant requirements.

* Delete combined.yaml

As described in KTibow/ha-blueprint, ha-blueprint is being retired and we should thereby switch over to hassfest and hacs validation.

* Update tox.yaml

Added workflow_dispatch

* Update tox.ini

* Reduced logging level for 'Command %d timed out waiting for sequence number'; set v.5.1.0

* Fixed tox errors

* Updated manifest.json

* Fix for socket.send() exceptions in the logs

* Fixing pylint error

* fix bug when climate entity is using default min/max temp and temp unit is F

The default min/max temps are in C but when the climate entity is set up with F this will cause incorrect boundary check and an inability to change the temperature from the home assistant entity UI widget.

* Allow calling localtuya.set_dp service by non-admin users

* Fixed initialization with API but no internet.

* Handle 3.4 protocol, fix CI (rospogrigio#1251)

* Use refresh interval in version 3.4
* Scan interval convert to integer
* Try to fix CI
* Try to fix CI

* Allow port reuse so that other integrations can read the same port (rospogrigio#1481)

Co-authored-by: rospogrigio <[email protected]>

* Fixing tox issues

* Replaced SUPPORT_* with enums, set minimum HA version in HACS configuration to 2024.1.0

* Add support for more ac/fan modes (rospogrigio#1389)

* Add support for more ac/fan modes

* Replace deprecated constants with enums

* Add support for ClimateEntityFeature.TURN_{ON,OFF}

* Fix swing log message

---------

Co-authored-by: Simon Tegelid <[email protected]>

* added dict get() instead of assuming keys exist; now handles config_flow setup failures without crashing

* feat: add climate entity support for Comfortbilt stoves

* refactor: change information for fork

* feat: add support for alarm

---------

Co-authored-by: sibowler <[email protected]>
Co-authored-by: Daan Kemper <[email protected]>
Co-authored-by: rospogrigio <[email protected]>
Co-authored-by: rospogrigio <[email protected]>
Co-authored-by: Daniel O'Connor <[email protected]>
Co-authored-by: GaoJing <[email protected]>
Co-authored-by: oven-lab <[email protected]>
Co-authored-by: nu <[email protected]>
Co-authored-by: Ovidiu Nitan <[email protected]>
Co-authored-by: Neal Joslin <[email protected]>
Co-authored-by: dulyts <[email protected]>
Co-authored-by: Luke Bonaccorsi <[email protected]>
Co-authored-by: Elad Bar <[email protected]>
Co-authored-by: Simon Tegelid <[email protected]>
Co-authored-by: Simon Tegelid <[email protected]>
Co-authored-by: [email protected] <[email protected]>
  • Loading branch information
17 people authored May 25, 2024
1 parent 408c6a5 commit 2a100ba
Show file tree
Hide file tree
Showing 31 changed files with 1,405 additions and 503 deletions.
30 changes: 13 additions & 17 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ assignees: ''
Provide details about your environment.
-->
- Localtuya version: <!-- plugin version from HACS, master, commit id -->
- Last working localtuya version (if known and relevant):
- Home Assistant Core version: <!-- Configuration => Info -->
- [] Are you using the Home Assistant Tuya Cloud component ? <!-- if yes, put a x between the two [] => [x] -->
- [] Are you using the Tuya App in parallel ? <!-- if yes, put a x between the two [] => [x] -->
- [] Does the device work using the Home Assistant Tuya Cloud component ? <!-- if yes, put a x between the two [] => [x] -->
- [] Does the device work using the Tinytuya (https://github.com/jasonacox/tinytuya) command line tool ? <!-- if yes, put a x between the two [] => [x] -->
- [] Was the device working with earlier versions of localtuya ? Which one? <!-- if yes, put a x between the two [] => [x] -->
- [] Are you using the Tuya/SmartLife App in parallel ? <!-- if yes, put a x between the two [] => [x] -->

## Steps to reproduce
<!--
Expand All @@ -37,32 +38,27 @@ assignees: ''
2.
3.

## Configuration `configuration.yaml` or `config_flow`
<!--
Fill this with the yaml or config_flow configuration of the failing device. Even if it seems unimportant to you.
Remove personal information and local key.
-->
```yaml

```

## DP dump
<!--
Paste here a DP dump, see https://github.com/rospogrigio/localtuya/wiki/HOWTO-get-a-DPs-dump
You can also try to qualify your device using the procedure described https://github.com/rospogrigio/localtuya/wiki/Qualifying-a-device
-->

## Provide Home Assistant taceback/logs
## Provide Home Assistant traceback/logs
<!--
Provide traces if they are relevant. If the problem is reproducible, try to set the log level to debug for this component at least:
In Dev Tools => Services:
Provide logs if they are relevant. In detail, it is useful to be able to compare working with non-working situations, such as HA logs compared to the output of the tuyadebug script or the tinytuya CLI tool.
To increase the debugging level of HA for the devices, check the "enable debug" button when configuring the device, and set the log level to debug for this component at least:
In configuration.yaml:
logger.set_level
custom_components.localtuya: debug
custom_components.localtuya.pytuya: debug
-->
```txt
```
put your log output between these markers
```


## Additional information
<!-- Put here any information that you think it may be relevant -->
26 changes: 0 additions & 26 deletions .github/workflows/combined.yaml

This file was deleted.

7 changes: 4 additions & 3 deletions .github/workflows/tox.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Tox PR CI

on: [pull_request]
on:
pull_request:
workflow_dispatch:

jobs:
build:
Expand All @@ -14,8 +16,7 @@ jobs:
platform:
- ubuntu-latest
python-version:
- 3.7
- 3.8
- 3.9
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: HACS Validate

on:
push:
pull_request:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:

jobs:
validate-hacs:
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v3"
- name: HACS validation
uses: "hacs/action@main"
with:
category: "integration"
- name: Hassfest validation
uses: home-assistant/actions/hassfest@master
35 changes: 32 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The following Tuya device types are currently supported:

Energy monitoring (voltage, current, watts, etc.) is supported for compatible devices.

> **Currently, only Tuya protocols 3.1, 3.3, and 3.4.**
> **Currently, Tuya protocols from 3.1 to 3.4 are supported.**
This repository's development began as code from [@NameLessJedi](https://github.com/NameLessJedi), [@mileperhour](https://github.com/mileperhour) and [@TradeFace](https://github.com/TradeFace). Their code was then deeply refactored to provide proper integration with Home Assistant environment, adding config flow and other features. Refer to the "Thanks to" section below.

Expand Down Expand Up @@ -161,6 +161,32 @@ You can obtain Energy monitoring (voltage, current) in two different ways:
unit_of_measurement: 'W'
```
# Climates
There are a multitude of Tuya based climates out there, both heaters,
thermostats and ACs. The all seems to be integrated in different ways and it's
hard to find a common DP mapping. Below are a table of DP to product mapping
which are currently seen working. Use it as a guide for your own mapping and
please contribute to the list if you have the possibility.
| DP | Moes BHT 002 | Qlima WMS S + SC52 (AB;AF) | Avatto |
|-----|---------------------------------------------------------|---------------------------------------------------------|--------------------------------------------|
| 1 | ID: On/Off<br>{true, false} | ID: On/Off<br>{true, false} | ID: On/Off<br>{true, false} |
| 2 | Target temperature<br>Integer, scaling: 0.5 | Target temperature<br>Integer, scaling 1 | Target temperature<br>Integer, scaling 1 |
| 3 | Current temperature<br>Integer, scaling: 0.5 | Current temperature<br>Integer, scaling: 1 | Current temperature<br>Integer, scaling: 1 |
| 4 | Mode<br>{0, 1} | Mode<br>{"hot", "wind", "wet", "cold", "auto"} | ? |
| 5 | Eco mode<br>? | Fan mode<br>{"strong", "high", "middle", "low", "auto"} | ? |
| 15 | Not supported | Supported, unknown<br>{true, false} | ? |
| 19 | Not supported | Temperature unit<br>{"c", "f"} | ? |
| 23 | Not supported | Supported, unknown<br>Integer, eg. 68 | ? |
| 24 | Not supported | Supported, unknown<br>Integer, eg. 64 | ? |
| 101 | Not supported | Outdoor temperature<br>Integer. Scaling: 1 | ? |
| 102 | Temperature of external sensor<br>Integer, scaling: 0.5 | Supported, unknown<br>Integer, eg. 34 | ? |
| 104 | Supported, unknown<br>{true, false(?)} | Not supported | ? |
[Moes BHT 002](https://community.home-assistant.io/t/moes-bht-002-thermostat-local-control-tuya-based/151953/47)
[Avatto thermostat](https://pl.aliexpress.com/item/1005001605377377.html?gatewayAdapt=glo2pol)
# Debugging
Whenever you write a bug report, it helps tremendously if you include debug logs directly (otherwise we will just ask for them and it will take longer). So please enable debug logs like this and include them in your issue:
Expand All @@ -170,8 +196,11 @@ logger:
default: warning
logs:
custom_components.localtuya: debug
custom_components.localtuya.pytuya: debug
```
Then, edit the device that is showing problems and check the "Enable debugging for this device" button.
# Notes:
* Do not declare anything as "tuya", such as by initiating a "switch.tuya". Using "tuya" launches Home Assistant's built-in, cloud-based Tuya integration in lieu of localtuya.
Expand All @@ -183,8 +212,6 @@ logger:
* Everything listed in https://github.com/rospogrigio/localtuya-homeassistant/issues/15
* Support devices that use Tuya protocol v.3.4
# Thanks to:
NameLessJedi https://github.com/NameLessJedi/localtuya-homeassistant and mileperhour https://github.com/mileperhour/localtuya-homeassistant being the major sources of inspiration, and whose code for switches is substantially unchanged.
Expand All @@ -193,6 +220,8 @@ TradeFace, for being the only one to provide the correct code for communication
sean6541, for the working (standard) Python Handler for Tuya devices.
jasonacox, for the TinyTuya project from where I could import the code to communicate with devices using protocol 3.4.
postlund, for the ideas, for coding 95% of the refactoring and boosting the quality of this repo to levels hard to imagine (by me, at least) and teaching me A LOT of how things work in Home Assistant.
<a href="https://www.buymeacoffee.com/rospogrigio" target="_blank"><img src="https://bmc-cdn.nyc3.digitaloceanspaces.com/BMC-button-images/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: auto !important;width: auto !important;" ></a>
Expand Down
22 changes: 12 additions & 10 deletions custom_components/localtuya/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,16 @@ def _device_discovered(device):
)
new_data[ATTR_UPDATED_AT] = str(int(time.time() * 1000))
hass.config_entries.async_update_entry(entry, data=new_data)
device = hass.data[DOMAIN][TUYA_DEVICES][device_id]
if not device.connected:
device.async_connect()

elif device_id in hass.data[DOMAIN][TUYA_DEVICES]:
# _LOGGER.debug("Device %s found with IP %s", device_id, device_ip)
_LOGGER.debug("Device %s found with IP %s", device_id, device_ip)

device = hass.data[DOMAIN][TUYA_DEVICES].get(device_id)
if not device:
_LOGGER.warning(f"Could not find device for device_id {device_id}")
elif not device.connected:
device.async_connect()

device = hass.data[DOMAIN][TUYA_DEVICES][device_id]
if not device.connected:
device.async_connect()

def _shutdown(event):
"""Clean up resources when shutting down."""
Expand All @@ -167,7 +168,7 @@ async def _async_reconnect(now):
_handle_reload,
)

hass.helpers.service.async_register_admin_service(
hass.services.async_register(
DOMAIN, SERVICE_SET_DP, _handle_set_dp, schema=SERVICE_SET_DP_SCHEMA
)

Expand Down Expand Up @@ -255,8 +256,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
res = await tuya_api.async_get_access_token()
if res != "ok":
_LOGGER.error("Cloud API connection failed: %s", res)
_LOGGER.info("Cloud API connection succeeded.")
res = await tuya_api.async_get_devices_list()
else:
_LOGGER.info("Cloud API connection succeeded.")
res = await tuya_api.async_get_devices_list()
hass.data[DOMAIN][DATA_CLOUD] = tuya_api

async def setup_entities(device_ids):
Expand Down
Loading

0 comments on commit 2a100ba

Please sign in to comment.