From e748f0c623225d019dbae1a5a3e6938c66dc0900 Mon Sep 17 00:00:00 2001 From: Patrick ZAJDA <patrick@zajda.fr> Date: Tue, 4 Apr 2023 21:18:41 +0200 Subject: [PATCH] Add entity name translations to Broadlink sensors (#90783) * Add entity name translations to Broadlink sensors Signed-off-by: Patrick ZAJDA <patrick@zajda.fr> * Update tests Signed-off-by: Patrick ZAJDA <patrick@zajda.fr> * Apply suggestions from code review Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> --------- Signed-off-by: Patrick ZAJDA <patrick@zajda.fr> Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> --- homeassistant/components/broadlink/sensor.py | 20 +++++------ .../components/broadlink/strings.json | 34 +++++++++++++++++++ tests/components/broadlink/test_sensors.py | 12 +++---- 3 files changed, 50 insertions(+), 16 deletions(-) diff --git a/homeassistant/components/broadlink/sensor.py b/homeassistant/components/broadlink/sensor.py index 33f1badcc1b..50c58d41667 100644 --- a/homeassistant/components/broadlink/sensor.py +++ b/homeassistant/components/broadlink/sensor.py @@ -25,61 +25,61 @@ from .entity import BroadlinkEntity SENSOR_TYPES: 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="air_quality", - name="Air quality", + translation_key="air_quality", ), SensorEntityDescription( key="humidity", - name="Humidity", + translation_key="humidity", native_unit_of_measurement=PERCENTAGE, device_class=SensorDeviceClass.HUMIDITY, state_class=SensorStateClass.MEASUREMENT, ), SensorEntityDescription( key="light", - name="Light", + translation_key="light", ), SensorEntityDescription( key="noise", - name="Noise", + translation_key="noise", ), SensorEntityDescription( key="power", - name="Current power", + translation_key="power", native_unit_of_measurement=UnitOfPower.WATT, device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, ), SensorEntityDescription( key="volt", - name="Voltage", + translation_key="voltage", native_unit_of_measurement=UnitOfElectricPotential.VOLT, device_class=SensorDeviceClass.VOLTAGE, state_class=SensorStateClass.MEASUREMENT, ), SensorEntityDescription( key="current", - name="Current", + translation_key="current", native_unit_of_measurement=UnitOfElectricCurrent.AMPERE, device_class=SensorDeviceClass.CURRENT, state_class=SensorStateClass.MEASUREMENT, ), SensorEntityDescription( key="overload", - name="Overload", + translation_key="overload", native_unit_of_measurement=UnitOfElectricCurrent.AMPERE, device_class=SensorDeviceClass.CURRENT, state_class=SensorStateClass.MEASUREMENT, ), SensorEntityDescription( key="totalconsum", - name="Total consumption", + translation_key="total_consumption", native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, diff --git a/homeassistant/components/broadlink/strings.json b/homeassistant/components/broadlink/strings.json index d324b0272a8..adff2303c74 100644 --- a/homeassistant/components/broadlink/strings.json +++ b/homeassistant/components/broadlink/strings.json @@ -43,5 +43,39 @@ "invalid_host": "[%key:common::config_flow::error::invalid_host%]", "unknown": "[%key:common::config_flow::error::unknown%]" } + }, + "entity": { + "sensor": { + "temperature": { + "name": "[%key:component::sensor::entity_component::temperature::name%]" + }, + "air_quality": { + "name": "[%key:component::sensor::entity_component::aqi::name%]" + }, + "humidity": { + "name": "[%key:component::sensor::entity_component::humidity::name%]" + }, + "light": { + "name": "[%key:component::sensor::entity_component::illuminance::name%]" + }, + "noise": { + "name": "Noise" + }, + "power": { + "name": "[%key:component::sensor::entity_component::power::name%]" + }, + "voltage": { + "name": "[%key:component::sensor::entity_component::voltage::name%]" + }, + "current": { + "name": "[%key:component::sensor::entity_component::current::name%]" + }, + "overload": { + "name": "Overload" + }, + "total_consumption": { + "name": "Total consumption" + } + } } } diff --git a/tests/components/broadlink/test_sensors.py b/tests/components/broadlink/test_sensors.py index c6201a8c9c7..43529fae631 100644 --- a/tests/components/broadlink/test_sensors.py +++ b/tests/components/broadlink/test_sensors.py @@ -50,8 +50,8 @@ async def test_a1_sensor_setup( assert sensors_and_states == { (f"{device.name} Temperature", "27.4"), (f"{device.name} Humidity", "59.3"), - (f"{device.name} Air quality", "3"), - (f"{device.name} Light", "2"), + (f"{device.name} Air quality index", "3"), + (f"{device.name} Illuminance", "2"), (f"{device.name} Noise", "1"), } @@ -101,8 +101,8 @@ async def test_a1_sensor_update( assert sensors_and_states == { (f"{device.name} Temperature", "22.5"), (f"{device.name} Humidity", "47.4"), - (f"{device.name} Air quality", "2"), - (f"{device.name} Light", "3"), + (f"{device.name} Air quality index", "2"), + (f"{device.name} Illuminance", "3"), (f"{device.name} Noise", "2"), } @@ -355,7 +355,7 @@ async def test_scb1e_sensor_setup( for sensor in sensors } assert sensors_and_states == { - (f"{device.name} Current power", "255.57"), + (f"{device.name} Power", "255.57"), (f"{device.name} Voltage", "121.7"), (f"{device.name} Current", "2.1"), (f"{device.name} Overload", "0"), @@ -421,7 +421,7 @@ async def test_scb1e_sensor_update( for sensor in sensors } assert sensors_and_states == { - (f"{device.name} Current power", "291.8"), + (f"{device.name} Power", "291.8"), (f"{device.name} Voltage", "121.6"), (f"{device.name} Current", "2.4"), (f"{device.name} Overload", "0"), -- GitLab