From e4b5fcf539ff67937c57d809c2d7e4de09efd455 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Fri, 12 Jun 2026 09:00:38 +0200 Subject: [PATCH] Convert RainMachine hw_version to string for device registry (#173545) --- .../components/rainmachine/entity.py | 2 +- .../fixtures/api_versions_data.json | 2 +- .../snapshots/test_diagnostics.ambr | 4 +-- tests/components/rainmachine/test_sensor.py | 28 ++++++++++++++++++- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/rainmachine/entity.py b/homeassistant/components/rainmachine/entity.py index 2e1f65c8967a..335419d8c35e 100644 --- a/homeassistant/components/rainmachine/entity.py +++ b/homeassistant/components/rainmachine/entity.py @@ -54,7 +54,7 @@ class RainMachineEntity(CoordinatorEntity[RainMachineDataUpdateCoordinator]): connections={(dr.CONNECTION_NETWORK_MAC, self._data.controller.mac)}, name=self._data.controller.name.capitalize(), manufacturer="RainMachine", - hw_version=self._version_coordinator.data["hwVer"], + hw_version=str(self._version_coordinator.data["hwVer"]), sw_version=f"{self._version_coordinator.data['swVer']} " f"(API: {self._version_coordinator.data['apiVer']})", ) diff --git a/tests/components/rainmachine/fixtures/api_versions_data.json b/tests/components/rainmachine/fixtures/api_versions_data.json index 67cfa4ce033f..d4ec1fb80e9d 100644 --- a/tests/components/rainmachine/fixtures/api_versions_data.json +++ b/tests/components/rainmachine/fixtures/api_versions_data.json @@ -1,5 +1,5 @@ { "apiVer": "4.6.1", - "hwVer": "3", + "hwVer": 3, "swVer": "4.0.1144" } diff --git a/tests/components/rainmachine/snapshots/test_diagnostics.ambr b/tests/components/rainmachine/snapshots/test_diagnostics.ambr index 681805996f1a..4dc543fc55e1 100644 --- a/tests/components/rainmachine/snapshots/test_diagnostics.ambr +++ b/tests/components/rainmachine/snapshots/test_diagnostics.ambr @@ -26,7 +26,7 @@ 'coordinator': dict({ 'api.versions': dict({ 'apiVer': '4.6.1', - 'hwVer': '3', + 'hwVer': 3, 'swVer': '4.0.1144', }), 'machine.firmware_update_status': dict({ @@ -1159,7 +1159,7 @@ 'coordinator': dict({ 'api.versions': dict({ 'apiVer': '4.6.1', - 'hwVer': '3', + 'hwVer': 3, 'swVer': '4.0.1144', }), 'machine.firmware_update_status': dict({ diff --git a/tests/components/rainmachine/test_sensor.py b/tests/components/rainmachine/test_sensor.py index 15bb87a81511..c32c87873c1b 100644 --- a/tests/components/rainmachine/test_sensor.py +++ b/tests/components/rainmachine/test_sensor.py @@ -1,5 +1,6 @@ """Test RainMachine sensors.""" +import logging from typing import Any from unittest.mock import AsyncMock, patch @@ -9,7 +10,7 @@ from syrupy.assertion import SnapshotAssertion from homeassistant.components.rainmachine import DOMAIN from homeassistant.const import Platform from homeassistant.core import HomeAssistant -from homeassistant.helpers import entity_registry as er +from homeassistant.helpers import device_registry as dr, entity_registry as er from homeassistant.setup import async_setup_component from tests.common import MockConfigEntry, snapshot_platform @@ -32,3 +33,28 @@ async def test_sensors( assert await async_setup_component(hass, DOMAIN, config) await hass.async_block_till_done() await snapshot_platform(hass, entity_registry, snapshot, config_entry.entry_id) + + +async def test_device_info_hw_version_is_string( + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + config: dict[str, Any], + config_entry: MockConfigEntry, + client: AsyncMock, + caplog: pytest.LogCaptureFixture, +) -> None: + """Test that hw_version is a string even when API returns int.""" + with ( + caplog.at_level(logging.WARNING, logger="homeassistant.helpers.frame"), + patch("homeassistant.components.rainmachine.Client", return_value=client), + patch("homeassistant.components.rainmachine.PLATFORMS", [Platform.SENSOR]), + ): + assert await async_setup_component(hass, DOMAIN, config) + await hass.async_block_till_done() + + device_entry = device_registry.async_get_device( + connections={(dr.CONNECTION_NETWORK_MAC, "aa:bb:cc:dd:ee:ff")} + ) + assert device_entry + assert device_entry.hw_version == "3" + assert "non-string value" not in caplog.text