2021-12-08 08:30:22 +00:00
|
|
|
"""Support for Magic Home switches."""
|
2021-10-11 17:20:11 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from typing import Any
|
|
|
|
|
|
|
|
from homeassistant import config_entries
|
|
|
|
from homeassistant.components.switch import SwitchEntity
|
|
|
|
from homeassistant.const import CONF_NAME
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
|
|
|
|
|
|
|
from . import FluxLedUpdateCoordinator
|
|
|
|
from .const import DOMAIN
|
2021-11-23 00:52:06 +00:00
|
|
|
from .entity import FluxOnOffEntity
|
2021-10-11 17:20:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
entry: config_entries.ConfigEntry,
|
|
|
|
async_add_entities: AddEntitiesCallback,
|
|
|
|
) -> None:
|
|
|
|
"""Set up the Flux lights."""
|
|
|
|
coordinator: FluxLedUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
|
|
|
async_add_entities(
|
|
|
|
[
|
|
|
|
FluxSwitch(
|
|
|
|
coordinator,
|
|
|
|
entry.unique_id,
|
|
|
|
entry.data[CONF_NAME],
|
|
|
|
)
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-11-23 00:52:06 +00:00
|
|
|
class FluxSwitch(FluxOnOffEntity, CoordinatorEntity, SwitchEntity):
|
2021-10-11 17:20:11 +00:00
|
|
|
"""Representation of a Flux switch."""
|
|
|
|
|
|
|
|
async def _async_turn_on(self, **kwargs: Any) -> None:
|
|
|
|
"""Turn the device on."""
|
|
|
|
if not self.is_on:
|
|
|
|
await self._device.async_turn_on()
|