2019-04-03 15:40:03 +00:00
|
|
|
"""Light support for switch entities."""
|
2021-03-18 13:31:38 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2018-11-20 10:51:34 +00:00
|
|
|
import voluptuous as vol
|
|
|
|
|
2022-03-10 11:23:01 +00:00
|
|
|
from homeassistant.components.light import PLATFORM_SCHEMA
|
|
|
|
from homeassistant.components.switch_as_x import LightSwitch
|
|
|
|
from homeassistant.const import CONF_ENTITY_ID, CONF_NAME
|
|
|
|
from homeassistant.core import HomeAssistant
|
2021-12-31 11:47:16 +00:00
|
|
|
from homeassistant.helpers import entity_registry as er
|
2018-11-20 10:51:34 +00:00
|
|
|
import homeassistant.helpers.config_validation as cv
|
2021-05-04 12:50:06 +00:00
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2021-03-29 23:24:56 +00:00
|
|
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2022-03-10 11:23:01 +00:00
|
|
|
from .const import DOMAIN as SWITCH_DOMAIN
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
DEFAULT_NAME = "Light Switch"
|
2018-11-20 10:51:34 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|
|
|
{
|
|
|
|
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
2022-03-10 11:23:01 +00:00
|
|
|
vol.Required(CONF_ENTITY_ID): cv.entity_domain(SWITCH_DOMAIN),
|
2019-07-31 19:25:30 +00:00
|
|
|
}
|
|
|
|
)
|
2018-11-20 10:51:34 +00:00
|
|
|
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
async def async_setup_platform(
|
2021-03-29 23:24:56 +00:00
|
|
|
hass: HomeAssistant,
|
2019-09-20 15:23:34 +00:00
|
|
|
config: ConfigType,
|
2021-05-04 12:50:06 +00:00
|
|
|
async_add_entities: AddEntitiesCallback,
|
2021-03-18 13:31:38 +00:00
|
|
|
discovery_info: DiscoveryInfoType | None = None,
|
2019-07-31 19:25:30 +00:00
|
|
|
) -> None:
|
2018-11-20 10:51:34 +00:00
|
|
|
"""Initialize Light Switch platform."""
|
2021-12-31 11:47:16 +00:00
|
|
|
registry = er.async_get(hass)
|
2020-09-30 11:05:18 +00:00
|
|
|
wrapped_switch = registry.async_get(config[CONF_ENTITY_ID])
|
|
|
|
unique_id = wrapped_switch.unique_id if wrapped_switch else None
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
async_add_entities(
|
2020-09-30 11:05:18 +00:00
|
|
|
[
|
|
|
|
LightSwitch(
|
2021-12-31 11:47:16 +00:00
|
|
|
config[CONF_NAME],
|
2020-09-30 11:05:18 +00:00
|
|
|
config[CONF_ENTITY_ID],
|
|
|
|
unique_id,
|
|
|
|
)
|
2021-03-03 18:13:04 +00:00
|
|
|
]
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|