From 48049d588cf394bd9bace94206aae2934b43ceff Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Thu, 29 Jun 2023 04:22:55 +0200 Subject: [PATCH] Add entity translations to iOS (#95467) --- homeassistant/components/ios/sensor.py | 14 ++++++++------ homeassistant/components/ios/strings.json | 7 +++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/ios/sensor.py b/homeassistant/components/ios/sensor.py index f4dab9e301b..f3767be9f3d 100644 --- a/homeassistant/components/ios/sensor.py +++ b/homeassistant/components/ios/sensor.py @@ -1,7 +1,11 @@ """Support for Home Assistant iOS app sensors.""" from __future__ import annotations -from homeassistant.components.sensor import SensorEntity, SensorEntityDescription +from homeassistant.components.sensor import ( + SensorDeviceClass, + SensorEntity, + SensorEntityDescription, +) from homeassistant.config_entries import ConfigEntry from homeassistant.const import PERCENTAGE from homeassistant.core import HomeAssistant, callback @@ -17,12 +21,12 @@ from .const import DOMAIN SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="level", - name="Battery Level", native_unit_of_measurement=PERCENTAGE, + device_class=SensorDeviceClass.BATTERY, ), SensorEntityDescription( key="state", - name="Battery State", + translation_key="battery_state", ), ) @@ -59,6 +63,7 @@ class IOSSensor(SensorEntity): """Representation of an iOS sensor.""" _attr_should_poll = False + _attr_has_entity_name = True def __init__( self, device_name, device, description: SensorEntityDescription @@ -67,9 +72,6 @@ class IOSSensor(SensorEntity): self.entity_description = description self._device = device - device_name = device[ios.ATTR_DEVICE][ios.ATTR_DEVICE_NAME] - self._attr_name = f"{device_name} {description.key}" - device_id = device[ios.ATTR_DEVICE_ID] self._attr_unique_id = f"{description.key}_{device_id}" diff --git a/homeassistant/components/ios/strings.json b/homeassistant/components/ios/strings.json index 2b486cc0c04..6c77209e317 100644 --- a/homeassistant/components/ios/strings.json +++ b/homeassistant/components/ios/strings.json @@ -8,5 +8,12 @@ "abort": { "single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]" } + }, + "entity": { + "sensor": { + "battery_state": { + "name": "Battery state" + } + } } }