2021-10-20 22:38:21 +00:00
|
|
|
"""Support for a ScreenLogic light 'circuit' switch."""
|
|
|
|
import logging
|
|
|
|
|
2023-02-07 02:13:36 +00:00
|
|
|
from screenlogicpy.const import CODE, DATA as SL_DATA, GENERIC_CIRCUIT_NAMES
|
2021-10-20 22:38:21 +00:00
|
|
|
|
2022-04-27 13:42:35 +00:00
|
|
|
from homeassistant.components.light import ColorMode, LightEntity
|
2022-01-03 14:43:55 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2021-10-20 22:38:21 +00:00
|
|
|
|
2023-02-07 02:13:36 +00:00
|
|
|
from . import ScreenlogicDataUpdateCoordinator
|
2021-10-20 22:38:21 +00:00
|
|
|
from .const import DOMAIN, LIGHT_CIRCUIT_FUNCTIONS
|
2023-02-07 02:13:36 +00:00
|
|
|
from .entity import ScreenLogicCircuitEntity
|
2021-10-20 22:38:21 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2022-01-03 14:43:55 +00:00
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
config_entry: ConfigEntry,
|
|
|
|
async_add_entities: AddEntitiesCallback,
|
|
|
|
) -> None:
|
2021-10-20 22:38:21 +00:00
|
|
|
"""Set up entry."""
|
2023-02-07 02:13:36 +00:00
|
|
|
coordinator: ScreenlogicDataUpdateCoordinator = hass.data[DOMAIN][
|
|
|
|
config_entry.entry_id
|
|
|
|
]
|
|
|
|
circuits = coordinator.gateway_data[SL_DATA.KEY_CIRCUITS]
|
2021-10-20 22:38:21 +00:00
|
|
|
async_add_entities(
|
|
|
|
[
|
|
|
|
ScreenLogicLight(
|
2023-02-07 02:13:36 +00:00
|
|
|
coordinator,
|
|
|
|
circuit_num,
|
|
|
|
CODE.STATUS_CHANGED,
|
|
|
|
circuit["name"] not in GENERIC_CIRCUIT_NAMES,
|
2021-10-20 22:38:21 +00:00
|
|
|
)
|
2023-02-07 02:13:36 +00:00
|
|
|
for circuit_num, circuit in circuits.items()
|
2021-10-20 22:38:21 +00:00
|
|
|
if circuit["function"] in LIGHT_CIRCUIT_FUNCTIONS
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class ScreenLogicLight(ScreenLogicCircuitEntity, LightEntity):
|
|
|
|
"""Class to represent a ScreenLogic Light."""
|
2022-04-27 13:42:35 +00:00
|
|
|
|
|
|
|
_attr_color_mode = ColorMode.ONOFF
|
|
|
|
_attr_supported_color_modes = {ColorMode.ONOFF}
|