Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add config and status for BLU TRV #688

Merged
merged 18 commits into from
Jan 9, 2025
Merged
2 changes: 2 additions & 0 deletions aioshelly/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,8 @@ class ShellyDevice:
MODEL_VINTAGE_V2,
}

BLU_TRV_IDENTIFIER = "blutrv"


class UndefinedType(Enum):
"""Singleton type for use with not set sentinel values."""
Expand Down
33 changes: 32 additions & 1 deletion aioshelly/rpc_device/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
process_ip_or_options,
)
from ..const import (
BLU_TRV_IDENTIFIER,
CONNECT_ERRORS,
DEVICE_INIT_TIMEOUT,
DEVICE_IO_TIMEOUT,
DEVICE_POLL_TIMEOUT,
FIRMWARE_PATTERN,
MODEL_BLU_GATEWAY_GEN3,
NOTIFY_WS_CLOSED,
VIRTUAL_COMPONENTS,
VIRTUAL_COMPONENTS_MIN_FIRMWARE,
Expand Down Expand Up @@ -280,6 +282,7 @@
self._status = results[0]
if has_dynamic:
self._parse_dynamic_components(results[1])
await self._retrieve_blutrv_components(results[1])

Check warning on line 285 in aioshelly/rpc_device/device.py

View check run for this annotation

Codecov / codecov/patch

aioshelly/rpc_device/device.py#L285

Added line #L285 was not covered by tests

async def _init_calls(self) -> None:
"""Make calls needed to initialize the device."""
Expand Down Expand Up @@ -309,7 +312,9 @@
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)

Check warning on line 317 in aioshelly/rpc_device/device.py

View check run for this annotation

Codecov / codecov/patch

aioshelly/rpc_device/device.py#L315-L317

Added lines #L315 - L317 were not covered by tests
chemelli74 marked this conversation as resolved.
Show resolved Hide resolved

async def script_list(self) -> list[ShellyScript]:
"""Get a list of scripts from 'Script.List'."""
Expand Down Expand Up @@ -509,6 +514,7 @@
return
components = await self.call_rpc("Shelly.GetComponents", {"dynamic_only": True})
self._parse_dynamic_components(components)
await self._retrieve_blutrv_components(components)

Check warning on line 517 in aioshelly/rpc_device/device.py

View check run for this annotation

Codecov / codecov/patch

aioshelly/rpc_device/device.py#L517

Added line #L517 was not covered by tests

def _supports_dynamic_components(self) -> bool:
"""Return True if device supports dynamic components."""
Expand Down Expand Up @@ -538,3 +544,28 @@
for item in self._dynamic_components
}
)

async def _retrieve_blutrv_components(self, components: dict[str, Any]) -> None:
chemelli74 marked this conversation as resolved.
Show resolved Hide resolved
"""Retrieve BLU TRV components."""
if self.model != MODEL_BLU_GATEWAY_GEN3:
return

Check warning on line 551 in aioshelly/rpc_device/device.py

View check run for this annotation

Codecov / codecov/patch

aioshelly/rpc_device/device.py#L550-L551

Added lines #L550 - L551 were not covered by tests

if not self._config or not self._status:
raise ConnectionError

Check warning on line 554 in aioshelly/rpc_device/device.py

View check run for this annotation

Codecov / codecov/patch

aioshelly/rpc_device/device.py#L553-L554

Added lines #L553 - L554 were not covered by tests
chemelli74 marked this conversation as resolved.
Show resolved Hide resolved

for component in components.get("components", []):
_key = component["key"].split(":")
if _key[0] == BLU_TRV_IDENTIFIER:
chemelli74 marked this conversation as resolved.
Show resolved Hide resolved
calls = [

Check warning on line 559 in aioshelly/rpc_device/device.py

View check run for this annotation

Codecov / codecov/patch

aioshelly/rpc_device/device.py#L556-L559

Added lines #L556 - L559 were not covered by tests
("BluTrv.GetRemoteConfig", {"id": _key[1]}),
("BluTrv.GetRemoteStatus", {"id": _key[1]}),
]
results = await self.call_rpc_multiple(calls)

Check warning on line 563 in aioshelly/rpc_device/device.py

View check run for this annotation

Codecov / codecov/patch

aioshelly/rpc_device/device.py#L563

Added line #L563 was not covered by tests

cfg: dict[str, Any] = results[0]["config"]["trv:0"]

Check warning on line 565 in aioshelly/rpc_device/device.py

View check run for this annotation

Codecov / codecov/patch

aioshelly/rpc_device/device.py#L565

Added line #L565 was not covered by tests
thecode marked this conversation as resolved.
Show resolved Hide resolved
# addr, name and model_id must be added from Shelly.GetComponents call
cfg.update({"addr": component["config"]["addr"]})
cfg.update({"name": component["config"]["name"]})
cfg.update({"model_id": component["attrs"].get("model_id")})
chemelli74 marked this conversation as resolved.
Show resolved Hide resolved
self._config.update({component["key"]: cfg})
self._status.update({component["key"]: results[1]["status"]["trv:0"]})

Check warning on line 571 in aioshelly/rpc_device/device.py

View check run for this annotation

Codecov / codecov/patch

aioshelly/rpc_device/device.py#L567-L571

Added lines #L567 - L571 were not covered by tests
thecode marked this conversation as resolved.
Show resolved Hide resolved
Loading