Add entity translations to iOS (#95467)
parent
b0c0b58340
commit
48049d588c
|
@ -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}"
|
||||
|
||||
|
|
|
@ -8,5 +8,12 @@
|
|||
"abort": {
|
||||
"single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]"
|
||||
}
|
||||
},
|
||||
"entity": {
|
||||
"sensor": {
|
||||
"battery_state": {
|
||||
"name": "Battery state"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue