Skip to content

Commit 3c5028d

Browse files
authored
Don't use GetComponents if firmware doesn't support it (#613)
* Don't use GetComponents if firmware doesn't support it * Add comment
1 parent df22e28 commit 3c5028d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

aioshelly/const.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,3 +281,5 @@
281281
FIRMWARE_PATTERN = re.compile(r"^(\d{8})")
282282

283283
VIRTUAL_COMPONENTS = ("boolean", "button", "enum", "number", "text")
284+
# Firmware 1.2.0 release date
285+
VIRTUAL_COMPONENTS_MIN_FIRMWARE = 20240213

aioshelly/rpc_device/device.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
GEN3_MIN_FIRMWARE_DATE,
2121
NOTIFY_WS_CLOSED,
2222
VIRTUAL_COMPONENTS,
23+
VIRTUAL_COMPONENTS_MIN_FIRMWARE,
2324
)
2425
from ..exceptions import (
2526
DeviceConnectionError,
@@ -454,12 +455,19 @@ def firmware_supported(self) -> bool:
454455

455456
async def get_dynamic_components(self) -> None:
456457
"""Return a list of dynamic components."""
457-
result = await self.call_rpc("Shelly.GetComponents", {"dynamic_only": True})
458+
components = {}
459+
match = FIRMWARE_PATTERN.search(self.firmware_version)
460+
461+
if match is not None and int(match[0]) >= VIRTUAL_COMPONENTS_MIN_FIRMWARE:
462+
components = await self.call_rpc(
463+
"Shelly.GetComponents", {"dynamic_only": True}
464+
)
465+
458466
# This is a workaround for Wall Display, we get rid of components that are not
459467
# virtual components.
460468
self._dynamic_components = [
461469
component
462-
for component in result["components"]
470+
for component in components.get("components", [])
463471
if any(supported in component["key"] for supported in VIRTUAL_COMPONENTS)
464472
]
465473

0 commit comments

Comments
 (0)