mirror of
https://github.com/home-assistant/core.git
synced 2026-04-21 00:49:54 +02:00
Deprecate Libre Hardware Monitor versions below v0.9.5 (#163838)
This commit is contained in:
@@ -6,7 +6,11 @@ import logging
|
||||
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
from homeassistant.helpers import (
|
||||
device_registry as dr,
|
||||
entity_registry as er,
|
||||
issue_registry as ir,
|
||||
)
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import (
|
||||
@@ -80,6 +84,21 @@ async def async_setup_entry(
|
||||
lhm_coordinator = LibreHardwareMonitorCoordinator(hass, config_entry)
|
||||
await lhm_coordinator.async_config_entry_first_refresh()
|
||||
|
||||
if lhm_coordinator.data.is_deprecated_version:
|
||||
issue_id = f"deprecated_api_{config_entry.entry_id}"
|
||||
ir.async_create_issue(
|
||||
hass,
|
||||
DOMAIN,
|
||||
issue_id,
|
||||
breaks_in_ha_version="2026.9.0",
|
||||
is_fixable=False,
|
||||
severity=ir.IssueSeverity.WARNING,
|
||||
translation_key="deprecated_api",
|
||||
translation_placeholders={
|
||||
"lhm_releases_url": "https://github.com/LibreHardwareMonitor/LibreHardwareMonitor/releases"
|
||||
},
|
||||
)
|
||||
|
||||
config_entry.runtime_data = lhm_coordinator
|
||||
await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryAuthFailed
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers import device_registry as dr, issue_registry as ir
|
||||
from homeassistant.helpers.aiohttp_client import async_create_clientsession
|
||||
from homeassistant.helpers.device_registry import DeviceEntry
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
@@ -50,7 +50,7 @@ class LibreHardwareMonitorCoordinator(DataUpdateCoordinator[LibreHardwareMonitor
|
||||
config_entry=config_entry,
|
||||
update_interval=timedelta(seconds=DEFAULT_SCAN_INTERVAL),
|
||||
)
|
||||
|
||||
self._entry_id = config_entry.entry_id
|
||||
self._api = LibreHardwareMonitorClient(
|
||||
host=config_entry.data[CONF_HOST],
|
||||
port=config_entry.data[CONF_PORT],
|
||||
@@ -59,13 +59,14 @@ class LibreHardwareMonitorCoordinator(DataUpdateCoordinator[LibreHardwareMonitor
|
||||
session=async_create_clientsession(hass),
|
||||
)
|
||||
device_entries: list[DeviceEntry] = dr.async_entries_for_config_entry(
|
||||
registry=dr.async_get(self.hass), config_entry_id=config_entry.entry_id
|
||||
registry=dr.async_get(self.hass), config_entry_id=self._entry_id
|
||||
)
|
||||
self._previous_devices: dict[DeviceId, DeviceName] = {
|
||||
DeviceId(next(iter(device.identifiers))[1]): DeviceName(device.name)
|
||||
for device in device_entries
|
||||
if device.identifiers and device.name
|
||||
}
|
||||
self._is_deprecated_version: bool | None = None
|
||||
|
||||
async def _async_update_data(self) -> LibreHardwareMonitorData:
|
||||
try:
|
||||
@@ -80,6 +81,12 @@ class LibreHardwareMonitorCoordinator(DataUpdateCoordinator[LibreHardwareMonitor
|
||||
except LibreHardwareMonitorNoDevicesError as err:
|
||||
raise UpdateFailed("No sensor data available, will retry") from err
|
||||
|
||||
# Check whether user has upgraded LHM from a deprecated version while the integration is running
|
||||
if self._is_deprecated_version and not lhm_data.is_deprecated_version:
|
||||
# Clear deprecation issue
|
||||
ir.async_delete_issue(self.hass, DOMAIN, f"deprecated_api_{self._entry_id}")
|
||||
self._is_deprecated_version = lhm_data.is_deprecated_version
|
||||
|
||||
await self._async_handle_changes_in_devices(
|
||||
dict(lhm_data.main_device_ids_and_names)
|
||||
)
|
||||
|
||||
@@ -33,5 +33,11 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"issues": {
|
||||
"deprecated_api": {
|
||||
"description": "Your version of Libre Hardware Monitor is deprecated and may not provide stable sensor data. To fix this issue:\n\n1. Download version 0.9.5 or later from {lhm_releases_url}\n2. Close Libre Hardware Monitor on your computer\n3. Install or extract the new version and start Libre Hardware Monitor again (you might have to re-enable the remote web server)\n4. Home Assistant will detect the new version and this issue will clear automatically",
|
||||
"title": "Deprecated Libre Hardware Monitor version"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,11 @@ from homeassistant.components.libre_hardware_monitor.const import (
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import STATE_UNAVAILABLE, STATE_UNKNOWN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
from homeassistant.helpers import (
|
||||
device_registry as dr,
|
||||
entity_registry as er,
|
||||
issue_registry as ir,
|
||||
)
|
||||
from homeassistant.helpers.device_registry import DeviceEntry
|
||||
|
||||
from . import init_integration
|
||||
@@ -312,3 +316,53 @@ async def test_integration_does_not_log_new_devices_on_first_refresh(
|
||||
if record.name.startswith("homeassistant.components.libre_hardware_monitor")
|
||||
]
|
||||
assert len(libre_hardware_monitor_logs) == 0
|
||||
|
||||
|
||||
async def test_non_deprecated_version_does_not_raise_issue(
|
||||
hass: HomeAssistant,
|
||||
mock_lhm_client: AsyncMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
issue_registry: ir.IssueRegistry,
|
||||
) -> None:
|
||||
"""Test that a non-deprecated Libre Hardware Monitor version does not raise an issue."""
|
||||
await init_integration(hass, mock_config_entry)
|
||||
|
||||
assert (
|
||||
DOMAIN,
|
||||
f"deprecated_api_{mock_config_entry.entry_id}",
|
||||
) not in issue_registry.issues
|
||||
|
||||
|
||||
async def test_deprecated_version_raises_issue_and_is_removed_after_update(
|
||||
hass: HomeAssistant,
|
||||
mock_lhm_client: AsyncMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
issue_registry: ir.IssueRegistry,
|
||||
) -> None:
|
||||
"""Test that a deprecated Libre Hardware Monitor version raises an issue that is removed after updating."""
|
||||
mock_lhm_client.get_data.return_value = replace(
|
||||
mock_lhm_client.get_data.return_value,
|
||||
is_deprecated_version=True,
|
||||
)
|
||||
|
||||
await init_integration(hass, mock_config_entry)
|
||||
|
||||
assert (
|
||||
DOMAIN,
|
||||
f"deprecated_api_{mock_config_entry.entry_id}",
|
||||
) in issue_registry.issues
|
||||
|
||||
mock_lhm_client.get_data.return_value = replace(
|
||||
mock_lhm_client.get_data.return_value,
|
||||
is_deprecated_version=False,
|
||||
)
|
||||
|
||||
freezer.tick(timedelta(DEFAULT_SCAN_INTERVAL))
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert (
|
||||
DOMAIN,
|
||||
f"deprecated_api_{mock_config_entry.entry_id}",
|
||||
) not in issue_registry.issues
|
||||
|
||||
Reference in New Issue
Block a user