forked from rospogrigio/localtuya
-
Notifications
You must be signed in to change notification settings - Fork 59
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
xZetsubou
merged 8 commits into
xZetsubou:master
from
Lurker00:fix-status_goes_to_wrong-device
Jul 31, 2024
Merged
Bug fix: status from a sub-device goes to its gateway #315
xZetsubou
merged 8 commits into
xZetsubou:master
from
Lurker00:fix-status_goes_to_wrong-device
Jul 31, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xZetsubou
reviewed
Jul 30, 2024
Co-authored-by: Bander <[email protected]>
Sorry I just woke up and mistyped the commit comment! |
xZetsubou
reviewed
Jul 31, 2024
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}\"") |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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:
exchange()
(7b0950f), which is expected to return a value in most calls.