add whitelist with 18,19,20

This commit is contained in:
Martín Villagra
2021-12-01 15:36:03 +00:00
parent 943bfa532e
commit 0db320ee36

View File

@@ -78,6 +78,9 @@ SUFFIX_VALUE = 0x0000AA55
HEARTBEAT_INTERVAL = 10 HEARTBEAT_INTERVAL = 10
# DPS that are known to be safe to use with update_dps (0x12) command
UPDATE_DPS_WHITELIST = [18, 19, 20] # Socket (Wi-Fi)
# This is intended to match requests.json payload at # This is intended to match requests.json payload at
# https://github.com/codetheweb/tuyapi : # https://github.com/codetheweb/tuyapi :
# type_0a devices require the 0a command as the status request # type_0a devices require the 0a command as the status request
@@ -489,15 +492,17 @@ class TuyaProtocol(asyncio.Protocol, ContextualLogger):
Request device to update index. Request device to update index.
Args: Args:
dps([int]): list of dps to update, default=all detected dps([int]): list of dps to update, default=detected&whitelisted
""" """
if self.version == 3.3: if self.version == 3.3:
if dps is None: if dps is None:
if not self.dps_cache: if not self.dps_cache:
await self.detect_available_dps() await self.detect_available_dps()
if self.dps_cache: if self.dps_cache:
dps = [int(dp) for dp in self.dps_cache][:255] dps = [int(dp) for dp in self.dps_cache]
self.debug("updatedps() entry (dps_cache %s)", self.dps_cache) # filter non whitelisted dps
dps = list(set(dps).intersection(set(UPDATE_DPS_WHITELIST)))
self.debug("updatedps() entry (dps %s, dps_cache %s)", dps, self.dps_cache)
payload = self._generate_payload(UPDATEDPS, dps) payload = self._generate_payload(UPDATEDPS, dps)
self.transport.write(payload) self.transport.write(payload)
return True return True