From 1ba347f2bfc322d57e15aea307c7ca45ef58ab3c Mon Sep 17 00:00:00 2001 From: Sab44 <64696149+Sab44@users.noreply.github.com> Date: Sat, 14 Nov 2026 20:19:51 +0100 Subject: [PATCH] Icon translations for Libre Hardware Monitor (#192706) --- .../libre_hardware_monitor/icons.json | 24 +++++++++++++++++++ .../libre_hardware_monitor/quality_scale.yaml | 2 +- .../libre_hardware_monitor/sensor.py | 12 ++++++++++ .../snapshots/test_sensor.ambr | 18 +++++++------- .../libre_hardware_monitor/test_sensor.py | 11 +++++++++ 5 files changed, 57 insertions(+), 10 deletions(-) create mode 100644 homeassistant/components/libre_hardware_monitor/icons.json diff --git a/homeassistant/components/libre_hardware_monitor/icons.json b/homeassistant/components/libre_hardware_monitor/icons.json new file mode 100644 index 000000000000..46bc67c88f07 --- /dev/null +++ b/homeassistant/components/libre_hardware_monitor/icons.json @@ -0,0 +1,24 @@ +{ + "entity": { + "sensor": { + "control": { + "default": "mdi:tune-vertical" + }, + "factor": { + "default": "mdi:multiplication" + }, + "fan": { + "default": "mdi:fan" + }, + "level": { + "default": "mdi:gauge" + }, + "load": { + "default": "mdi:speedometer" + }, + "timing": { + "default": "mdi:timer-outline" + } + } + } +} diff --git a/homeassistant/components/libre_hardware_monitor/quality_scale.yaml b/homeassistant/components/libre_hardware_monitor/quality_scale.yaml index ad514248c278..5bfdf04d1aec 100644 --- a/homeassistant/components/libre_hardware_monitor/quality_scale.yaml +++ b/homeassistant/components/libre_hardware_monitor/quality_scale.yaml @@ -77,7 +77,7 @@ rules: comment: Desired devices are selected in Libre Hardware Monitor. entity-translations: todo exception-translations: done - icon-translations: todo + icon-translations: done reconfiguration-flow: done repair-issues: status: exempt diff --git a/homeassistant/components/libre_hardware_monitor/sensor.py b/homeassistant/components/libre_hardware_monitor/sensor.py index 5e024e8b63c2..551998af5307 100644 --- a/homeassistant/components/libre_hardware_monitor/sensor.py +++ b/homeassistant/components/libre_hardware_monitor/sensor.py @@ -56,6 +56,16 @@ DEVICE_CLASSES: dict[SensorType, SensorDeviceClass] = { SensorType.HUMIDITY: SensorDeviceClass.HUMIDITY, } +# Sensor types without a device class get their icon via translation key +TRANSLATION_KEYS: dict[SensorType, str] = { + SensorType.LOAD: "load", + SensorType.FAN: "fan", + SensorType.CONTROL: "control", + SensorType.LEVEL: "level", + SensorType.FACTOR: "factor", + SensorType.TIMING: "timing", +} + async def async_setup_entry( hass: HomeAssistant, @@ -221,6 +231,8 @@ class LibreHardwareMonitorSensor( elif device_class is SensorDeviceClass.DATA_SIZE: # LHM versions >= 0.9.7 report data sizes in raw bytes self._attr_suggested_unit_of_measurement = UnitOfInformation.GIBIBYTES + elif translation_key := TRANSLATION_KEYS.get(sensor_data.type): + self._attr_translation_key = translation_key self._set_state(sensor_data) self._attr_unique_id: str = f"{entry_id}_{sensor_data.sensor_id}" diff --git a/tests/components/libre_hardware_monitor/snapshots/test_sensor.ambr b/tests/components/libre_hardware_monitor/snapshots/test_sensor.ambr index cebbbe1f0cd9..6238d59939d4 100644 --- a/tests/components/libre_hardware_monitor/snapshots/test_sensor.ambr +++ b/tests/components/libre_hardware_monitor/snapshots/test_sensor.ambr @@ -93,7 +93,7 @@ 'previous_unique_id': None, 'suggested_object_id': None, 'supported_features': 0, - 'translation_key': None, + 'translation_key': 'load', 'unique_id': 'test_entry_id_amdcpu-0-load-0', 'unit_of_measurement': '%', }) @@ -509,7 +509,7 @@ 'previous_unique_id': None, 'suggested_object_id': None, 'supported_features': 0, - 'translation_key': None, + 'translation_key': 'fan', 'unique_id': 'test_entry_id_lpc-nct6687d-0-fan-0', 'unit_of_measurement': 'RPM', }) @@ -625,7 +625,7 @@ 'previous_unique_id': None, 'suggested_object_id': None, 'supported_features': 0, - 'translation_key': None, + 'translation_key': 'fan', 'unique_id': 'test_entry_id_lpc-nct6687d-0-fan-1', 'unit_of_measurement': 'RPM', }) @@ -681,7 +681,7 @@ 'previous_unique_id': None, 'suggested_object_id': None, 'supported_features': 0, - 'translation_key': None, + 'translation_key': 'fan', 'unique_id': 'test_entry_id_lpc-nct6687d-0-fan-2', 'unit_of_measurement': None, }) @@ -916,7 +916,7 @@ 'previous_unique_id': None, 'suggested_object_id': None, 'supported_features': 0, - 'translation_key': None, + 'translation_key': 'load', 'unique_id': 'test_entry_id_gpu-nvidia-0-load-0', 'unit_of_measurement': '%', }) @@ -1032,7 +1032,7 @@ 'previous_unique_id': None, 'suggested_object_id': None, 'supported_features': 0, - 'translation_key': None, + 'translation_key': 'fan', 'unique_id': 'test_entry_id_gpu-nvidia-0-fan-1', 'unit_of_measurement': 'RPM', }) @@ -1088,7 +1088,7 @@ 'previous_unique_id': None, 'suggested_object_id': None, 'supported_features': 0, - 'translation_key': None, + 'translation_key': 'fan', 'unique_id': 'test_entry_id_gpu-nvidia-0-fan-2', 'unit_of_measurement': 'RPM', }) @@ -1264,7 +1264,7 @@ 'previous_unique_id': None, 'suggested_object_id': None, 'supported_features': 0, - 'translation_key': None, + 'translation_key': 'load', 'unique_id': 'test_entry_id_gpu-nvidia-0-load-1', 'unit_of_measurement': '%', }) @@ -1443,7 +1443,7 @@ 'previous_unique_id': None, 'suggested_object_id': None, 'supported_features': 0, - 'translation_key': None, + 'translation_key': 'load', 'unique_id': 'test_entry_id_gpu-nvidia-0-load-2', 'unit_of_measurement': '%', }) diff --git a/tests/components/libre_hardware_monitor/test_sensor.py b/tests/components/libre_hardware_monitor/test_sensor.py index 479dc8fea8ab..e9bb3a68a633 100644 --- a/tests/components/libre_hardware_monitor/test_sensor.py +++ b/tests/components/libre_hardware_monitor/test_sensor.py @@ -31,9 +31,11 @@ from homeassistant.components.libre_hardware_monitor.const import ( DOMAIN, ) from homeassistant.components.libre_hardware_monitor.sensor import ( + DEVICE_CLASSES, MISSING_SENSOR_REMOVAL_UPDATES, STATE_MAX_VALUE, STATE_MIN_VALUE, + TRANSLATION_KEYS, ) from homeassistant.components.sensor import SensorDeviceClass from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState @@ -468,6 +470,15 @@ async def test_sensors_are_updated( assert state.state == state_value +async def test_all_sensor_types_have_a_translation_key() -> None: + """Test that all sensor types have a translation key.""" + types_with_translation_keys = DEVICE_CLASSES.keys() | TRANSLATION_KEYS.keys() + + for sensor_type in SensorType: + if sensor_type not in types_with_translation_keys: + raise AssertionError(f"Sensor type {sensor_type} has no translation key") + + async def test_integration_dynamically_adds_new_devices( hass: HomeAssistant, entity_registry: er.EntityRegistry,