From cd476b42aecf742437acdcf588a19b01731b4c6f Mon Sep 17 00:00:00 2001
From: umu <46300268+xZetsubou@users.noreply.github.com>
Date: Wed, 30 Aug 2023 11:17:57 +0300
Subject: [PATCH] Tuya upgrades 35, sub_devices bump 6.0.0 etc... (#15)
* rewrite add device manually message.
* Add 7000 Port listening and reuse port
* App broadcasting and improve data decrypt
* Add auto protcol in config flow
* and supported protocols in const
* Add node ID to const
* Add settings contexts
* Add support for SubDevices and 3.5[Hope] in pytuya core
* Fix sample template
* clarify CID context
* ADD Tuya const
* add explain error into config_flow
* Clarify Error_values when try to connect!
* Report errors values if happend in core!
* add node_id to common.py
* update config_flow with many changes in PR edit: 1
* remove debug message
* comment
* increase timeout to 8secs.
* revert increase timeout
* typo
* fix a bug when import template [need rewrite dev_config)
* rework on helpers
* update dps function version uses constant versions
* remove duplicated function
* cleansup codes
* Fix unique IDs already exists. solve_issue_1 in PR
* Rework config_flow actions Menu instead of radiobox
* Spaces on Cover Commands Labels
* Rename from `LocalTuya integration` to `Local Tuya`
* rewrite translation to menu init
* remove `CONF ACTION` and adjust `CONF CLOUD`
* add `data_description` en lang to template step
* Fix devices don't comeback after adding new device
* remove unnecessary contect func
* remove unnecessary contect func
* fix entity_category and some cleans
* clean up codes
* cleans up helpers
* for futrue things.
* pump version
* Give Docs when installing new integration.
* cleans up repo
---
.dependabot/config.yml | 19 -
README.md | 220 ++++-----
custom_components/localtuya/__init__.py | 50 +-
custom_components/localtuya/common.py | 23 +-
custom_components/localtuya/config_flow.py | 295 +++++++-----
custom_components/localtuya/const.py | 13 +-
custom_components/localtuya/cover.py | 6 +-
custom_components/localtuya/discovery.py | 71 ++-
custom_components/localtuya/helpers.py | 123 +++++
.../localtuya/helpers/templates.py | 72 ---
custom_components/localtuya/manifest.json | 4 +-
.../localtuya/pytuya/__init__.py | 440 +++++++++++++-----
.../localtuya/templates/sample_2g_switch.yaml | 4 +-
.../localtuya/translations/en.json | 29 +-
.../localtuya/translations/it.json | 6 +-
.../localtuya/translations/pt-BR.json | 6 +-
img/1-discovery.png | Bin 39087 -> 0 bytes
img/10-integration_configure.png | Bin 10229 -> 0 bytes
img/11-config_menu.png | Bin 14953 -> 0 bytes
img/2-device.png | Bin 29877 -> 0 bytes
img/3-entity_type.png | Bin 18659 -> 0 bytes
img/4-entity.png | Bin 33040 -> 0 bytes
img/5-success.png | Bin 13436 -> 0 bytes
img/6-project_date.png | Bin 59139 -> 0 bytes
img/7-auth_keys.png | Bin 66636 -> 0 bytes
img/8-user_id.png | Bin 73998 -> 0 bytes
img/9-cloud_setup.png | Bin 23243 -> 0 bytes
img/icon.png | Bin 39299 -> 0 bytes
img/icon@2x.png | Bin 119152 -> 0 bytes
img/logo-small.png | Bin 29130 -> 0 bytes
img/logo.png | Bin 69462 -> 0 bytes
img/logo@2x.png | Bin 179318 -> 0 bytes
info.md | 196 --------
33 files changed, 850 insertions(+), 727 deletions(-)
delete mode 100644 .dependabot/config.yml
create mode 100644 custom_components/localtuya/helpers.py
delete mode 100644 custom_components/localtuya/helpers/templates.py
delete mode 100644 img/1-discovery.png
delete mode 100644 img/10-integration_configure.png
delete mode 100644 img/11-config_menu.png
delete mode 100644 img/2-device.png
delete mode 100644 img/3-entity_type.png
delete mode 100644 img/4-entity.png
delete mode 100644 img/5-success.png
delete mode 100644 img/6-project_date.png
delete mode 100644 img/7-auth_keys.png
delete mode 100644 img/8-user_id.png
delete mode 100644 img/9-cloud_setup.png
delete mode 100644 img/icon.png
delete mode 100644 img/icon@2x.png
delete mode 100644 img/logo-small.png
delete mode 100644 img/logo.png
delete mode 100644 img/logo@2x.png
delete mode 100644 info.md
diff --git a/.dependabot/config.yml b/.dependabot/config.yml
deleted file mode 100644
index 0ac25411c..000000000
--- a/.dependabot/config.yml
+++ /dev/null
@@ -1,19 +0,0 @@
-version: 1
-update_configs:
- - package_manager: "python"
- directory: "/"
- update_schedule: "live"
- default_reviewers:
- - postlund
- - rospogrigio
- - ultratoto14
- default_labels:
- - dependencies
- default_assignees:
- - postlund
- - rospogrigio
- - ultratoto14
- automerged_updates:
- - match:
- dependency_type: "all"
- update_type: "all"
diff --git a/README.md b/README.md
index 97625333c..d28b1f1e4 100644
--- a/README.md
+++ b/README.md
@@ -1,52 +1,20 @@
![logo](https://github.com/rospogrigio/localtuya-homeassistant/blob/master/img/logo-small.png)
-
-
-[Preview!](https://user-images.githubusercontent.com/46300268/260274212-084d8784-df8b-4187-ae67-711e9aac4821.gif)
-```yaml
-Templates:
-The template is basically ready to go configs can be imported instead of choosing configs DPs names etc...
-
-IMPORTANT:
-there is now valid check atm config so make sure you're importing correct configs.
-
-the configs depends on the platform and what input does platform support read bottom.
-
-THERE Is 2 ways to make template:
-- 1st is write the yaml ur self:
- [ Keep in mind there is no valid check atm ]
-
-- 2st is to export ur device file from config flow. [ Recommended ]:
- in HA Dashboard go to [ localtuya -> Configure -> Edit Device * choose the device u want to export
- Export the device config then submit]
-Templates DIR:
- the configs will be exported in [custom_components/localtuya/templates]
-
-How to import:
--- When u add new device when the form [ Pick Entity type selection ]
- Import template Form will show up showing avaliable templates in templates folder.
-
--- templates in [custom_components/localtuya/templates]
- Templates files will load up with HA so adding files will require restarting HA to show up.
-```
-
-
The following Tuya device types are currently supported:
* Switches
@@ -58,81 +26,78 @@ The following Tuya device types are currently supported:
Energy monitoring (voltage, current, watts, etc.) is supported for compatible devices.
-> **Currently, Tuya protocols from 3.1 to 3.4 are supported.**
+
+
1. Open HACS and navigate to Integrations Section
+
Manual installation:
1. Download the source files from [releases](https://github.com/xZetsubou/localtuya/releases).
2. Extract/open the archive file go inside the directory `custom_components` and copy localtuya folder.
3. Paste the folder into `/config/custom_components` you can use `VSCode add-on, SMB < better or ssh` to reach /config folder
-# Usage:
-
-**NOTE: You must have your Tuya device's Key and ID in order to use LocalTuya. The easiest way is to configure the Cloud API account in the integration. If you choose not to do it, there are several ways to obtain the local_keys depending on your environment and the devices you own. A good place to start getting info is https://github.com/codetheweb/tuyapi/blob/master/docs/SETUP.md or https://pypi.org/project/tinytuya/.**
-
-
-**NOTE 2: If you plan to integrate these devices on a network that has internet and blocking their internet access, you must also block DNS requests (to the local DNS server, e.g. 192.168.1.1). If you only block outbound internet, then the device will sit in a zombie state; it will refuse / not respond to any connections with the localkey. Therefore, you must first connect the devices with an active internet connection, grab each device localkey, and implement the block.**
-
-
-# Adding the Integration
-
-
-**NOTE: starting from v4.0.0, configuration using YAML files is no longer supported. The integration can only be configured using the config flow.**
-
-
-To start configuring the integration, just press the "+ADD INTEGRATION" button in the Settings - Integrations page, and select LocalTuya from the drop-down menu.
-The Cloud API configuration page will appear, requesting to input your Tuya IoT Platform account credentials:
-
-![cloud_setup](https://github.com/rospogrigio/localtuya-homeassistant/blob/master/img/9-cloud_setup.png)
-
-To setup a Tuya IoT Platform account and setup a project in it, refer to the instructions for the official Tuya integration:
-https://www.home-assistant.io/integrations/tuya/
-The place to find the Client ID and Secret is described in this link (in the ["Get Authorization Key"](https://www.home-assistant.io/integrations/tuya/#get-authorization-key) paragraph), while the User ID can be found in the "Link Tuya App Account" subtab within the Cloud project:
-
-![user_id.png](https://github.com/rospogrigio/localtuya-homeassistant/blob/master/img/8-user_id.png)
+How to use templates
-Supported platforms
+
+
+HACS installation
+
2. Open the Overflow Menu (⋮) in the top right corner and click on Custom repositories
3. Paste `https://github.com/xZetsubou/localtuya` into the input field and select Integration from the category dropdown then click ADD.
4. Now the integration should be added search in for it and install it!
+Manual installation
+
-If you upgrade LocalTuya from v3.x.x or older, the config entry will automatically be migrated to the new setup. Everything should work as it did before the upgrade, apart from the fact that in the Integration tab you will see just one LocalTuya integration (showing the number of devices and entities configured) instead of several Integrations grouped within the LocalTuya Box. This will happen both if the old configuration was done using YAML files and with the config flow. Once migrated, you can just input your Tuya IoT account credentials to enable the support for the Cloud API (and benefit from the local_key retrieval and auto-update): see [Configuration menu](https://github.com/rospogrigio/localtuya#integration-configuration-menu). +Usually we use True `on` and False `off` commands for switches but if you have device that do more like single, double clicks and long press. there are 2 method to manage this devices: -If you had configured LocalTuya using YAML files, you can delete all its references from within the YAML files because they will no longer be considered so they might bring confusion (only the logger configuration part needs to be kept, of course, see [Debugging](https://github.com/rospogrigio/localtuya#debugging) ). +#### Method 1: +add the device as select. assuming your device uses `0, 1 and 3` values then as the config would be like this: +![image](https://github.com/xZetsubou/hass-localtuya/assets/46300268/f38ae38e-3a7a-43de-ac39-7942f75db28d) -# Energy monitoring values +#### Method 2: Call_Service +is to add the device any way you want as sensor or switch but doing action through HA do it with call_service +to set your actions: ( The best since set any value you want ). +```yaml +service: localtuya.set_dp +data: + device_id: 767823809c9c1f842393 # you devices_id + dp: 1 # The DP you want to control it + value: 0 # assuming 0 is single_click +``` -You can obtain Energy monitoring (voltage, current) in two different ways: +
+# Debugging @@ -212,21 +175,24 @@ logger: 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: +
++ +# Credits: 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. @@ -238,5 +204,5 @@ jasonacox, for the TinyTuya project from where I could import the code to commun 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. - - +
+Cf5uQvJz8_RKx~^
z0o1F)zwo!fLu|New-LMUy1Xv{h&b{K)m!eNhS9P8y21f8 &ob@4BTY^aq$;Nj
zZ{W49W^q1H&z3lHxHja*#~W2?mb2`Aaoq?KLaLl+>2QrC0driWox`w%To0q*v1QKD#M?=*KX%
zSYT5_G7nk(xn6X6JZp_<`!c}ZNmqJBb(6*us=CA5Eq_W8^|TsQ-~s#~?yCFH75)&O
zZPCu