mirror of
https://github.com/home-assistant/core.git
synced 2025-04-26 02:07:54 +00:00
Add entity name translations to Rituals Perfume Genie (#92549)
This commit is contained in:
parent
88893121a1
commit
9e53bca452
@ -39,7 +39,7 @@ class RitualsBinarySensorEntityDescription(
|
||||
ENTITY_DESCRIPTIONS = (
|
||||
RitualsBinarySensorEntityDescription(
|
||||
key="charging",
|
||||
name="Battery Charging",
|
||||
translation_key="charging",
|
||||
device_class=BinarySensorDeviceClass.BATTERY_CHARGING,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
is_on_fn=lambda diffuser: diffuser.charging,
|
||||
@ -71,15 +71,6 @@ class RitualsBinarySensorEntity(DiffuserEntity, BinarySensorEntity):
|
||||
|
||||
entity_description: RitualsBinarySensorEntityDescription
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: RitualsDataUpdateCoordinator,
|
||||
description: RitualsBinarySensorEntityDescription,
|
||||
) -> None:
|
||||
"""Initialize Rituals binary sensor entity."""
|
||||
super().__init__(coordinator, description)
|
||||
self._attr_name = f"{coordinator.diffuser.name} {description.name}"
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
"""Return the state of the binary sensor."""
|
||||
|
@ -15,6 +15,8 @@ MODEL2 = "The Perfume Genie 2.0"
|
||||
class DiffuserEntity(CoordinatorEntity[RitualsDataUpdateCoordinator]):
|
||||
"""Representation of a diffuser entity."""
|
||||
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: RitualsDataUpdateCoordinator,
|
||||
|
@ -35,7 +35,7 @@ class RitualsNumberEntityDescription(
|
||||
ENTITY_DESCRIPTIONS = (
|
||||
RitualsNumberEntityDescription(
|
||||
key="perfume_amount",
|
||||
name="Perfume Amount",
|
||||
translation_key="perfume_amount",
|
||||
icon="mdi:gauge",
|
||||
native_min_value=1,
|
||||
native_max_value=3,
|
||||
@ -66,15 +66,6 @@ class RitualsNumberEntity(DiffuserEntity, NumberEntity):
|
||||
|
||||
entity_description: RitualsNumberEntityDescription
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: RitualsDataUpdateCoordinator,
|
||||
description: RitualsNumberEntityDescription,
|
||||
) -> None:
|
||||
"""Initialize the diffuser perfume amount number."""
|
||||
super().__init__(coordinator, description)
|
||||
self._attr_name = f"{coordinator.diffuser.name} {description.name}"
|
||||
|
||||
@property
|
||||
def native_value(self) -> int:
|
||||
"""Return the number value."""
|
||||
|
@ -35,7 +35,7 @@ class RitualsSelectEntityDescription(
|
||||
ENTITY_DESCRIPTIONS = (
|
||||
RitualsSelectEntityDescription(
|
||||
key="room_size_square_meter",
|
||||
name="Room Size",
|
||||
translation_key="room_size_square_meter",
|
||||
icon="mdi:ruler-square",
|
||||
unit_of_measurement=AREA_SQUARE_METERS,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
@ -80,7 +80,6 @@ class RitualsSelectEntity(DiffuserEntity, SelectEntity):
|
||||
self._attr_entity_registry_enabled_default = (
|
||||
self.coordinator.diffuser.has_battery
|
||||
)
|
||||
self._attr_name = f"{coordinator.diffuser.name} {description.name}"
|
||||
|
||||
@property
|
||||
def current_option(self) -> str:
|
||||
|
@ -40,7 +40,7 @@ class RitualsSensorEntityDescription(
|
||||
ENTITY_DESCRIPTIONS = (
|
||||
RitualsSensorEntityDescription(
|
||||
key="battery_percentage",
|
||||
name="Battery",
|
||||
translation_key="battery_percentage",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
device_class=SensorDeviceClass.BATTERY,
|
||||
value_fn=lambda diffuser: diffuser.battery_percentage,
|
||||
@ -48,19 +48,19 @@ ENTITY_DESCRIPTIONS = (
|
||||
),
|
||||
RitualsSensorEntityDescription(
|
||||
key="fill",
|
||||
name="Fill",
|
||||
translation_key="fill",
|
||||
icon="mdi:beaker",
|
||||
value_fn=lambda diffuser: diffuser.fill,
|
||||
),
|
||||
RitualsSensorEntityDescription(
|
||||
key="perfume",
|
||||
name="Perfume",
|
||||
translation_key="perfume",
|
||||
icon="mdi:tag",
|
||||
value_fn=lambda diffuser: diffuser.perfume,
|
||||
),
|
||||
RitualsSensorEntityDescription(
|
||||
key="wifi_percentage",
|
||||
name="Wifi",
|
||||
translation_key="wifi_percentage",
|
||||
icon="mdi:wifi",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
value_fn=lambda diffuser: diffuser.wifi_percentage,
|
||||
@ -92,15 +92,6 @@ class RitualsSensorEntity(DiffuserEntity, SensorEntity):
|
||||
entity_description: RitualsSensorEntityDescription
|
||||
_attr_entity_category = EntityCategory.DIAGNOSTIC
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: RitualsDataUpdateCoordinator,
|
||||
description: RitualsSensorEntityDescription,
|
||||
) -> None:
|
||||
"""Initialize the diffuser sensor."""
|
||||
super().__init__(coordinator, description)
|
||||
self._attr_name = f"{coordinator.diffuser.name} {description.name}"
|
||||
|
||||
@property
|
||||
def native_value(self) -> str | int:
|
||||
"""Return the sensor value."""
|
||||
|
@ -17,5 +17,36 @@
|
||||
"abort": {
|
||||
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
|
||||
}
|
||||
},
|
||||
"entity": {
|
||||
"binary_sensor": {
|
||||
"charging": {
|
||||
"name": "[%key:component::binary_sensor::entity_component::battery_charging::name%]"
|
||||
}
|
||||
},
|
||||
"number": {
|
||||
"perfume_amount": {
|
||||
"name": "Perfume amount"
|
||||
}
|
||||
},
|
||||
"select": {
|
||||
"room_size_square_meter": {
|
||||
"name": "Room size"
|
||||
}
|
||||
},
|
||||
"sensor": {
|
||||
"battery_percentage": {
|
||||
"name": "[%key:component::sensor::entity_component::battery::name%]"
|
||||
},
|
||||
"fill": {
|
||||
"name": "Fill"
|
||||
},
|
||||
"perfume": {
|
||||
"name": "Perfume"
|
||||
},
|
||||
"wifi_percentage": {
|
||||
"name": "Wi-Fi signal"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -73,7 +73,6 @@ class RitualsSwitchEntity(DiffuserEntity, SwitchEntity):
|
||||
) -> None:
|
||||
"""Initialize the diffuser switch."""
|
||||
super().__init__(coordinator, description)
|
||||
self._attr_name = coordinator.diffuser.name
|
||||
self._attr_is_on = description.is_on_fn(coordinator.diffuser)
|
||||
|
||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||
|
@ -20,14 +20,14 @@ async def test_binary_sensors(
|
||||
await init_integration(hass, config_entry, [diffuser])
|
||||
hublot = diffuser.hublot
|
||||
|
||||
state = hass.states.get("binary_sensor.genie_battery_charging")
|
||||
state = hass.states.get("binary_sensor.genie_charging")
|
||||
assert state
|
||||
assert state.state == STATE_ON
|
||||
assert (
|
||||
state.attributes[ATTR_DEVICE_CLASS] == BinarySensorDeviceClass.BATTERY_CHARGING
|
||||
)
|
||||
|
||||
entry = entity_registry.async_get("binary_sensor.genie_battery_charging")
|
||||
entry = entity_registry.async_get("binary_sensor.genie_charging")
|
||||
assert entry
|
||||
assert entry.unique_id == f"{hublot}-charging"
|
||||
assert entry.entity_category == EntityCategory.DIAGNOSTIC
|
||||
|
@ -55,13 +55,13 @@ async def test_sensors_diffuser_v1_battery_cartridge(
|
||||
assert entry.unique_id == f"{hublot}-battery_percentage"
|
||||
assert entry.entity_category == EntityCategory.DIAGNOSTIC
|
||||
|
||||
state = hass.states.get("sensor.genie_wifi")
|
||||
state = hass.states.get("sensor.genie_wi_fi_signal")
|
||||
assert state
|
||||
assert state.state == str(diffuser.wifi_percentage)
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) is None
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE
|
||||
|
||||
entry = entity_registry.async_get("sensor.genie_wifi")
|
||||
entry = entity_registry.async_get("sensor.genie_wi_fi_signal")
|
||||
assert entry
|
||||
assert entry.unique_id == f"{hublot}-wifi_percentage"
|
||||
assert entry.entity_category == EntityCategory.DIAGNOSTIC
|
||||
|
Loading…
x
Reference in New Issue
Block a user