Add entity translations to Steamist (#96182)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Joost Lekkerkerker 2023-12-23 19:58:54 +01:00 committed by GitHub
parent 9234852e2a
commit 8c0594219f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 10 deletions

View File

@ -4,7 +4,7 @@ from __future__ import annotations
from aiosteamist import SteamistStatus
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST, CONF_MODEL, CONF_NAME
from homeassistant.const import CONF_HOST, CONF_MODEL
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity import Entity, EntityDescription
@ -14,7 +14,9 @@ from .coordinator import SteamistDataUpdateCoordinator
class SteamistEntity(CoordinatorEntity[SteamistDataUpdateCoordinator], Entity):
"""Representation of an Steamist entity."""
"""Representation of a Steamist entity."""
_attr_has_entity_name = True
def __init__(
self,
@ -25,13 +27,10 @@ class SteamistEntity(CoordinatorEntity[SteamistDataUpdateCoordinator], Entity):
"""Initialize the entity."""
super().__init__(coordinator)
self.entity_description = description
if coordinator.device_name:
self._attr_name = f"{coordinator.device_name} {description.name}"
self._attr_unique_id = f"{entry.entry_id}_{description.key}"
if entry.unique_id: # Only present if UDP broadcast works
self._attr_device_info = DeviceInfo(
connections={(dr.CONNECTION_NETWORK_MAC, entry.unique_id)},
name=entry.data[CONF_NAME],
manufacturer="Steamist",
model=entry.data[CONF_MODEL],
configuration_url=f"http://{entry.data[CONF_HOST]}",

View File

@ -47,13 +47,13 @@ class SteamistSensorEntityDescription(
SENSORS: tuple[SteamistSensorEntityDescription, ...] = (
SteamistSensorEntityDescription(
key=_KEY_MINUTES_REMAIN,
name="Steam Minutes Remain",
translation_key="steam_minutes_remain",
native_unit_of_measurement=UnitOfTime.MINUTES,
value_fn=lambda status: status.minutes_remain,
),
SteamistSensorEntityDescription(
key=_KEY_TEMP,
name="Steam Temperature",
translation_key="steam_temperature",
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
value_fn=lambda status: status.temp,
@ -79,7 +79,7 @@ async def async_setup_entry(
class SteamistSensorEntity(SteamistEntity, SensorEntity):
"""Representation of an Steamist steam switch."""
"""Representation of a Steamist steam switch."""
entity_description: SteamistSensorEntityDescription

View File

@ -28,5 +28,20 @@
"no_devices_found": "[%key:common::config_flow::abort::no_devices_found%]",
"not_steamist_device": "Not a steamist device"
}
},
"entity": {
"sensor": {
"steam_minutes_remain": {
"name": "Steam minutes remain"
},
"steam_temperature": {
"name": "Steam temperature"
}
},
"switch": {
"steam_active": {
"name": "Steam active"
}
}
}
}

View File

@ -13,7 +13,9 @@ from .coordinator import SteamistDataUpdateCoordinator
from .entity import SteamistEntity
ACTIVE_SWITCH = SwitchEntityDescription(
key="active", icon="mdi:pot-steam", name="Steam Active"
key="active",
icon="mdi:pot-steam",
translation_key="steam_active",
)
@ -30,7 +32,7 @@ async def async_setup_entry(
class SteamistSwitchEntity(SteamistEntity, SwitchEntity):
"""Representation of an Steamist steam switch."""
"""Representation of a Steamist steam switch."""
@property
def is_on(self) -> bool: