Skip to content

Commit ae70ca7

Browse files
authored
Add sw_version to Shelly BLU TRV device info (home-assistant#152129)
1 parent 66d1cf8 commit ae70ca7

File tree

8 files changed

+37
-9
lines changed

8 files changed

+37
-9
lines changed

homeassistant/components/shelly/binary_sensor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,9 @@ def __init__(
9898

9999
super().__init__(coordinator, key, attribute, description)
100100
ble_addr: str = coordinator.device.config[key]["addr"]
101+
fw_ver = coordinator.device.status[key].get("fw_ver")
101102
self._attr_device_info = get_blu_trv_device_info(
102-
coordinator.device.config[key], ble_addr, coordinator.mac
103+
coordinator.device.config[key], ble_addr, coordinator.mac, fw_ver
103104
)
104105

105106

homeassistant/components/shelly/button.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,14 @@ def __init__(
254254
"""Initialize."""
255255
super().__init__(coordinator, description)
256256

257-
config = coordinator.device.config[f"{BLU_TRV_IDENTIFIER}:{id_}"]
257+
key = f"{BLU_TRV_IDENTIFIER}:{id_}"
258+
config = coordinator.device.config[key]
258259
ble_addr: str = config["addr"]
260+
fw_ver = coordinator.device.status[key].get("fw_ver")
261+
259262
self._attr_unique_id = f"{ble_addr}_{description.key}"
260263
self._attr_device_info = get_blu_trv_device_info(
261-
config, ble_addr, coordinator.mac
264+
config, ble_addr, coordinator.mac, fw_ver
262265
)
263266
self._id = id_
264267

homeassistant/components/shelly/climate.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,11 +557,12 @@ def __init__(self, coordinator: ShellyRpcCoordinator, id_: int) -> None:
557557

558558
super().__init__(coordinator, f"{BLU_TRV_IDENTIFIER}:{id_}")
559559
self._id = id_
560-
self._config = coordinator.device.config[f"{BLU_TRV_IDENTIFIER}:{id_}"]
560+
self._config = coordinator.device.config[self.key]
561561
ble_addr: str = self._config["addr"]
562562
self._attr_unique_id = f"{ble_addr}-{self.key}"
563+
fw_ver = coordinator.device.status[self.key].get("fw_ver")
563564
self._attr_device_info = get_blu_trv_device_info(
564-
self._config, ble_addr, self.coordinator.mac
565+
self._config, ble_addr, self.coordinator.mac, fw_ver
565566
)
566567

567568
@property

homeassistant/components/shelly/number.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,9 @@ def __init__(
125125

126126
super().__init__(coordinator, key, attribute, description)
127127
ble_addr: str = coordinator.device.config[key]["addr"]
128+
fw_ver = coordinator.device.status[key].get("fw_ver")
128129
self._attr_device_info = get_blu_trv_device_info(
129-
coordinator.device.config[key], ble_addr, coordinator.mac
130+
coordinator.device.config[key], ble_addr, coordinator.mac, fw_ver
130131
)
131132

132133

homeassistant/components/shelly/sensor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,9 @@ def __init__(
169169

170170
super().__init__(coordinator, key, attribute, description)
171171
ble_addr: str = coordinator.device.config[key]["addr"]
172+
fw_ver = coordinator.device.status[key].get("fw_ver")
172173
self._attr_device_info = get_blu_trv_device_info(
173-
coordinator.device.config[key], ble_addr, coordinator.mac
174+
coordinator.device.config[key], ble_addr, coordinator.mac, fw_ver
174175
)
175176

176177

homeassistant/components/shelly/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ def get_rpc_device_info(
811811

812812

813813
def get_blu_trv_device_info(
814-
config: dict[str, Any], ble_addr: str, parent_mac: str
814+
config: dict[str, Any], ble_addr: str, parent_mac: str, fw_ver: str | None
815815
) -> DeviceInfo:
816816
"""Return device info for RPC device."""
817817
model_id = config.get("local_name")
@@ -823,6 +823,7 @@ def get_blu_trv_device_info(
823823
model=BLU_TRV_MODEL_NAME.get(model_id) if model_id else None,
824824
model_id=config.get("local_name"),
825825
name=config["name"] or f"shellyblutrv-{ble_addr.replace(':', '')}",
826+
sw_version=fw_ver,
826827
)
827828

828829

tests/components/shelly/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ def mock_white_light_set_state(
324324
"rssi": -60,
325325
"battery": 100,
326326
"errors": [],
327+
"fw_ver": "v1.2.10",
327328
},
328329
"blutrv:201": {
329330
"id": 0,

tests/components/shelly/test_devices.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from unittest.mock import Mock
44

5-
from aioshelly.const import MODEL_2PM_G3, MODEL_PRO_EM3
5+
from aioshelly.const import MODEL_2PM_G3, MODEL_BLU_GATEWAY_G3, MODEL_PRO_EM3
66
from freezegun.api import FrozenDateTimeFactory
77
import pytest
88
from syrupy.assertion import SnapshotAssertion
@@ -510,3 +510,22 @@ async def test_block_channel_with_name(
510510
device_entry = device_registry.async_get(entry.device_id)
511511
assert device_entry
512512
assert device_entry.name == "Test name"
513+
514+
515+
async def test_blu_trv_device_info(
516+
hass: HomeAssistant,
517+
mock_blu_trv: Mock,
518+
entity_registry: EntityRegistry,
519+
device_registry: DeviceRegistry,
520+
) -> None:
521+
"""Test BLU TRV device info."""
522+
await init_integration(hass, 3, model=MODEL_BLU_GATEWAY_G3)
523+
524+
entry = entity_registry.async_get("climate.trv_name")
525+
assert entry
526+
527+
device_entry = device_registry.async_get(entry.device_id)
528+
assert device_entry
529+
assert device_entry.name == "TRV-Name"
530+
assert device_entry.model_id == "SBTR-001AEU"
531+
assert device_entry.sw_version == "v1.2.10"

0 commit comments

Comments
 (0)