2024-01-29 16:11:29 +00:00
|
|
|
"""Child device implementation."""
|
2024-02-02 16:29:14 +00:00
|
|
|
from typing import Optional
|
2024-01-29 16:11:29 +00:00
|
|
|
|
2024-02-02 16:29:14 +00:00
|
|
|
from ..device_type import DeviceType
|
2024-01-29 16:11:29 +00:00
|
|
|
from ..deviceconfig import DeviceConfig
|
|
|
|
from ..smartprotocol import SmartProtocol, _ChildProtocolWrapper
|
2024-02-04 15:20:08 +00:00
|
|
|
from .smartdevice import SmartDevice
|
2024-01-29 16:11:29 +00:00
|
|
|
|
|
|
|
|
2024-02-04 15:20:08 +00:00
|
|
|
class SmartChildDevice(SmartDevice):
|
2024-01-29 16:11:29 +00:00
|
|
|
"""Presentation of a child device.
|
|
|
|
|
|
|
|
This wraps the protocol communications and sets internal data for the child.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(
|
|
|
|
self,
|
2024-02-04 15:20:08 +00:00
|
|
|
parent: SmartDevice,
|
2024-01-29 16:11:29 +00:00
|
|
|
child_id: str,
|
|
|
|
config: Optional[DeviceConfig] = None,
|
|
|
|
protocol: Optional[SmartProtocol] = None,
|
|
|
|
) -> None:
|
|
|
|
super().__init__(parent.host, config=parent.config, protocol=parent.protocol)
|
|
|
|
self._parent = parent
|
|
|
|
self._id = child_id
|
|
|
|
self.protocol = _ChildProtocolWrapper(child_id, parent.protocol)
|
2024-02-02 16:29:14 +00:00
|
|
|
# TODO: remove the assignment after modularization is done,
|
|
|
|
# currently required to allow accessing time-related properties
|
|
|
|
self._time = parent._time
|
|
|
|
self._device_type = DeviceType.StripSocket
|
2024-01-29 16:11:29 +00:00
|
|
|
|
|
|
|
async def update(self, update_children: bool = True):
|
2024-02-02 16:29:14 +00:00
|
|
|
"""Noop update. The parent updates our internals."""
|
2024-01-29 16:11:29 +00:00
|
|
|
|
2024-02-02 16:29:14 +00:00
|
|
|
def update_internal_state(self, info):
|
|
|
|
"""Set internal state for the child."""
|
|
|
|
# TODO: cleanup the _last_update, _sys_info, _info, _data mess.
|
|
|
|
self._last_update = self._sys_info = self._info = info
|
2024-01-29 16:11:29 +00:00
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return f"<ChildDevice {self.alias} of {self._parent}>"
|