Generalize smartdevice child support (#775)

* Initialize children's modules (and features) using the child component negotiation results
* Set device_type based on the device response
* Print out child features in cli 'state'
* Add --child option to cli 'command' to allow targeting child devices
* Guard "generic" features like rssi, ssid, etc. only to devices which have this information

Note, we do not currently perform queries on child modules so some data may not be available. At the moment, a stop-gap solution to use parent's data is used but this is not always correct; even if the device shares the same clock and cloud connectivity, it may have its own firmware updates.
This commit is contained in:
Teemu R
2024-02-22 20:46:19 +01:00
committed by GitHub
parent f965b14021
commit 2b0721aea9
12 changed files with 198 additions and 99 deletions

View File

@@ -3,7 +3,7 @@ import logging
from abc import ABC, abstractmethod
from dataclasses import dataclass
from datetime import datetime
from typing import Any, Dict, List, Optional, Sequence, Union
from typing import Any, Dict, List, Mapping, Optional, Sequence, Union
from .credentials import Credentials
from .device_type import DeviceType
@@ -71,6 +71,8 @@ class Device(ABC):
self.modules: Dict[str, Any] = {}
self._features: Dict[str, Feature] = {}
self._parent: Optional["Device"] = None
self._children: Mapping[str, "Device"] = {}
@staticmethod
async def connect(
@@ -182,9 +184,13 @@ class Device(ABC):
return await self.protocol.query(request=request)
@property
@abstractmethod
def children(self) -> Sequence["Device"]:
"""Returns the child devices."""
return list(self._children.values())
def get_child_device(self, id_: str) -> "Device":
"""Return child device by its ID."""
return self._children[id_]
@property
@abstractmethod