Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions tinytuya/Cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,10 +519,26 @@ def getdevices(self, verbose=False, oldlist=[], include_map=False):
for dev in changed_devices:
if 'product_id' in dev and dev['product_id'] == productid:
dev['mapping'] = mappings[productid]
# also set unchanged devices just in case the mapping changed
for dev in unchanged_devices:
if 'product_id' in dev and dev['product_id'] == productid:
dev['mapping'] = mappings[productid]
# also set unchanged devices just in case the mapping changed,
# but only if the new mapping is non-empty (guard against overwriting
# a good cached mapping with an empty result from a transient API failure)
if mappings[productid]:
for dev in unchanged_devices:
if 'product_id' in dev and dev['product_id'] == productid:
dev['mapping'] = mappings[productid]

# Fallback: restore old mapping for changed devices that got no mapping back
# (API failure, rate limit, etc.) — use the mapping from oldlist if available.
# Only fallback when the mapping is missing or explicitly None, so that an
# intentionally empty mapping {} (e.g. device with no DPs, cloud code 2009)
# is preserved rather than replaced with a potentially stale old mapping.
for dev in changed_devices:
if 'mapping' not in dev or dev['mapping'] is None:
dev_id = dev.get('id')
if dev_id and dev_id in old_devices:
old_mapping = old_devices[dev_id].get('mapping')
if old_mapping is not None:
dev['mapping'] = old_mapping

log.debug( 'changed: %d', len(changed_devices) )
log.debug( 'unchanged: %d', len(unchanged_devices) )
Expand Down
Loading