mirror of
https://github.com/home-assistant/core.git
synced 2026-07-08 15:24:58 +01:00
Convert RainMachine hw_version to string for device registry (#173545)
This commit is contained in:
@@ -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']})",
|
||||
)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"apiVer": "4.6.1",
|
||||
"hwVer": "3",
|
||||
"hwVer": 3,
|
||||
"swVer": "4.0.1144"
|
||||
}
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user