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:
Steven B.
2024-10-23 16:17:27 +01:00
committed by GitHub
parent 048c84d72c
commit cd0a74ca96
4 changed files with 32 additions and 3 deletions

View File

@@ -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