From 4c7e17865fb15629d1754683e86a0830bdb1c66b Mon Sep 17 00:00:00 2001 From: Simone Chemelli Date: Tue, 15 Oct 2024 09:48:02 +0000 Subject: [PATCH] feat: add config and status for BLU TRV --- aioshelly/rpc_device/device.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/aioshelly/rpc_device/device.py b/aioshelly/rpc_device/device.py index 64759ec8..e62367c4 100644 --- a/aioshelly/rpc_device/device.py +++ b/aioshelly/rpc_device/device.py @@ -280,6 +280,7 @@ async def poll(self) -> None: self._status = results[0] if has_dynamic: self._parse_dynamic_components(results[1]) + await self._retrieve_blutrv_components(results[1]) async def _init_calls(self) -> None: """Make calls needed to initialize the device.""" @@ -309,7 +310,9 @@ async def _init_calls(self) -> None: if fetch_status: self._status = results.pop(0) if fetch_dynamic: - self._parse_dynamic_components(results.pop(0)) + components = results.pop(0) + self._parse_dynamic_components(components) + await self._retrieve_blutrv_components(components) async def script_list(self) -> list[ShellyScript]: """Get a list of scripts from 'Script.List'.""" @@ -509,6 +512,7 @@ async def get_dynamic_components(self) -> None: return components = await self.call_rpc("Shelly.GetComponents", {"dynamic_only": True}) self._parse_dynamic_components(components) + await self._retrieve_blutrv_components(components) def _supports_dynamic_components(self) -> bool: """Return True if device supports dynamic components.""" @@ -538,3 +542,26 @@ def _parse_dynamic_components(self, components: dict[str, Any]) -> None: for item in self._dynamic_components } ) + + async def _retrieve_blutrv_components(self, components: dict[str, Any]) -> None: + """Retrieve BLU TRV components.""" + if TYPE_CHECKING: + assert self._config + assert self._status + + for component in components.get("components", []): + _key = component["key"].split(":") + if _key[0] == "blutrv": + calls = [ + ( + "BluTRV.Call", + {"id": _key[1], "method": "Trv.GetConfig", "params": {"id": 0}}, + ), + ( + "BluTRV.Call", + {"id": _key[1], "method": "Trv.GetStatus", "params": {"id": 0}}, + ), + ] + results = await self.call_rpc_multiple(calls) + self._config.update({component["key"]: results[0]}) + self._status.update({component["key"]: results[1]})