mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Add entity translations to Steamist (#96182)
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
parent
9234852e2a
commit
8c0594219f
@ -4,7 +4,7 @@ from __future__ import annotations
|
|||||||
from aiosteamist import SteamistStatus
|
from aiosteamist import SteamistStatus
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
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 import device_registry as dr
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
from homeassistant.helpers.entity import Entity, EntityDescription
|
from homeassistant.helpers.entity import Entity, EntityDescription
|
||||||
@ -14,7 +14,9 @@ from .coordinator import SteamistDataUpdateCoordinator
|
|||||||
|
|
||||||
|
|
||||||
class SteamistEntity(CoordinatorEntity[SteamistDataUpdateCoordinator], Entity):
|
class SteamistEntity(CoordinatorEntity[SteamistDataUpdateCoordinator], Entity):
|
||||||
"""Representation of an Steamist entity."""
|
"""Representation of a Steamist entity."""
|
||||||
|
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@ -25,13 +27,10 @@ class SteamistEntity(CoordinatorEntity[SteamistDataUpdateCoordinator], Entity):
|
|||||||
"""Initialize the entity."""
|
"""Initialize the entity."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self.entity_description = description
|
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}"
|
self._attr_unique_id = f"{entry.entry_id}_{description.key}"
|
||||||
if entry.unique_id: # Only present if UDP broadcast works
|
if entry.unique_id: # Only present if UDP broadcast works
|
||||||
self._attr_device_info = DeviceInfo(
|
self._attr_device_info = DeviceInfo(
|
||||||
connections={(dr.CONNECTION_NETWORK_MAC, entry.unique_id)},
|
connections={(dr.CONNECTION_NETWORK_MAC, entry.unique_id)},
|
||||||
name=entry.data[CONF_NAME],
|
|
||||||
manufacturer="Steamist",
|
manufacturer="Steamist",
|
||||||
model=entry.data[CONF_MODEL],
|
model=entry.data[CONF_MODEL],
|
||||||
configuration_url=f"http://{entry.data[CONF_HOST]}",
|
configuration_url=f"http://{entry.data[CONF_HOST]}",
|
||||||
|
@ -47,13 +47,13 @@ class SteamistSensorEntityDescription(
|
|||||||
SENSORS: tuple[SteamistSensorEntityDescription, ...] = (
|
SENSORS: tuple[SteamistSensorEntityDescription, ...] = (
|
||||||
SteamistSensorEntityDescription(
|
SteamistSensorEntityDescription(
|
||||||
key=_KEY_MINUTES_REMAIN,
|
key=_KEY_MINUTES_REMAIN,
|
||||||
name="Steam Minutes Remain",
|
translation_key="steam_minutes_remain",
|
||||||
native_unit_of_measurement=UnitOfTime.MINUTES,
|
native_unit_of_measurement=UnitOfTime.MINUTES,
|
||||||
value_fn=lambda status: status.minutes_remain,
|
value_fn=lambda status: status.minutes_remain,
|
||||||
),
|
),
|
||||||
SteamistSensorEntityDescription(
|
SteamistSensorEntityDescription(
|
||||||
key=_KEY_TEMP,
|
key=_KEY_TEMP,
|
||||||
name="Steam Temperature",
|
translation_key="steam_temperature",
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
value_fn=lambda status: status.temp,
|
value_fn=lambda status: status.temp,
|
||||||
@ -79,7 +79,7 @@ async def async_setup_entry(
|
|||||||
|
|
||||||
|
|
||||||
class SteamistSensorEntity(SteamistEntity, SensorEntity):
|
class SteamistSensorEntity(SteamistEntity, SensorEntity):
|
||||||
"""Representation of an Steamist steam switch."""
|
"""Representation of a Steamist steam switch."""
|
||||||
|
|
||||||
entity_description: SteamistSensorEntityDescription
|
entity_description: SteamistSensorEntityDescription
|
||||||
|
|
||||||
|
@ -28,5 +28,20 @@
|
|||||||
"no_devices_found": "[%key:common::config_flow::abort::no_devices_found%]",
|
"no_devices_found": "[%key:common::config_flow::abort::no_devices_found%]",
|
||||||
"not_steamist_device": "Not a steamist device"
|
"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"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,9 @@ from .coordinator import SteamistDataUpdateCoordinator
|
|||||||
from .entity import SteamistEntity
|
from .entity import SteamistEntity
|
||||||
|
|
||||||
ACTIVE_SWITCH = SwitchEntityDescription(
|
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):
|
class SteamistSwitchEntity(SteamistEntity, SwitchEntity):
|
||||||
"""Representation of an Steamist steam switch."""
|
"""Representation of a Steamist steam switch."""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user