Add entity translations to Modern Forms (#95738)

pull/97066/head
Joost Lekkerkerker 2023-07-22 16:19:37 +02:00 committed by GitHub
parent d708c159e7
commit 47426e50d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 53 additions and 22 deletions

View File

@ -121,12 +121,13 @@ class ModernFormsDataUpdateCoordinator(DataUpdateCoordinator[ModernFormsDeviceSt
class ModernFormsDeviceEntity(CoordinatorEntity[ModernFormsDataUpdateCoordinator]):
"""Defines a Modern Forms device entity."""
_attr_has_entity_name = True
def __init__(
self,
*,
entry_id: str,
coordinator: ModernFormsDataUpdateCoordinator,
name: str,
icon: str | None = None,
enabled_default: bool = True,
) -> None:
@ -135,7 +136,6 @@ class ModernFormsDeviceEntity(CoordinatorEntity[ModernFormsDataUpdateCoordinator
self._attr_enabled_default = enabled_default
self._entry_id = entry_id
self._attr_icon = icon
self._attr_name = name
@property
def device_info(self) -> DeviceInfo:

View File

@ -40,14 +40,11 @@ class ModernFormsBinarySensor(ModernFormsDeviceEntity, BinarySensorEntity):
*,
entry_id: str,
coordinator: ModernFormsDataUpdateCoordinator,
name: str,
icon: str,
key: str,
) -> None:
"""Initialize Modern Forms switch."""
super().__init__(
entry_id=entry_id, coordinator=coordinator, name=name, icon=icon
)
super().__init__(entry_id=entry_id, coordinator=coordinator, icon=icon)
self._attr_unique_id = f"{coordinator.data.info.mac_address}_{key}"
@ -56,6 +53,7 @@ class ModernFormsLightSleepTimerActive(ModernFormsBinarySensor):
"""Defines a Modern Forms Light Sleep Timer Active sensor."""
_attr_entity_registry_enabled_default = False
_attr_translation_key = "light_sleep_timer_active"
def __init__(
self, entry_id: str, coordinator: ModernFormsDataUpdateCoordinator
@ -66,7 +64,6 @@ class ModernFormsLightSleepTimerActive(ModernFormsBinarySensor):
entry_id=entry_id,
icon="mdi:av-timer",
key="light_sleep_timer_active",
name=f"{coordinator.data.info.device_name} Light Sleep Timer Active",
)
@property
@ -88,6 +85,7 @@ class ModernFormsFanSleepTimerActive(ModernFormsBinarySensor):
"""Defines a Modern Forms Fan Sleep Timer Active sensor."""
_attr_entity_registry_enabled_default = False
_attr_translation_key = "fan_sleep_timer_active"
def __init__(
self, entry_id: str, coordinator: ModernFormsDataUpdateCoordinator
@ -98,7 +96,6 @@ class ModernFormsFanSleepTimerActive(ModernFormsBinarySensor):
entry_id=entry_id,
icon="mdi:av-timer",
key="fan_sleep_timer_active",
name=f"{coordinator.data.info.device_name} Fan Sleep Timer Active",
)
@property

View File

@ -73,6 +73,7 @@ class ModernFormsFanEntity(FanEntity, ModernFormsDeviceEntity):
SPEED_RANGE = (1, 6) # off is not included
_attr_supported_features = FanEntityFeature.DIRECTION | FanEntityFeature.SET_SPEED
_attr_translation_key = "fan"
def __init__(
self, entry_id: str, coordinator: ModernFormsDataUpdateCoordinator
@ -81,7 +82,6 @@ class ModernFormsFanEntity(FanEntity, ModernFormsDeviceEntity):
super().__init__(
entry_id=entry_id,
coordinator=coordinator,
name=f"{coordinator.data.info.device_name} Fan",
)
self._attr_unique_id = f"{self.coordinator.data.info.mac_address}"

View File

@ -81,6 +81,7 @@ class ModernFormsLightEntity(ModernFormsDeviceEntity, LightEntity):
_attr_color_mode = ColorMode.BRIGHTNESS
_attr_supported_color_modes = {ColorMode.BRIGHTNESS}
_attr_translation_key = "light"
def __init__(
self, entry_id: str, coordinator: ModernFormsDataUpdateCoordinator
@ -89,7 +90,6 @@ class ModernFormsLightEntity(ModernFormsDeviceEntity, LightEntity):
super().__init__(
entry_id=entry_id,
coordinator=coordinator,
name=f"{coordinator.data.info.device_name} Light",
icon=None,
)
self._attr_unique_id = f"{self.coordinator.data.info.mac_address}"

View File

@ -43,21 +43,20 @@ class ModernFormsSensor(ModernFormsDeviceEntity, SensorEntity):
*,
entry_id: str,
coordinator: ModernFormsDataUpdateCoordinator,
name: str,
icon: str,
key: str,
) -> None:
"""Initialize Modern Forms switch."""
self._key = key
super().__init__(
entry_id=entry_id, coordinator=coordinator, name=name, icon=icon
)
super().__init__(entry_id=entry_id, coordinator=coordinator, icon=icon)
self._attr_unique_id = f"{self.coordinator.data.info.mac_address}_{self._key}"
class ModernFormsLightTimerRemainingTimeSensor(ModernFormsSensor):
"""Defines the Modern Forms Light Timer remaining time sensor."""
_attr_translation_key = "light_timer_remaining_time"
def __init__(
self, entry_id: str, coordinator: ModernFormsDataUpdateCoordinator
) -> None:
@ -67,7 +66,6 @@ class ModernFormsLightTimerRemainingTimeSensor(ModernFormsSensor):
entry_id=entry_id,
icon="mdi:timer-outline",
key="light_timer_remaining_time",
name=f"{coordinator.data.info.device_name} Light Sleep Time",
)
self._attr_device_class = SensorDeviceClass.TIMESTAMP
@ -88,6 +86,8 @@ class ModernFormsLightTimerRemainingTimeSensor(ModernFormsSensor):
class ModernFormsFanTimerRemainingTimeSensor(ModernFormsSensor):
"""Defines the Modern Forms Light Timer remaining time sensor."""
_attr_translation_key = "fan_timer_remaining_time"
def __init__(
self, entry_id: str, coordinator: ModernFormsDataUpdateCoordinator
) -> None:
@ -97,7 +97,6 @@ class ModernFormsFanTimerRemainingTimeSensor(ModernFormsSensor):
entry_id=entry_id,
icon="mdi:timer-outline",
key="fan_timer_remaining_time",
name=f"{coordinator.data.info.device_name} Fan Sleep Time",
)
self._attr_device_class = SensorDeviceClass.TIMESTAMP

View File

@ -21,6 +21,42 @@
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]"
}
},
"entity": {
"binary_sensor": {
"light_sleep_timer_active": {
"name": "Light sleep timer active"
},
"fan_sleep_timer_active": {
"name": "Fan sleep timer active"
}
},
"fan": {
"fan": {
"name": "[%key:component::fan::title%]"
}
},
"light": {
"light": {
"name": "[%key:component::light::title%]"
}
},
"sensor": {
"light_timer_remaining_time": {
"name": "Light sleep time"
},
"fan_timer_remaining_time": {
"name": "Fan sleep time"
}
},
"switch": {
"away_mode": {
"name": "Away mode"
},
"adaptive_learning": {
"name": "Adaptive learning"
}
}
},
"services": {
"set_light_sleep_timer": {
"name": "Set light sleep timer",

View File

@ -39,21 +39,20 @@ class ModernFormsSwitch(ModernFormsDeviceEntity, SwitchEntity):
*,
entry_id: str,
coordinator: ModernFormsDataUpdateCoordinator,
name: str,
icon: str,
key: str,
) -> None:
"""Initialize Modern Forms switch."""
self._key = key
super().__init__(
entry_id=entry_id, coordinator=coordinator, name=name, icon=icon
)
super().__init__(entry_id=entry_id, coordinator=coordinator, icon=icon)
self._attr_unique_id = f"{self.coordinator.data.info.mac_address}_{self._key}"
class ModernFormsAwaySwitch(ModernFormsSwitch):
"""Defines a Modern Forms Away mode switch."""
_attr_translation_key = "away_mode"
def __init__(
self, entry_id: str, coordinator: ModernFormsDataUpdateCoordinator
) -> None:
@ -63,7 +62,6 @@ class ModernFormsAwaySwitch(ModernFormsSwitch):
entry_id=entry_id,
icon="mdi:airplane-takeoff",
key="away_mode",
name=f"{coordinator.data.info.device_name} Away Mode",
)
@property
@ -85,6 +83,8 @@ class ModernFormsAwaySwitch(ModernFormsSwitch):
class ModernFormsAdaptiveLearningSwitch(ModernFormsSwitch):
"""Defines a Modern Forms Adaptive Learning switch."""
_attr_translation_key = "adaptive_learning"
def __init__(
self, entry_id: str, coordinator: ModernFormsDataUpdateCoordinator
) -> None:
@ -94,7 +94,6 @@ class ModernFormsAdaptiveLearningSwitch(ModernFormsSwitch):
entry_id=entry_id,
icon="mdi:school-outline",
key="adaptive_learning",
name=f"{coordinator.data.info.device_name} Adaptive Learning",
)
@property