Add post update hook to module and use in smart LightEffect (#921)

Adds a post update hook to modules so they can calculate values and collections once rather than on each property access
This commit is contained in:
Steven B
2024-05-19 10:18:17 +01:00
committed by GitHub
parent 3490a1ef84
commit 9989d0f6ec
5 changed files with 46 additions and 23 deletions

View File

@@ -184,6 +184,13 @@ class SmartDevice(Device):
for info in child_info["child_device_list"]:
self._children[info["device_id"]]._update_internal_state(info)
# Call handle update for modules that want to update internal data
for module in self._modules.values():
module._post_update_hook()
for child in self._children.values():
for child_module in child._modules.values():
child_module._post_update_hook()
# We can first initialize the features after the first update.
# We make here an assumption that every device has at least a single feature.
if not self._features:
@@ -332,6 +339,9 @@ class SmartDevice(Device):
for feat in module._module_features.values():
self._add_feature(feat)
for child in self._children.values():
await child._initialize_features()
@property
def is_cloud_connected(self) -> bool:
"""Returns if the device is connected to the cloud."""