Skip to content

Commit

Permalink
"delay" parameter for "status" method
Browse files Browse the repository at this point in the history
  • Loading branch information
Lurker00 committed Jul 18, 2024
1 parent d2bf8ce commit af1a73a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion custom_components/localtuya/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ async def _make_connection(self):

self.debug("Retrieving initial state")
# Usually we use status instead of detect_available_dps, but some device doesn't reports all dps when ask for status.
status = await self._interface.status(cid=self._node_id)
status = await self._interface.status(self._node_id)
if status is None:
raise Exception("Failed to retrieve status")

Expand Down
9 changes: 6 additions & 3 deletions custom_components/localtuya/core/pytuya/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1110,9 +1110,9 @@ async def exchange(self, command, dps=None, nodeID=None, delay=True, payload=Non
return await self.exchange(command, dps, nodeID=nodeID)
return payload

async def status(self, cid=None):
async def status(self, cid, delay=True):
"""Return device status."""
status: dict = await self.exchange(command=DP_QUERY, nodeID=cid, delay=False)
status: dict = await self.exchange(command=DP_QUERY, nodeID=cid, delay=delay)

self.dps_cache.setdefault("parent", {})
if status and "dps" in status:
Expand Down Expand Up @@ -1196,12 +1196,13 @@ async def detect_available_dps(self, cid=None):

ranges = [(2, 11), (11, 21), (21, 31), (100, 111)]

delay = True
for dps_range in ranges:
# dps 1 must always be sent, otherwise it might fail in case no dps is found
# in the requested range
self.dps_to_request = {"1": None}
self.add_dps_to_request(range(*dps_range))
data = await self.status(cid=cid)
data = await self.status(cid, delay)
if cid and cid in data:
self.dps_cache.update({cid: data[cid]})
elif not cid and "parent" in data:
Expand All @@ -1210,6 +1211,8 @@ async def detect_available_dps(self, cid=None):
if self.dev_type == "type_0a" and not cid:
return self.dps_cache.get("parent", {})

delay = False

return self.dps_cache.get(cid or "parent", {})

def add_dps_to_request(self, dp_indicies):
Expand Down

0 comments on commit af1a73a

Please sign in to comment.