From 77ebf8a8e5cdfc939884c92c1d5d43a31b87ca92 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Tue, 11 Jul 2023 20:34:11 +0200 Subject: [PATCH] Add entity translations to Juicenet (#95487) --- homeassistant/components/juicenet/entity.py | 2 ++ homeassistant/components/juicenet/number.py | 4 +--- homeassistant/components/juicenet/sensor.py | 9 ++------- .../components/juicenet/strings.json | 20 +++++++++++++++++++ homeassistant/components/juicenet/switch.py | 7 ++----- 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/homeassistant/components/juicenet/entity.py b/homeassistant/components/juicenet/entity.py index 0f3811bef6f..2f25a934e7f 100644 --- a/homeassistant/components/juicenet/entity.py +++ b/homeassistant/components/juicenet/entity.py @@ -14,6 +14,8 @@ from .const import DOMAIN class JuiceNetDevice(CoordinatorEntity): """Represent a base JuiceNet device.""" + _attr_has_entity_name = True + def __init__( self, device: Charger, key: str, coordinator: DataUpdateCoordinator ) -> None: diff --git a/homeassistant/components/juicenet/number.py b/homeassistant/components/juicenet/number.py index 45be1dd9004..e78f6189baf 100644 --- a/homeassistant/components/juicenet/number.py +++ b/homeassistant/components/juicenet/number.py @@ -37,7 +37,7 @@ class JuiceNetNumberEntityDescription( NUMBER_TYPES: tuple[JuiceNetNumberEntityDescription, ...] = ( JuiceNetNumberEntityDescription( - name="Amperage Limit", + translation_key="amperage_limit", key="current_charging_amperage_limit", native_min_value=6, native_max_value_key="max_charging_amperage", @@ -80,8 +80,6 @@ class JuiceNetNumber(JuiceNetDevice, NumberEntity): super().__init__(device, description.key, coordinator) self.entity_description = description - self._attr_name = f"{self.device.name} {description.name}" - @property def native_value(self) -> float | None: """Return the value of the entity.""" diff --git a/homeassistant/components/juicenet/sensor.py b/homeassistant/components/juicenet/sensor.py index fdc40211d77..5f71e066b9c 100644 --- a/homeassistant/components/juicenet/sensor.py +++ b/homeassistant/components/juicenet/sensor.py @@ -29,40 +29,36 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( ), SensorEntityDescription( key="temperature", - name="Temperature", native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, ), SensorEntityDescription( key="voltage", - name="Voltage", native_unit_of_measurement=UnitOfElectricPotential.VOLT, device_class=SensorDeviceClass.VOLTAGE, ), SensorEntityDescription( key="amps", - name="Amps", native_unit_of_measurement=UnitOfElectricCurrent.AMPERE, device_class=SensorDeviceClass.CURRENT, state_class=SensorStateClass.MEASUREMENT, ), SensorEntityDescription( key="watts", - name="Watts", native_unit_of_measurement=UnitOfPower.WATT, device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, ), SensorEntityDescription( key="charge_time", - name="Charge time", + translation_key="charge_time", native_unit_of_measurement=UnitOfTime.SECONDS, icon="mdi:timer-outline", ), SensorEntityDescription( key="energy_added", - name="Energy added", + translation_key="energy_added", native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, @@ -97,7 +93,6 @@ class JuiceNetSensorDevice(JuiceNetDevice, SensorEntity): """Initialise the sensor.""" super().__init__(device, description.key, coordinator) self.entity_description = description - self._attr_name = f"{self.device.name} {description.name}" @property def icon(self): diff --git a/homeassistant/components/juicenet/strings.json b/homeassistant/components/juicenet/strings.json index bc4a66e72d4..0e3732c66d2 100644 --- a/homeassistant/components/juicenet/strings.json +++ b/homeassistant/components/juicenet/strings.json @@ -17,5 +17,25 @@ "title": "Connect to JuiceNet" } } + }, + "entity": { + "number": { + "amperage_limit": { + "name": "Amperage limit" + } + }, + "sensor": { + "charge_time": { + "name": "Charge time" + }, + "energy_added": { + "name": "Energy added" + } + }, + "switch": { + "charge_now": { + "name": "Charge now" + } + } } } diff --git a/homeassistant/components/juicenet/switch.py b/homeassistant/components/juicenet/switch.py index 576c66c0841..7c373eeeb24 100644 --- a/homeassistant/components/juicenet/switch.py +++ b/homeassistant/components/juicenet/switch.py @@ -29,15 +29,12 @@ async def async_setup_entry( class JuiceNetChargeNowSwitch(JuiceNetDevice, SwitchEntity): """Implementation of a JuiceNet switch.""" + _attr_translation_key = "charge_now" + def __init__(self, device, coordinator): """Initialise the switch.""" super().__init__(device, "charge_now", coordinator) - @property - def name(self): - """Return the name of the device.""" - return f"{self.device.name} Charge Now" - @property def is_on(self): """Return true if switch is on."""