mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Icon translations for Libre Hardware Monitor (#192706)
This commit is contained in:
@@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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}"
|
||||
|
||||
@@ -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': '%',
|
||||
})
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user