From b65e3ddc99d8dfee73e5fffd998f981e3e08df0b Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Tue, 22 Aug 2023 22:21:20 +0200 Subject: [PATCH] Add entity translations to OVO Energy (#98835) --- .../components/ovo_energy/__init__.py | 2 ++ homeassistant/components/ovo_energy/sensor.py | 16 +++++------ .../components/ovo_energy/strings.json | 28 +++++++++++++++++++ 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/ovo_energy/__init__.py b/homeassistant/components/ovo_energy/__init__.py index 99dd02a36a1..f9547fc3493 100644 --- a/homeassistant/components/ovo_energy/__init__.py +++ b/homeassistant/components/ovo_energy/__init__.py @@ -98,6 +98,8 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: class OVOEnergyEntity(CoordinatorEntity[DataUpdateCoordinator[OVODailyUsage]]): """Defines a base OVO Energy entity.""" + _attr_has_entity_name = True + def __init__( self, coordinator: DataUpdateCoordinator[OVODailyUsage], diff --git a/homeassistant/components/ovo_energy/sensor.py b/homeassistant/components/ovo_energy/sensor.py index 2a4005e748f..b32a17f0323 100644 --- a/homeassistant/components/ovo_energy/sensor.py +++ b/homeassistant/components/ovo_energy/sensor.py @@ -43,7 +43,7 @@ class OVOEnergySensorEntityDescription(SensorEntityDescription): SENSOR_TYPES_ELECTRICITY: tuple[OVOEnergySensorEntityDescription, ...] = ( OVOEnergySensorEntityDescription( key="last_electricity_reading", - name="OVO Last Electricity Reading", + translation_key="last_electricity_reading", device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, @@ -51,7 +51,7 @@ SENSOR_TYPES_ELECTRICITY: tuple[OVOEnergySensorEntityDescription, ...] = ( ), OVOEnergySensorEntityDescription( key=KEY_LAST_ELECTRICITY_COST, - name="OVO Last Electricity Cost", + translation_key=KEY_LAST_ELECTRICITY_COST, device_class=SensorDeviceClass.MONETARY, state_class=SensorStateClass.TOTAL_INCREASING, value=lambda usage: usage.electricity[-1].cost.amount @@ -60,14 +60,14 @@ SENSOR_TYPES_ELECTRICITY: tuple[OVOEnergySensorEntityDescription, ...] = ( ), OVOEnergySensorEntityDescription( key="last_electricity_start_time", - name="OVO Last Electricity Start Time", + translation_key="last_electricity_start_time", entity_registry_enabled_default=False, device_class=SensorDeviceClass.TIMESTAMP, value=lambda usage: dt_util.as_utc(usage.electricity[-1].interval.start), ), OVOEnergySensorEntityDescription( key="last_electricity_end_time", - name="OVO Last Electricity End Time", + translation_key="last_electricity_end_time", entity_registry_enabled_default=False, device_class=SensorDeviceClass.TIMESTAMP, value=lambda usage: dt_util.as_utc(usage.electricity[-1].interval.end), @@ -77,7 +77,7 @@ SENSOR_TYPES_ELECTRICITY: tuple[OVOEnergySensorEntityDescription, ...] = ( SENSOR_TYPES_GAS: tuple[OVOEnergySensorEntityDescription, ...] = ( OVOEnergySensorEntityDescription( key="last_gas_reading", - name="OVO Last Gas Reading", + translation_key="last_gas_reading", device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, @@ -86,7 +86,7 @@ SENSOR_TYPES_GAS: tuple[OVOEnergySensorEntityDescription, ...] = ( ), OVOEnergySensorEntityDescription( key=KEY_LAST_GAS_COST, - name="OVO Last Gas Cost", + translation_key=KEY_LAST_GAS_COST, device_class=SensorDeviceClass.MONETARY, state_class=SensorStateClass.TOTAL_INCREASING, icon="mdi:cash-multiple", @@ -96,14 +96,14 @@ SENSOR_TYPES_GAS: tuple[OVOEnergySensorEntityDescription, ...] = ( ), OVOEnergySensorEntityDescription( key="last_gas_start_time", - name="OVO Last Gas Start Time", + translation_key="last_gas_start_time", entity_registry_enabled_default=False, device_class=SensorDeviceClass.TIMESTAMP, value=lambda usage: dt_util.as_utc(usage.gas[-1].interval.start), ), OVOEnergySensorEntityDescription( key="last_gas_end_time", - name="OVO Last Gas End Time", + translation_key="last_gas_end_time", entity_registry_enabled_default=False, device_class=SensorDeviceClass.TIMESTAMP, value=lambda usage: dt_util.as_utc(usage.gas[-1].interval.end), diff --git a/homeassistant/components/ovo_energy/strings.json b/homeassistant/components/ovo_energy/strings.json index 810602b1412..fda0c2996dc 100644 --- a/homeassistant/components/ovo_energy/strings.json +++ b/homeassistant/components/ovo_energy/strings.json @@ -24,5 +24,33 @@ "title": "Reauthentication" } } + }, + "entity": { + "sensor": { + "last_electricity_reading": { + "name": "Last electricity reading" + }, + "last_electricity_cost": { + "name": "Last electricity cost" + }, + "last_electricity_start_time": { + "name": "Last electricity start time" + }, + "last_electricity_end_time": { + "name": "Last electricity end time" + }, + "last_gas_reading": { + "name": "Last gas reading" + }, + "last_gas_cost": { + "name": "Last gas cost" + }, + "last_gas_start_time": { + "name": "Last gas start time" + }, + "last_gas_end_time": { + "name": "Last gas end time" + } + } } }