mirror of
https://github.com/home-assistant/core.git
synced 2026-05-08 17:49:37 +01:00
Add Computer Name to device in Libre Hardware Monitor (#159342)
This commit is contained in:
@@ -32,15 +32,15 @@ async def async_migrate_entry(
|
||||
entity_registry, config_entry.entry_id
|
||||
)
|
||||
for reg_entry in registry_entries:
|
||||
new_entity_id = f"{config_entry.entry_id}_{reg_entry.unique_id[4:]}"
|
||||
new_unique_id = f"{config_entry.entry_id}_{reg_entry.unique_id[4:]}"
|
||||
_LOGGER.debug(
|
||||
"Migrating entity %s unique id from %s to %s",
|
||||
reg_entry.entity_id,
|
||||
reg_entry.unique_id,
|
||||
new_entity_id,
|
||||
new_unique_id,
|
||||
)
|
||||
entity_registry.async_update_entity(
|
||||
reg_entry.entity_id, new_unique_id=new_entity_id
|
||||
reg_entry.entity_id, new_unique_id=new_unique_id
|
||||
)
|
||||
|
||||
# Migrate device identifiers
|
||||
|
||||
@@ -46,7 +46,7 @@ class LibreHardwareMonitorConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
)
|
||||
|
||||
try:
|
||||
_ = (await api.get_data()).main_device_ids_and_names.values()
|
||||
computer_name = (await api.get_data()).computer_name
|
||||
except LibreHardwareMonitorConnectionError as exception:
|
||||
_LOGGER.error(exception)
|
||||
errors["base"] = "cannot_connect"
|
||||
@@ -54,7 +54,7 @@ class LibreHardwareMonitorConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
errors["base"] = "no_devices"
|
||||
else:
|
||||
return self.async_create_entry(
|
||||
title=f"{user_input[CONF_HOST]}:{user_input[CONF_PORT]}",
|
||||
title=f"{computer_name} ({user_input[CONF_HOST]}:{user_input[CONF_PORT]})",
|
||||
data=user_input,
|
||||
)
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ class LibreHardwareMonitorCoordinator(DataUpdateCoordinator[LibreHardwareMonitor
|
||||
lhm_data = await self._api.get_data()
|
||||
except LibreHardwareMonitorConnectionError as err:
|
||||
raise UpdateFailed(
|
||||
"LibreHardwareMonitor connection failed, will retry"
|
||||
"LibreHardwareMonitor connection failed, will retry", retry_after=30
|
||||
) from err
|
||||
except LibreHardwareMonitorNoDevicesError as err:
|
||||
raise UpdateFailed("No sensor data available, will retry") from err
|
||||
|
||||
@@ -7,5 +7,5 @@
|
||||
"integration_type": "device",
|
||||
"iot_class": "local_polling",
|
||||
"quality_scale": "silver",
|
||||
"requirements": ["librehardwaremonitor-api==1.5.0"]
|
||||
"requirements": ["librehardwaremonitor-api==1.6.0"]
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ class LibreHardwareMonitorSensor(
|
||||
# Hardware device
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, f"{entry_id}_{sensor_data.device_id}")},
|
||||
name=sensor_data.device_name,
|
||||
name=f"[{coordinator.data.computer_name}] {sensor_data.device_name}",
|
||||
model=sensor_data.device_type,
|
||||
)
|
||||
|
||||
|
||||
Generated
+1
-1
@@ -1391,7 +1391,7 @@ libpyfoscamcgi==0.0.9
|
||||
libpyvivotek==0.6.1
|
||||
|
||||
# homeassistant.components.libre_hardware_monitor
|
||||
librehardwaremonitor-api==1.5.0
|
||||
librehardwaremonitor-api==1.6.0
|
||||
|
||||
# homeassistant.components.mikrotik
|
||||
librouteros==3.2.0
|
||||
|
||||
Generated
+1
-1
@@ -1222,7 +1222,7 @@ libpyfoscamcgi==0.0.9
|
||||
libpyvivotek==0.6.1
|
||||
|
||||
# homeassistant.components.libre_hardware_monitor
|
||||
librehardwaremonitor-api==1.5.0
|
||||
librehardwaremonitor-api==1.6.0
|
||||
|
||||
# homeassistant.components.mikrotik
|
||||
librouteros==3.2.0
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"Children": [
|
||||
{
|
||||
"id": 1,
|
||||
"Text": "GAMING",
|
||||
"Text": "GAMING-PC",
|
||||
"Min": "",
|
||||
"Value": "",
|
||||
"Max": "",
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -42,7 +42,7 @@ async def test_create_entry(
|
||||
mock_config_entry = result["result"]
|
||||
assert (
|
||||
mock_config_entry.title
|
||||
== f"{VALID_CONFIG[CONF_HOST]}:{VALID_CONFIG[CONF_PORT]}"
|
||||
== f"GAMING-PC ({VALID_CONFIG[CONF_HOST]}:{VALID_CONFIG[CONF_PORT]})"
|
||||
)
|
||||
assert mock_config_entry.data == VALID_CONFIG
|
||||
|
||||
|
||||
@@ -88,3 +88,8 @@ async def test_migration_to_unique_ids(
|
||||
assert (
|
||||
entity_registry.async_get_entity_id("sensor", DOMAIN, legacy_entity_id) is None
|
||||
)
|
||||
|
||||
updated_config_entry = hass.config_entries.async_get_entry(
|
||||
legacy_config_entry_v1.entry_id
|
||||
)
|
||||
assert updated_config_entry.version == 2
|
||||
|
||||
@@ -92,7 +92,7 @@ async def test_sensors_are_updated(
|
||||
"""Test sensors are updated with properly formatted values."""
|
||||
await init_integration(hass, mock_config_entry)
|
||||
|
||||
entity_id = "sensor.amd_ryzen_7_7800x3d_package_temperature"
|
||||
entity_id = "sensor.gaming_pc_amd_ryzen_7_7800x3d_package_temperature"
|
||||
state = hass.states.get(entity_id)
|
||||
|
||||
assert state
|
||||
@@ -128,7 +128,7 @@ async def test_sensor_state_is_unknown_when_no_sensor_data_is_provided(
|
||||
"""Test sensor state is unknown when sensor data is missing."""
|
||||
await init_integration(hass, mock_config_entry)
|
||||
|
||||
entity_id = "sensor.amd_ryzen_7_7800x3d_package_temperature"
|
||||
entity_id = "sensor.gaming_pc_amd_ryzen_7_7800x3d_package_temperature"
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
|
||||
@@ -200,6 +200,7 @@ async def _mock_orphaned_device(
|
||||
previous_data = mock_lhm_client.get_data.return_value
|
||||
|
||||
mock_lhm_client.get_data.return_value = LibreHardwareMonitorData(
|
||||
computer_name=mock_lhm_client.get_data.return_value.computer_name,
|
||||
main_device_ids_and_names=MappingProxyType(
|
||||
{
|
||||
device_id: name
|
||||
@@ -230,6 +231,7 @@ async def test_integration_does_not_log_new_devices_on_first_refresh(
|
||||
) -> None:
|
||||
"""Test that initial data update does not cause warning about new devices."""
|
||||
mock_lhm_client.get_data.return_value = LibreHardwareMonitorData(
|
||||
computer_name=mock_lhm_client.get_data.return_value.computer_name,
|
||||
main_device_ids_and_names=MappingProxyType(
|
||||
{
|
||||
**mock_lhm_client.get_data.return_value.main_device_ids_and_names,
|
||||
|
||||
Reference in New Issue
Block a user