Add entity translations to Flux led (#95355)
This commit is contained in:
parent
90854df5b2
commit
e19b29d6ae
8 changed files with 104 additions and 53 deletions
|
@ -9,7 +9,7 @@ from flux_led.const import MODE_MUSIC
|
|||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.switch import SwitchEntity
|
||||
from homeassistant.const import CONF_NAME, EntityCategory
|
||||
from homeassistant.const import EntityCategory
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
@ -34,18 +34,15 @@ async def async_setup_entry(
|
|||
coordinator: FluxLedUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
entities: list[FluxSwitch | FluxRemoteAccessSwitch | FluxMusicSwitch] = []
|
||||
base_unique_id = entry.unique_id or entry.entry_id
|
||||
name = entry.data.get(CONF_NAME, entry.title)
|
||||
|
||||
if coordinator.device.device_type == DeviceType.Switch:
|
||||
entities.append(FluxSwitch(coordinator, base_unique_id, name, None))
|
||||
entities.append(FluxSwitch(coordinator, base_unique_id, None))
|
||||
|
||||
if entry.data.get(CONF_REMOTE_ACCESS_HOST):
|
||||
entities.append(FluxRemoteAccessSwitch(coordinator.device, entry))
|
||||
|
||||
if coordinator.device.microphone:
|
||||
entities.append(
|
||||
FluxMusicSwitch(coordinator, base_unique_id, f"{name} Music", "music")
|
||||
)
|
||||
entities.append(FluxMusicSwitch(coordinator, base_unique_id, "music"))
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
@ -55,6 +52,8 @@ class FluxSwitch(
|
|||
):
|
||||
"""Representation of a Flux switch."""
|
||||
|
||||
_attr_name = None
|
||||
|
||||
async def _async_turn_on(self, **kwargs: Any) -> None:
|
||||
"""Turn the device on."""
|
||||
if not self.is_on:
|
||||
|
@ -65,6 +64,7 @@ class FluxRemoteAccessSwitch(FluxBaseEntity, SwitchEntity):
|
|||
"""Representation of a Flux remote access switch."""
|
||||
|
||||
_attr_entity_category = EntityCategory.CONFIG
|
||||
_attr_translation_key = "remote_access"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
@ -73,7 +73,6 @@ class FluxRemoteAccessSwitch(FluxBaseEntity, SwitchEntity):
|
|||
) -> None:
|
||||
"""Initialize the light."""
|
||||
super().__init__(device, entry)
|
||||
self._attr_name = f"{entry.data.get(CONF_NAME, entry.title)} Remote Access"
|
||||
base_unique_id = entry.unique_id or entry.entry_id
|
||||
self._attr_unique_id = f"{base_unique_id}_remote_access"
|
||||
|
||||
|
@ -113,6 +112,8 @@ class FluxRemoteAccessSwitch(FluxBaseEntity, SwitchEntity):
|
|||
class FluxMusicSwitch(FluxEntity, SwitchEntity):
|
||||
"""Representation of a Flux music switch."""
|
||||
|
||||
_attr_translation_key = "music"
|
||||
|
||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||
"""Turn the microphone on."""
|
||||
await self._async_ensure_device_on()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue