Parcourir la source

Add support for protocol version 3.5

Introduced in the new tinytuya 1.10.0 (updated in manifest a few
commits back, now updated in dev requirements also).

May help with issue #359, though it does seem there are no 3.5 devices
in the market yet, as this change was made in tinytuya based on
documentation alone.
Jason Rumney il y a 3 ans
Parent
commit
443d5f90ec

+ 1 - 1
custom_components/tuya_local/const.py

@@ -6,4 +6,4 @@ CONF_DEVICE_ID = "device_id"
 CONF_LOCAL_KEY = "local_key"
 CONF_TYPE = "type"
 CONF_PROTOCOL_VERSION = "protocol_version"
-API_PROTOCOL_VERSIONS = [3.3, 3.1, 3.2, 3.4]
+API_PROTOCOL_VERSIONS = [3.3, 3.1, 3.2, 3.4, 3.5]

+ 1 - 1
custom_components/tuya_local/device.py

@@ -81,7 +81,7 @@ class TuyaLocalDevice(object):
         self._CACHE_TIMEOUT = 120
         # More attempts are needed in auto mode so we can cycle through all
         # the possibilities a couple of times
-        self._AUTO_CONNECTION_ATTEMPTS = 9
+        self._AUTO_CONNECTION_ATTEMPTS = 11
         self._SINGLE_PROTO_CONNECTION_ATTEMPTS = 3
         self._lock = Lock()
 

+ 1 - 1
requirements-dev.txt

@@ -5,4 +5,4 @@ pytest
 pytest-asyncio
 pytest-cov
 pycryptodome~=3.16.0
-tinytuya~=1.9.1
+tinytuya~=1.10.0

+ 1 - 1
requirements.txt

@@ -1,2 +1,2 @@
 pycryptodome~=3.16.0
-tinytuya~=1.9.1
+tinytuya~=1.10.0

+ 6 - 3
tests/test_device.py

@@ -115,7 +115,7 @@ class TestDevice(IsolatedAsyncioTestCase):
         self.mock_api().status.assert_called_once()
         self.assertEqual(self.subject._cached_state["1"], "called")
 
-    async def test_refresh_retries_up_to_nine_times(self):
+    async def test_refresh_retries_up_to_eleven_times(self):
         self.subject._api_protocol_working = False
         self.mock_api().status.side_effect = [
             Exception("Error"),
@@ -126,12 +126,14 @@ class TestDevice(IsolatedAsyncioTestCase):
             Exception("Error"),
             Exception("Error"),
             Exception("Error"),
+            Exception("Error"),
+            Exception("Error"),
             {"dps": {"1": False}},
         ]
 
         await self.subject.async_refresh()
 
-        self.assertEqual(self.mock_api().status.call_count, 9)
+        self.assertEqual(self.mock_api().status.call_count, 11)
         self.assertEqual(self.subject._cached_state["1"], False)
 
     async def test_refresh_clears_cache_after_allowed_failures(self):
@@ -161,11 +163,12 @@ class TestDevice(IsolatedAsyncioTestCase):
             Exception("Error"),
             Exception("Error"),
             Exception("Error"),
+            Exception("Error"),
         ]
         await self.subject.async_refresh()
 
         self.mock_api().set_version.assert_has_calls(
-            [call(3.1), call(3.2), call(3.4), call(3.3), call(3.1)]
+            [call(3.1), call(3.2), call(3.4), call(3.5), call(3.3), call(3.1)]
         )
 
     async def test_api_protocol_version_is_stable_once_successful(self):