Add entity translations to iOS (#95467)

pull/95509/head
Joost Lekkerkerker 2023-06-29 04:22:55 +02:00 committed by GitHub
parent b0c0b58340
commit 48049d588c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 6 deletions

View File

@ -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}"

View File

@ -8,5 +8,12 @@
"abort": {
"single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]"
}
},
"entity": {
"sensor": {
"battery_state": {
"name": "Battery state"
}
}
}
}