Merge remote-tracking branch 'upstream/master' into feat/parent_child_updates

This commit is contained in:
sdb9696
2024-07-02 14:40:08 +01:00
31 changed files with 1360 additions and 206 deletions

View File

@@ -333,10 +333,12 @@ class IotStripPlug(IotPlug):
The plug inherits (most of) the system information from the parent.
"""
_parent: IotStrip
def __init__(self, host: str, parent: IotStrip, child_id: str) -> None:
super().__init__(host)
self.parent = parent
self._parent = parent
self.child_id = child_id
self._last_update = parent._last_update
self._set_sys_info(parent.sys_info)
@@ -400,14 +402,15 @@ class IotStripPlug(IotPlug):
update_children_or_parent = False
if update_children_or_parent:
await self.parent._update(called_from_child=self)
await self._parent._update(called_from_child=self)
else:
await self._update()
async def _update(self):
"""Query the device to update the data.
Needed for properties that are decorated with `requires_update`.
Internal implementation to allow patching of public update in the cli
or test framework.
"""
await self._modular_update({})
for module in self._modules.values():
@@ -429,7 +432,7 @@ class IotStripPlug(IotPlug):
self, target: str, cmd: str, arg: dict | None = None, child_ids=None
) -> Any:
"""Override query helper to include the child_ids."""
return await self.parent._query_helper(
return await self._parent._query_helper(
target, cmd, arg, child_ids=[self.child_id]
)
@@ -490,13 +493,15 @@ class IotStripPlug(IotPlug):
@requires_update
def model(self) -> str:
"""Return device model for a child socket."""
sys_info = self.parent.sys_info
sys_info = self._parent.sys_info
return f"Socket for {sys_info['model']}"
def _get_child_info(self) -> dict:
"""Return the subdevice information for this device."""
for plug in self.parent.sys_info["children"]:
for plug in self._parent.sys_info["children"]:
if plug["id"] == self.child_id:
return plug
raise KasaException(f"Unable to find children {self.child_id}")
raise KasaException(
f"Unable to find children {self.child_id}"
) # pragma: no cover