From 8f9868024c659faa6133ef6f0ae6ba53fd3f866e Mon Sep 17 00:00:00 2001 From: Michael <35783820+mib1185@users.noreply.github.com> Date: Mon, 3 Apr 2023 19:55:54 +0200 Subject: [PATCH] Add entity name translations to Luftdaten (#90725) --- homeassistant/components/luftdaten/sensor.py | 12 +++++------ .../components/luftdaten/strings.json | 20 +++++++++++++++++++ tests/components/luftdaten/test_sensor.py | 18 +++++++++++------ 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/luftdaten/sensor.py b/homeassistant/components/luftdaten/sensor.py index 67672759706..262a6701f56 100644 --- a/homeassistant/components/luftdaten/sensor.py +++ b/homeassistant/components/luftdaten/sensor.py @@ -32,42 +32,42 @@ from .const import ATTR_SENSOR_ID, CONF_SENSOR_ID, DOMAIN SENSORS: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="temperature", - name="Temperature", + translation_key="temperature", native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, ), SensorEntityDescription( key="humidity", - name="Humidity", + translation_key="humidity", native_unit_of_measurement=PERCENTAGE, device_class=SensorDeviceClass.HUMIDITY, state_class=SensorStateClass.MEASUREMENT, ), SensorEntityDescription( key="pressure", - name="Pressure", + translation_key="pressure", native_unit_of_measurement=UnitOfPressure.PA, device_class=SensorDeviceClass.PRESSURE, state_class=SensorStateClass.MEASUREMENT, ), SensorEntityDescription( key="pressure_at_sealevel", - name="Pressure at sealevel", + translation_key="pressure_at_sealevel", native_unit_of_measurement=UnitOfPressure.PA, device_class=SensorDeviceClass.PRESSURE, state_class=SensorStateClass.MEASUREMENT, ), SensorEntityDescription( key="P1", - name="PM10", + translation_key="pm10", native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, device_class=SensorDeviceClass.PM10, state_class=SensorStateClass.MEASUREMENT, ), SensorEntityDescription( key="P2", - name="PM2.5", + translation_key="pm25", native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, device_class=SensorDeviceClass.PM25, state_class=SensorStateClass.MEASUREMENT, diff --git a/homeassistant/components/luftdaten/strings.json b/homeassistant/components/luftdaten/strings.json index 508e12924d3..d54bc6d0bdc 100644 --- a/homeassistant/components/luftdaten/strings.json +++ b/homeassistant/components/luftdaten/strings.json @@ -13,5 +13,25 @@ "invalid_sensor": "Sensor not available or invalid", "cannot_connect": "[%key:common::config_flow::error::cannot_connect%]" } + }, + "entity": { + "sensor": { + "humidity": { + "name": "[%key:component::sensor::entity_component::humidity::name%]" + }, + "pressure": { + "name": "[%key:component::sensor::entity_component::pressure::name%]" + }, + "pressure_at_sealevel": { "name": "Pressure at sealevel" }, + "pm10": { + "name": "[%key:component::sensor::entity_component::pm10::name%]" + }, + "pm25": { + "name": "[%key:component::sensor::entity_component::pm25::name%]" + }, + "temperature": { + "name": "[%key:component::sensor::entity_component::temperature::name%]" + } + } } } diff --git a/tests/components/luftdaten/test_sensor.py b/tests/components/luftdaten/test_sensor.py index e9e86fd9f1b..1cb87a36922 100644 --- a/tests/components/luftdaten/test_sensor.py +++ b/tests/components/luftdaten/test_sensor.py @@ -87,15 +87,18 @@ async def test_luftdaten_sensors( assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfPressure.PA assert ATTR_ICON not in state.attributes - entry = entity_registry.async_get("sensor.sensor_12345_pm10") + entry = entity_registry.async_get("sensor.sensor_12345_particulate_matter_10_mm") assert entry assert entry.device_id assert entry.unique_id == "12345_P1" - state = hass.states.get("sensor.sensor_12345_pm10") + state = hass.states.get("sensor.sensor_12345_particulate_matter_10_mm") assert state assert state.state == "8.5" - assert state.attributes.get(ATTR_FRIENDLY_NAME) == "Sensor 12345 PM10" + assert ( + state.attributes.get(ATTR_FRIENDLY_NAME) + == "Sensor 12345 Particulate matter 10 μm" + ) assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.PM10 assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT assert ( @@ -104,15 +107,18 @@ async def test_luftdaten_sensors( ) assert ATTR_ICON not in state.attributes - entry = entity_registry.async_get("sensor.sensor_12345_pm2_5") + entry = entity_registry.async_get("sensor.sensor_12345_particulate_matter_2_5_mm") assert entry assert entry.device_id assert entry.unique_id == "12345_P2" - state = hass.states.get("sensor.sensor_12345_pm2_5") + state = hass.states.get("sensor.sensor_12345_particulate_matter_2_5_mm") assert state assert state.state == "4.07" - assert state.attributes.get(ATTR_FRIENDLY_NAME) == "Sensor 12345 PM2.5" + assert ( + state.attributes.get(ATTR_FRIENDLY_NAME) + == "Sensor 12345 Particulate matter 2.5 μm" + ) assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.PM25 assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT assert (