send updatedps with all detected dps by default

This commit is contained in:
Martín Villagra
2021-11-28 01:46:12 +00:00
parent e292524793
commit d6e7c7dec4
2 changed files with 15 additions and 4 deletions

View File

@@ -173,7 +173,7 @@ class TuyaDevice(pytuya.TuyaListener, pytuya.ContextualLogger):
async def _async_refresh(self, _now): async def _async_refresh(self, _now):
if self._interface is not None: if self._interface is not None:
await self._interface.updatedps() await self._interface.update_dps()
async def close(self): async def close(self):
"""Close connection and stop re-connect loop.""" """Close connection and stop re-connect loop."""

View File

@@ -21,6 +21,7 @@ Functions
json = status() # returns json payload json = status() # returns json payload
set_version(version) # 3.1 [default] or 3.3 set_version(version) # 3.1 [default] or 3.3
detect_available_dps() # returns a list of available dps provided by the device 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 add_dps_to_request(dp_index) # adds dp_index to the list of dps used by the
# device (to be queried in the payload) # device (to be queried in the payload)
set_dp(on, dp_index) # Set value of any dps index. set_dp(on, dp_index) # Set value of any dps index.
@@ -503,10 +504,20 @@ class TuyaProtocol(asyncio.Protocol, ContextualLogger):
"""Send a heartbeat message.""" """Send a heartbeat message."""
return await self.exchange(HEARTBEAT) return await self.exchange(HEARTBEAT)
async def updatedps(self): async def update_dps(self, dps=None):
"""Request device to update index.""" """
Request device to update index.
Args:
dps([int]): list of dps to update, default=all detected
"""
if self.version == 3.3: 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 return True
async def set_dp(self, value, dp_index): async def set_dp(self, value, dp_index):