From 99430ceb3404cd9e5923a69485826bf0a02f43a1 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Thu, 6 Jul 2023 22:51:05 +0200 Subject: [PATCH] Add entity translations for PureEnergie (#95935) * Add entity translations for PureEnergie * Fix tests --- homeassistant/components/pure_energie/sensor.py | 7 ++++--- homeassistant/components/pure_energie/strings.json | 13 +++++++++++++ tests/components/pure_energie/test_sensor.py | 6 +++--- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/pure_energie/sensor.py b/homeassistant/components/pure_energie/sensor.py index 7d584c7c1a8..9f67665d66c 100644 --- a/homeassistant/components/pure_energie/sensor.py +++ b/homeassistant/components/pure_energie/sensor.py @@ -39,7 +39,7 @@ class PureEnergieSensorEntityDescription( SENSORS: tuple[PureEnergieSensorEntityDescription, ...] = ( PureEnergieSensorEntityDescription( key="power_flow", - name="Power Flow", + translation_key="power_flow", native_unit_of_measurement=UnitOfPower.WATT, device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, @@ -47,7 +47,7 @@ SENSORS: tuple[PureEnergieSensorEntityDescription, ...] = ( ), PureEnergieSensorEntityDescription( key="energy_consumption_total", - name="Energy Consumption", + translation_key="energy_consumption_total", native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, @@ -55,7 +55,7 @@ SENSORS: tuple[PureEnergieSensorEntityDescription, ...] = ( ), PureEnergieSensorEntityDescription( key="energy_production_total", - name="Energy Production", + translation_key="energy_production_total", native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, @@ -83,6 +83,7 @@ class PureEnergieSensorEntity( ): """Defines an Pure Energie sensor.""" + _attr_has_entity_name = True entity_description: PureEnergieSensorEntityDescription def __init__( diff --git a/homeassistant/components/pure_energie/strings.json b/homeassistant/components/pure_energie/strings.json index a76b4a001e6..3545f62d667 100644 --- a/homeassistant/components/pure_energie/strings.json +++ b/homeassistant/components/pure_energie/strings.json @@ -22,5 +22,18 @@ "already_configured": "[%key:common::config_flow::abort::already_configured_device%]", "cannot_connect": "[%key:common::config_flow::error::cannot_connect%]" } + }, + "entity": { + "sensor": { + "power_flow": { + "name": "Power flow" + }, + "energy_consumption_total": { + "name": "Energy consumption" + }, + "energy_production_total": { + "name": "Energy production" + } + } } } diff --git a/tests/components/pure_energie/test_sensor.py b/tests/components/pure_energie/test_sensor.py index 2881bf28d8f..eb0b9634e83 100644 --- a/tests/components/pure_energie/test_sensor.py +++ b/tests/components/pure_energie/test_sensor.py @@ -34,7 +34,7 @@ async def test_sensors( assert state assert entry.unique_id == "aabbccddeeff_energy_consumption_total" assert state.state == "17762.1" - assert state.attributes.get(ATTR_FRIENDLY_NAME) == "Energy Consumption" + assert state.attributes.get(ATTR_FRIENDLY_NAME) == "home Energy consumption" assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.TOTAL_INCREASING assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfEnergy.KILO_WATT_HOUR assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENERGY @@ -46,7 +46,7 @@ async def test_sensors( assert state assert entry.unique_id == "aabbccddeeff_energy_production_total" assert state.state == "21214.6" - assert state.attributes.get(ATTR_FRIENDLY_NAME) == "Energy Production" + assert state.attributes.get(ATTR_FRIENDLY_NAME) == "home Energy production" assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.TOTAL_INCREASING assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfEnergy.KILO_WATT_HOUR assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENERGY @@ -58,7 +58,7 @@ async def test_sensors( assert state assert entry.unique_id == "aabbccddeeff_power_flow" assert state.state == "338" - assert state.attributes.get(ATTR_FRIENDLY_NAME) == "Power Flow" + assert state.attributes.get(ATTR_FRIENDLY_NAME) == "home Power flow" assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfPower.WATT assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.POWER