mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-08-09 20:24:02 +00:00
Support smart child modules queries (#967)
Required for the P300 firmware update with `auto_off` module on child devices. Will query child modules for parent devices that are not hubs. Coverage will be fixed when the P300 fixture is added https://github.com/python-kasa/python-kasa/pull/915
This commit is contained in:
@@ -99,3 +99,11 @@ class AutoOff(SmartModule):
|
||||
sysinfo = self._device.sys_info
|
||||
|
||||
return self._device.time + timedelta(seconds=sysinfo["auto_off_remain_time"])
|
||||
|
||||
async def _check_supported(self):
|
||||
"""Additional check to see if the module is supported by the device.
|
||||
|
||||
Parent devices that report components of children such as P300 will not have
|
||||
the auto_off_status is sysinfo.
|
||||
"""
|
||||
return "auto_off_status" in self._device.sys_info
|
||||
|
@@ -3,6 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from ..device_type import DeviceType
|
||||
from ..deviceconfig import DeviceConfig
|
||||
@@ -34,7 +35,17 @@ class SmartChildDevice(SmartDevice):
|
||||
self.protocol = _ChildProtocolWrapper(self._id, parent.protocol)
|
||||
|
||||
async def update(self, update_children: bool = True):
|
||||
"""Noop update. The parent updates our internals."""
|
||||
"""Update child module info.
|
||||
|
||||
The parent updates our internal info so just update modules with
|
||||
their own queries.
|
||||
"""
|
||||
req: dict[str, Any] = {}
|
||||
for module in self.modules.values():
|
||||
if mod_query := module.query():
|
||||
req.update(mod_query)
|
||||
if req:
|
||||
self._last_update = await self.protocol.query(req)
|
||||
|
||||
@classmethod
|
||||
async def create(cls, parent: SmartDevice, child_info, child_components):
|
||||
|
@@ -149,7 +149,7 @@ class SmartDevice(Device):
|
||||
if "child_device" in self._components and not self.children:
|
||||
await self._initialize_children()
|
||||
|
||||
async def update(self, update_children: bool = True):
|
||||
async def update(self, update_children: bool = False):
|
||||
"""Update the device."""
|
||||
if self.credentials is None and self.credentials_hash is None:
|
||||
raise AuthenticationError("Tapo plug requires authentication.")
|
||||
@@ -167,9 +167,14 @@ class SmartDevice(Device):
|
||||
self._last_update = resp = await self.protocol.query(req)
|
||||
|
||||
self._info = self._try_get_response(resp, "get_device_info")
|
||||
|
||||
# Call child update which will only update module calls, info is updated
|
||||
# from get_child_device_list. update_children only affects hub devices, other
|
||||
# devices will always update children to prevent errors on module access.
|
||||
if update_children or self.device_type != DeviceType.Hub:
|
||||
for child in self._children.values():
|
||||
await child.update()
|
||||
if child_info := self._try_get_response(resp, "get_child_device_list", {}):
|
||||
# TODO: we don't currently perform queries on children based on modules,
|
||||
# but just update the information that is returned in the main query.
|
||||
for info in child_info["child_device_list"]:
|
||||
self._children[info["device_id"]]._update_internal_state(info)
|
||||
|
||||
@@ -352,8 +357,7 @@ class SmartDevice(Device):
|
||||
@property
|
||||
def time(self) -> datetime:
|
||||
"""Return the time."""
|
||||
# TODO: Default to parent's time module for child devices
|
||||
if self._parent and Module.Time in self.modules:
|
||||
if self._parent and Module.Time in self._parent.modules:
|
||||
_timemod = self._parent.modules[Module.Time]
|
||||
else:
|
||||
_timemod = self.modules[Module.Time]
|
||||
|
Reference in New Issue
Block a user