47 lines
1.2 KiB
Python
47 lines
1.2 KiB
Python
"""Light support for switch entities."""
|
|
from __future__ import annotations
|
|
|
|
from homeassistant.components.light import (
|
|
DOMAIN as LIGHT_DOMAIN,
|
|
ColorMode,
|
|
LightEntity,
|
|
)
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.const import CONF_ENTITY_ID
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers import entity_registry as er
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
from .entity import BaseToggleEntity
|
|
|
|
|
|
async def async_setup_entry(
|
|
hass: HomeAssistant,
|
|
config_entry: ConfigEntry,
|
|
async_add_entities: AddEntitiesCallback,
|
|
) -> None:
|
|
"""Initialize Light Switch config entry."""
|
|
registry = er.async_get(hass)
|
|
entity_id = er.async_validate_entity_id(
|
|
registry, config_entry.options[CONF_ENTITY_ID]
|
|
)
|
|
|
|
async_add_entities(
|
|
[
|
|
LightSwitch(
|
|
hass,
|
|
config_entry.title,
|
|
LIGHT_DOMAIN,
|
|
entity_id,
|
|
config_entry.entry_id,
|
|
)
|
|
]
|
|
)
|
|
|
|
|
|
class LightSwitch(BaseToggleEntity, LightEntity):
|
|
"""Represents a Switch as a Light."""
|
|
|
|
_attr_color_mode = ColorMode.ONOFF
|
|
_attr_supported_color_modes = {ColorMode.ONOFF}
|