mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-08-07 11:14:02 +00:00
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:
@@ -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."""
|
||||
|
Reference in New Issue
Block a user