mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-10-12 18:38:03 +00:00
Improve supported module checks for hub children (#1188)
No devices in `fixtures/smart/child` support the `get_device_time` or `get_device_usage` methods so this PR tests for whether the device is a hub child and marks those modules/methods as not supported. This prevents features being erroneously created on child devices. It also moves the logic for getting the time from the parent module behind getting it from the child module which was masking the creation of these unsupported modules.
This commit is contained in:
@@ -457,6 +457,11 @@ class SmartDevice(Device):
|
||||
for child in self._children.values():
|
||||
await child._initialize_features()
|
||||
|
||||
@property
|
||||
def _is_hub_child(self) -> bool:
|
||||
"""Returns true if the device is a child of a hub."""
|
||||
return self.parent is not None and self.parent.device_type is DeviceType.Hub
|
||||
|
||||
@property
|
||||
def is_cloud_connected(self) -> bool:
|
||||
"""Returns if the device is connected to the cloud."""
|
||||
@@ -485,8 +490,8 @@ class SmartDevice(Device):
|
||||
@property
|
||||
def time(self) -> datetime:
|
||||
"""Return the time."""
|
||||
if (self._parent and (time_mod := self._parent.modules.get(Module.Time))) or (
|
||||
time_mod := self.modules.get(Module.Time)
|
||||
if (time_mod := self.modules.get(Module.Time)) or (
|
||||
self._parent and (time_mod := self._parent.modules.get(Module.Time))
|
||||
):
|
||||
return time_mod.time
|
||||
|
||||
|
Reference in New Issue
Block a user