Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions miio/devicestatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def __new__(metacls, name, bases, namespace, **kwargs):
cls._sensors: Dict[str, SensorDescriptor] = {}
cls._settings: Dict[str, SettingDescriptor] = {}

cls._parent: Optional["DeviceStatus"] = None
cls._embedded: Dict[str, "DeviceStatus"] = {}

descriptor_map = {
Expand Down Expand Up @@ -117,6 +118,7 @@ def embed(self, other: "DeviceStatus"):
other_name = str(other.__class__.__name__)

self._embedded[other_name] = other
other._parent = self # type: ignore[attr-defined]

for name, sensor in other.sensors().items():
final_name = f"{other_name}__{name}"
Expand Down
1 change: 1 addition & 0 deletions miio/tests/test_devicestatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ def sub_sensor(self):
main.embed(sub)
sensors = main.sensors()
assert len(sensors) == 2
assert sub._parent == main

assert getattr(main, sensors["main_sensor"].property) == "main"
assert getattr(main, sensors["SubStatus__sub_sensor"].property) == "sub"
Expand Down