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

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
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
34 changes: 33 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,29 @@
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 TYPE_CHECKING:
assert self._config
assert self._status

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

View check run for this annotation

Codecov / codecov/patch

aioshelly/rpc_device/device.py#L553-L555

Added lines #L553 - L555 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 560 in aioshelly/rpc_device/device.py

View check run for this annotation

Codecov / codecov/patch

aioshelly/rpc_device/device.py#L557-L560

Added lines #L557 - L560 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 564 in aioshelly/rpc_device/device.py

View check run for this annotation

Codecov / codecov/patch

aioshelly/rpc_device/device.py#L564

Added line #L564 was not covered by tests

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

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

View check run for this annotation

Codecov / codecov/patch

aioshelly/rpc_device/device.py#L566

Added line #L566 was not covered by tests
thecode marked this conversation as resolved.
Show resolved Hide resolved
# addr and name must be added from Shelly.GetComponents call
# model_id can't be retrieved, remote device call (TRV.GetConfig) needed
cfg.update({"addr": component["config"]["addr"]})
cfg.update({"name": component["config"]["name"]})
self._config.update({component["key"]: cfg})
self._status.update({component["key"]: results[1]["status"]["trv:0"]})

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

View check run for this annotation

Codecov / codecov/patch

aioshelly/rpc_device/device.py#L569-L572

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