From d6e7c7dec433c1c89e33efe6cb100da8f399d35d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Villagra?= Date: Sun, 28 Nov 2021 01:46:12 +0000 Subject: [PATCH] send updatedps with all detected dps by default --- custom_components/localtuya/common.py | 2 +- custom_components/localtuya/pytuya/__init__.py | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/custom_components/localtuya/common.py b/custom_components/localtuya/common.py index 30028af..badfabc 100644 --- a/custom_components/localtuya/common.py +++ b/custom_components/localtuya/common.py @@ -173,7 +173,7 @@ class TuyaDevice(pytuya.TuyaListener, pytuya.ContextualLogger): async def _async_refresh(self, _now): if self._interface is not None: - await self._interface.updatedps() + await self._interface.update_dps() async def close(self): """Close connection and stop re-connect loop.""" diff --git a/custom_components/localtuya/pytuya/__init__.py b/custom_components/localtuya/pytuya/__init__.py index ccde438..24b0268 100644 --- a/custom_components/localtuya/pytuya/__init__.py +++ b/custom_components/localtuya/pytuya/__init__.py @@ -21,6 +21,7 @@ Functions json = status() # returns json payload set_version(version) # 3.1 [default] or 3.3 detect_available_dps() # returns a list of available dps provided by the device + update_dps(dps) # sends update dps command add_dps_to_request(dp_index) # adds dp_index to the list of dps used by the # device (to be queried in the payload) set_dp(on, dp_index) # Set value of any dps index. @@ -503,10 +504,20 @@ class TuyaProtocol(asyncio.Protocol, ContextualLogger): """Send a heartbeat message.""" return await self.exchange(HEARTBEAT) - async def updatedps(self): - """Request device to update index.""" + async def update_dps(self, dps=None): + """ + Request device to update index. + + Args: + dps([int]): list of dps to update, default=all detected + """ if self.version == 3.3: - return await self.exchange(UPDATEDPS) + if dps is None: + if not self.dps_cache: + await self.detect_available_dps() + if self.dps_cache: + dps = [int(dp) for dp in self.dps_cache][:255] + return await self.exchange(UPDATEDPS, dps) return True async def set_dp(self, value, dp_index):