Jelajahi Sumber

Switch out the underlying library to tinytuya.

pytuya is unmaintained, and there seem to be several improved versions since by Tradeface (also seems to be abandoned) and James Cox (tinytuya) which still seems to be actively maintained.

Hopefully this will improve reliability, especially with the 3.3 protocol version, which still seems flakey with pytuya.  We may need to look at using some of the higher level methods to take advantage of some of the improvements, as the current Device implementation works with some underscore methods that were probably intended to be internal.
Jason Rumney 5 tahun lalu
induk
melakukan
0a5b600a98

+ 8 - 5
README.md

@@ -6,6 +6,8 @@
 [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=make-all_tuya-local&metric=ncloc)](https://sonarcloud.io/dashboard?id=make-all_tuya-local)
 [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=make-all_tuya-local&metric=coverage)](https://sonarcloud.io/dashboard?id=make-all_tuya-local)
 
+This is a Home Assistant add-on to support Wi-fi devices running Tuya firmware without going via the Tuya cloud.  Using this integration does not stop your devices from sending status to the Tuya cloud, so this should not be seen as a security measure, rather it improves speed and reliability by using local connections, and may unlock some features of your device, or even unlock whole devices, that are not supported by the Tuya cloud API.  Currently the focus is mainly on climate devices, which are not well supported by other similar integrations. The long term plan is to overhaul the architecture to make adding new devices a matter of adding a single configuration file. Until that is done I will not be adding simpler devices like switches and lights which can be covered by [rospogrigio/localtuya](https://github.com/rospogrigio/localtuya/).
+
 The `tuya_local` component integrates Goldair WiFi-enabled [heaters](http://www.goldair.co.nz/product-catalogue/heating/wifi-heaters), [dehumidifiers](http://www.goldair.co.nz/product-catalogue/heating/dehumidifiers) and [fans](http://www.goldair.co.nz/product-catalogue/cooling/pedestal-fans/40cm-dc-quiet-fan-with-wifi-and-remote-gcpf315), Kogan WiFi-enabled [heaters](https://www.kogan.com/au/c/smarterhome-range/shop/heating-cooling/) and [plugs](https://www.kogan.com/au/shop/connected-home/smart-plug/), Andersson heaters, Eurom [heaters](https://eurom.nl/en/product-category/heating/wifi-heaters/), Purline [heaters](https://www.purline.es/hoti-m100--ean-8436545097380.htm) and Garden PAC pool [heatpumps](https://www.iot-pool.com/en/products/bomba-de-calor-garden-pac-full-inverter) into Home Assistant, enabling control of setting the following parameters via the UI and the following services:
 
 ### Climate devices
@@ -239,11 +241,12 @@ Please report any issues and feel free to raise pull requests.
 
 None of this would have been possible without some foundational discovery work to get me started:
 
-- [nikrolls](https://github.com/nikrolls)'s [homeassistant-goldair-climate](https://github.com/nikrolls/homeassistant-goldair-climate) was the starting point for expanding to non-Goldair devices as well
-- [TarxBoy](https://github.com/TarxBoy)'s [investigation using codetheweb/tuyapi](https://github.com/codetheweb/tuyapi/issues/31) to figure out the correlation of the cryptic DPS states 
-- [sean6541](https://github.com/sean6541)'s [tuya-homeassistant](https://github.com/sean6541/tuya-homeassistant) library giving an example of integrating Tuya devices with Home Assistant
-- [clach04](https://github.com/clach04)'s [python-tuya](https://github.com/clach04/python-tuya) library
-- [etamtlosz](https://github.com/etamtlosz) and [KiLLeRRaT](https://github.com/KiLLeRRaT) for their support and dev work towards GECO and GPCV heaters
+- [nikrolls](https://github.com/nikrolls)'s [homeassistant-goldair-climate](https://github.com/nikrolls/homeassistant-goldair-climate) was the starting point for expanding to non-Goldair devices as well.
+- [TarxBoy](https://github.com/TarxBoy)'s [investigation using codetheweb/tuyapi](https://github.com/codetheweb/tuyapi/issues/31) to figure out the correlation of the cryptic DPS states .
+- [sean6541](https://github.com/sean6541)'s [tuya-homeassistant](https://github.com/sean6541/tuya-homeassistant) library giving an example of integrating Tuya devices with Home Assistant.
+- [clach04](https://github.com/clach04)'s [python-tuya](https://github.com/clach04/python-tuya) library.
+- [jasonacox](https://github.com/jasonacox)'s [tinytuya](https://github.com/jasonacox/tinytuya) library which improves on the original.
+- [etamtlosz](https://github.com/etamtlosz) and [KiLLeRRaT](https://github.com/KiLLeRRaT) for their support and dev work towards GECO and GPCV heaters.
 - [botts7](https://github.com/botts7) for support towards widening Kogan SmartPlug support.
 - [awaismun](https://github.com/awaismun) for assistance in supporting Andersson heaters.
 - [FeikoJoosten](https://github.com/FeikoJoosten) for development of support for Eurom heaters.

+ 0 - 16
build-release.sh

@@ -1,16 +0,0 @@
-#!/usr/bin/env bash
-
-set -ex
-
-ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
-TEMP_DIR=`mktemp -d`
-CWD=`pwd`
-
-cd $TEMP_DIR
-cp -r "$ROOT_DIR/custom_components/goldair_climate" .
-cd goldair_climate
-rm -rf __pycache__ */__pycache__
-zip -r homeassistant-goldair-climate * .translations
-cp homeassistant-goldair-climate.zip "$CWD"
-cd "$CWD"
-rm -rf $TEMP_DIR

+ 2 - 2
custom_components/tuya_local/device.py

@@ -39,12 +39,12 @@ class TuyaLocalDevice(object):
             address (str): The network address.
             local_key (str): The encryption key.
         """
-        import pytuya
+        import tinytuya
 
         self._name = name
         self._api_protocol_version_index = None
         self._api_protocol_working = False
-        self._api = pytuya.Device(dev_id, address, local_key, "device")
+        self._api = tinytuya.Device(dev_id, address, local_key)
         self._refresh_task = None
         self._rotate_api_protocol_version()
 

+ 1 - 1
custom_components/tuya_local/manifest.json

@@ -6,6 +6,6 @@
     "issue_tracker": "https://github.com/make-all/tuya-local/issues",
   "dependencies": [],
   "codeowners": ["@make-all"],
-  "requirements": ["pycryptodome~=3.9","pytuya~=7.0.5"],
+  "requirements": ["pycryptodome~=3.9","tinytuya~=1.2.3"],
   "config_flow": true
 }

+ 1 - 1
requirements-dev.txt

@@ -1,6 +1,6 @@
 homeassistant~=0.110
 pycryptodome~=3.9
-pytuya~=7.0
+tinytuya~=1.2.3
 pytest~=5.4
 pytest-cov~=2.9
 black~=19.10b0

+ 1 - 1
requirements.txt

@@ -1,2 +1,2 @@
 pycryptodome~=3.9
-pytuya~=7.0
+tinytuya~=1.2.3

+ 3 - 3
tests/test_device.py

@@ -38,7 +38,7 @@ from .const import (
 
 class TestDevice(IsolatedAsyncioTestCase):
     def setUp(self):
-        device_patcher = patch("pytuya.Device")
+        device_patcher = patch("tinytuya.Device")
         self.addCleanup(device_patcher.stop)
         self.mock_api = device_patcher.start()
 
@@ -50,9 +50,9 @@ class TestDevice(IsolatedAsyncioTestCase):
             "Some name", "some_dev_id", "some.ip.address", "some_local_key", self.hass()
         )
 
-    def test_configures_pytuya_correctly(self):
+    def test_configures_tinytuya_correctly(self):
         self.mock_api.assert_called_once_with(
-            "some_dev_id", "some.ip.address", "some_local_key", "device"
+            "some_dev_id", "some.ip.address", "some_local_key"
         )
         self.assertIs(self.subject._api, self.mock_api())