mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Add capability to display updated firmware versions in Home Assistant (#140524)
* add firmware version update * incoperate review feedback
This commit is contained in:
parent
6b9c1e17e0
commit
2c9eb288e3
@ -8,6 +8,7 @@ from iometer import IOmeterClient, IOmeterConnectionError, Reading, Status
|
|||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers import device_registry as dr
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
@ -31,6 +32,7 @@ class IOMeterCoordinator(DataUpdateCoordinator[IOmeterData]):
|
|||||||
|
|
||||||
config_entry: IOmeterConfigEntry
|
config_entry: IOmeterConfigEntry
|
||||||
client: IOmeterClient
|
client: IOmeterClient
|
||||||
|
current_fw_version: str = ""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@ -58,4 +60,17 @@ class IOMeterCoordinator(DataUpdateCoordinator[IOmeterData]):
|
|||||||
except IOmeterConnectionError as error:
|
except IOmeterConnectionError as error:
|
||||||
raise UpdateFailed(f"Error communicating with IOmeter: {error}") from error
|
raise UpdateFailed(f"Error communicating with IOmeter: {error}") from error
|
||||||
|
|
||||||
|
fw_version = f"{status.device.core.version}/{status.device.bridge.version}"
|
||||||
|
if self.current_fw_version and fw_version != self.current_fw_version:
|
||||||
|
device_registry = dr.async_get(self.hass)
|
||||||
|
device_entry = device_registry.async_get_device(
|
||||||
|
identifiers={(DOMAIN, status.device.id)}
|
||||||
|
)
|
||||||
|
assert device_entry
|
||||||
|
device_registry.async_update_device(
|
||||||
|
device_entry.id,
|
||||||
|
sw_version=fw_version,
|
||||||
|
)
|
||||||
|
self.current_fw_version = fw_version
|
||||||
|
|
||||||
return IOmeterData(reading=reading, status=status)
|
return IOmeterData(reading=reading, status=status)
|
||||||
|
@ -20,5 +20,5 @@ class IOmeterEntity(CoordinatorEntity[IOMeterCoordinator]):
|
|||||||
identifiers={(DOMAIN, status.device.id)},
|
identifiers={(DOMAIN, status.device.id)},
|
||||||
manufacturer="IOmeter GmbH",
|
manufacturer="IOmeter GmbH",
|
||||||
model="IOmeter",
|
model="IOmeter",
|
||||||
sw_version=f"{status.device.core.version}/{status.device.bridge.version}",
|
sw_version=coordinator.current_fw_version,
|
||||||
)
|
)
|
||||||
|
@ -1 +1,13 @@
|
|||||||
"""Tests for the IOmeter integration."""
|
"""Tests for the IOmeter integration."""
|
||||||
|
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
|
async def setup_integration(hass: HomeAssistant, config_entry: MockConfigEntry) -> None:
|
||||||
|
"""Fixture for setting up the component."""
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
|
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
42
tests/components/iometer/test_init.py
Normal file
42
tests/components/iometer/test_init.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
"""Tests for the AirGradient integration."""
|
||||||
|
|
||||||
|
from datetime import timedelta
|
||||||
|
from unittest.mock import AsyncMock
|
||||||
|
|
||||||
|
from freezegun.api import FrozenDateTimeFactory
|
||||||
|
|
||||||
|
from homeassistant.components.iometer.const import DOMAIN
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers import device_registry as dr
|
||||||
|
|
||||||
|
from . import setup_integration
|
||||||
|
|
||||||
|
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||||
|
|
||||||
|
|
||||||
|
async def test_new_firmware_version(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
mock_iometer_client: AsyncMock,
|
||||||
|
mock_config_entry: MockConfigEntry,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
freezer: FrozenDateTimeFactory,
|
||||||
|
) -> None:
|
||||||
|
"""Test device registry integration."""
|
||||||
|
await setup_integration(hass, mock_config_entry)
|
||||||
|
device_entry = device_registry.async_get_device(
|
||||||
|
identifiers={(DOMAIN, mock_config_entry.unique_id)}
|
||||||
|
)
|
||||||
|
assert device_entry is not None
|
||||||
|
assert device_entry.sw_version == "build-58/build-65"
|
||||||
|
mock_iometer_client.get_current_status.return_value.device.core.version = "build-62"
|
||||||
|
mock_iometer_client.get_current_status.return_value.device.bridge.version = (
|
||||||
|
"build-69"
|
||||||
|
)
|
||||||
|
freezer.tick(timedelta(minutes=1))
|
||||||
|
async_fire_time_changed(hass)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
device_entry = device_registry.async_get_device(
|
||||||
|
identifiers={(DOMAIN, mock_config_entry.unique_id)}
|
||||||
|
)
|
||||||
|
assert device_entry is not None
|
||||||
|
assert device_entry.sw_version == "build-62/build-69"
|
Loading…
x
Reference in New Issue
Block a user