Fix broken support for 0d devices
This commit is contained in:
committed by
rospogrigio
parent
5d64cb4e18
commit
81c04bfc4e
@@ -186,11 +186,10 @@ class TuyaDevice(pytuya.TuyaListener):
|
|||||||
@callback
|
@callback
|
||||||
def status_updated(self, status):
|
def status_updated(self, status):
|
||||||
"""Device updated status."""
|
"""Device updated status."""
|
||||||
if "dps" in status:
|
self._status.update(status)
|
||||||
self._status.update(status["dps"])
|
|
||||||
|
|
||||||
signal = f"localtuya_{self._config_entry[CONF_DEVICE_ID]}"
|
signal = f"localtuya_{self._config_entry[CONF_DEVICE_ID]}"
|
||||||
async_dispatcher_send(self._hass, signal, self._status)
|
async_dispatcher_send(self._hass, signal, self._status)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def disconnected(self, exc):
|
def disconnected(self, exc):
|
||||||
|
@@ -315,12 +315,17 @@ class TuyaProtocol(asyncio.Protocol):
|
|||||||
self.dispatcher = self._setup_dispatcher()
|
self.dispatcher = self._setup_dispatcher()
|
||||||
self.on_connected = on_connected
|
self.on_connected = on_connected
|
||||||
self.heartbeater = None
|
self.heartbeater = None
|
||||||
|
self.dps_cache = {}
|
||||||
|
|
||||||
def _setup_dispatcher(self):
|
def _setup_dispatcher(self):
|
||||||
def _status_update(msg):
|
def _status_update(msg):
|
||||||
|
decoded_message = self._decode_payload(msg.payload)
|
||||||
|
if "dps" in decoded_message:
|
||||||
|
self.dps_cache.update(decoded_message["dps"])
|
||||||
|
|
||||||
listener = self.listener()
|
listener = self.listener()
|
||||||
if listener is not None:
|
if listener is not None:
|
||||||
listener.status_updated(self._decode_payload(msg.payload))
|
listener.status_updated(self.dps_cache)
|
||||||
|
|
||||||
return MessageDispatcher(self.log, _status_update)
|
return MessageDispatcher(self.log, _status_update)
|
||||||
|
|
||||||
@@ -414,7 +419,10 @@ class TuyaProtocol(asyncio.Protocol):
|
|||||||
|
|
||||||
async def status(self):
|
async def status(self):
|
||||||
"""Return device status."""
|
"""Return device status."""
|
||||||
return await self.exchange(STATUS)
|
status = await self.exchange(STATUS)
|
||||||
|
if "dps" in status:
|
||||||
|
self.dps_cache.update(status["dps"])
|
||||||
|
return self.dps_cache
|
||||||
|
|
||||||
async def heartbeat(self):
|
async def heartbeat(self):
|
||||||
"""Send a heartbeat message."""
|
"""Send a heartbeat message."""
|
||||||
@@ -436,7 +444,7 @@ class TuyaProtocol(asyncio.Protocol):
|
|||||||
# list of available dps experience shows that the dps available are usually
|
# list of available dps experience shows that the dps available are usually
|
||||||
# in the ranges [1-25] and [100-110] need to split the bruteforcing in
|
# in the ranges [1-25] and [100-110] need to split the bruteforcing in
|
||||||
# different steps due to request payload limitation (max. length = 255)
|
# different steps due to request payload limitation (max. length = 255)
|
||||||
detected_dps = {}
|
self.dps_cache = {}
|
||||||
ranges = [(2, 11), (11, 21), (21, 31), (100, 111)]
|
ranges = [(2, 11), (11, 21), (21, 31), (100, 111)]
|
||||||
|
|
||||||
for dps_range in ranges:
|
for dps_range in ranges:
|
||||||
@@ -450,12 +458,12 @@ class TuyaProtocol(asyncio.Protocol):
|
|||||||
self.log.warning("Failed to get status: %s", e)
|
self.log.warning("Failed to get status: %s", e)
|
||||||
raise
|
raise
|
||||||
if "dps" in data:
|
if "dps" in data:
|
||||||
detected_dps.update(data["dps"])
|
self.dps_cache.update(data["dps"])
|
||||||
|
|
||||||
if self.dev_type == "type_0a":
|
if self.dev_type == "type_0a":
|
||||||
return detected_dps
|
return self.dps_cache
|
||||||
self.log.debug("detected dps: %s", detected_dps)
|
self.log.debug("detected dps: %s", self.dps_cache)
|
||||||
return detected_dps
|
return self.dps_cache
|
||||||
|
|
||||||
def add_dps_to_request(self, dps_index):
|
def add_dps_to_request(self, dps_index):
|
||||||
"""Add a datapoint (DP) to be included in requests."""
|
"""Add a datapoint (DP) to be included in requests."""
|
||||||
|
Reference in New Issue
Block a user