Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix: status from a sub-device goes to its gateway #315

Merged
merged 8 commits into from
Jul 31, 2024

Conversation

Lurker00
Copy link

The last commit (2e28850) fixes a bug: a status from payload of a sub-device can be passed to its gateway. Though it is not a problem with fake gateways, which don't accept status changes, it's a big problem with real gateways. The examples are:

  • a sub-device is attached to the gateway but not to LocalTuya;
  • a sub-device is not added to the gateway's sub_devices list when the gateway is already connected (e.g. during LocalTuya current version start).

Tested in both cases, with BLE and ZIgbee sub-devices.

This is the last problem I found that prevented me to use real gateways in LocalTuya. Now I prefer and I'd recommend to add real gateways to LocalTuya, especially to those who has BLE devices.

By the way, I added some other small changes:

  • comments for pylint (1bc069a);
  • a fix for rare case, when the data used by an async task could be changed (21af3e1);
  • a fix for the case when an error happens during write from exchange()(7b0950f), which is expected to return a value in most calls.

Co-authored-by: Bander <[email protected]>
@Lurker00
Copy link
Author

Sorry I just woke up and mistyped the commit comment!

Comment on lines 904 to 914
if cid:
listener = listener.sub_devices.get(cid, listener)
device = self.dps_cache.get(cid, {})
# Don't pass sub-device's payload to the (fake)gateway!
listener = listener.sub_devices.get(cid, None)
status = self.dps_cache.get(cid, {})
else:
device = self.dps_cache.get("parent", {})
status = self.dps_cache.get("parent", {})

listener.status_updated(device)
if listener is not None:
listener.status_updated(status)
else:
self.debug(f"Payload for missing sub-device discarded: \"{decoded_message}\"")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if cid:
listener = listener.sub_devices.get(cid, listener)
device = self.dps_cache.get(cid, {})
# Don't pass sub-device's payload to the (fake)gateway!
listener = listener.sub_devices.get(cid, None)
status = self.dps_cache.get(cid, {})
else:
device = self.dps_cache.get("parent", {})
status = self.dps_cache.get("parent", {})
listener.status_updated(device)
if listener is not None:
listener.status_updated(status)
else:
self.debug(f"Payload for missing sub-device discarded: \"{decoded_message}\"")
if cid:
# Don't pass sub-device's payload to the (fake)gateway!
if not listener := listener.sub_devices.get(cid, None):
return self.debug(f"Payload for missing sub-device discarded: \"{decoded_message}\"")
status = self.dps_cache.get(cid, {})
else:
status = self.dps_cache.get("parent", {})
listener.status_updated(status)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It didn't allow me to apply the change. Commited.

@xZetsubou xZetsubou merged commit c886574 into xZetsubou:master Jul 31, 2024
2 checks passed
@Lurker00 Lurker00 deleted the fix-status_goes_to_wrong-device branch August 1, 2024 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants