mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-08-08 11:44:02 +00:00
Generalize smartdevice child support (#775)
* Initialize children's modules (and features) using the child component negotiation results * Set device_type based on the device response * Print out child features in cli 'state' * Add --child option to cli 'command' to allow targeting child devices * Guard "generic" features like rssi, ssid, etc. only to devices which have this information Note, we do not currently perform queries on child modules so some data may not be available. At the moment, a stop-gap solution to use parent's data is used but this is not always correct; even if the device shares the same clock and cloud connectivity, it may have its own firmware updates.
This commit is contained in:
@@ -57,16 +57,25 @@ class SmartModule(Module):
|
||||
"""
|
||||
q = self.query()
|
||||
q_keys = list(q.keys())
|
||||
# TODO: hacky way to check if update has been called.
|
||||
if q_keys[0] not in self._device._last_update:
|
||||
raise KasaException(
|
||||
f"You need to call update() prior accessing module data"
|
||||
f" for '{self._module}'"
|
||||
)
|
||||
query_key = q_keys[0]
|
||||
|
||||
dev = self._device
|
||||
|
||||
# TODO: hacky way to check if update has been called.
|
||||
# The way this falls back to parent may not always be wanted.
|
||||
# Especially, devices can have their own firmware updates.
|
||||
if query_key not in dev._last_update:
|
||||
if dev._parent and query_key in dev._parent._last_update:
|
||||
_LOGGER.debug("%s not found child, but found on parent", query_key)
|
||||
dev = dev._parent
|
||||
else:
|
||||
raise KasaException(
|
||||
f"You need to call update() prior accessing module data"
|
||||
f" for '{self._module}'"
|
||||
)
|
||||
|
||||
filtered_data = {k: v for k, v in dev._last_update.items() if k in q_keys}
|
||||
|
||||
filtered_data = {
|
||||
k: v for k, v in self._device._last_update.items() if k in q_keys
|
||||
}
|
||||
if len(filtered_data) == 1:
|
||||
return next(iter(filtered_data.values()))
|
||||
|
||||
|
Reference in New Issue
Block a user