2021-03-16 23:32:02 +00:00
|
|
|
"""Support for a ScreenLogic 'circuit' switch."""
|
|
|
|
import logging
|
|
|
|
|
2021-10-20 22:38:21 +00:00
|
|
|
from screenlogicpy.const import DATA as SL_DATA, GENERIC_CIRCUIT_NAMES
|
2021-03-16 23:32:02 +00:00
|
|
|
|
|
|
|
from homeassistant.components.switch import SwitchEntity
|
2022-01-03 15:44:20 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2021-03-16 23:32:02 +00:00
|
|
|
|
2021-10-20 22:38:21 +00:00
|
|
|
from . import ScreenLogicCircuitEntity
|
|
|
|
from .const import DOMAIN, LIGHT_CIRCUIT_FUNCTIONS
|
2021-03-16 23:32:02 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2022-01-03 15:44:20 +00:00
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
config_entry: ConfigEntry,
|
|
|
|
async_add_entities: AddEntitiesCallback,
|
|
|
|
) -> None:
|
2021-03-16 23:32:02 +00:00
|
|
|
"""Set up entry."""
|
2021-10-20 22:38:21 +00:00
|
|
|
coordinator = hass.data[DOMAIN][config_entry.entry_id]
|
|
|
|
async_add_entities(
|
|
|
|
[
|
|
|
|
ScreenLogicSwitch(
|
|
|
|
coordinator, circuit_num, circuit["name"] not in GENERIC_CIRCUIT_NAMES
|
2021-03-29 23:27:17 +00:00
|
|
|
)
|
2021-10-20 22:38:21 +00:00
|
|
|
for circuit_num, circuit in coordinator.data[SL_DATA.KEY_CIRCUITS].items()
|
|
|
|
if circuit["function"] not in LIGHT_CIRCUIT_FUNCTIONS
|
|
|
|
]
|
|
|
|
)
|
2021-03-29 23:27:17 +00:00
|
|
|
|
2021-03-16 23:32:02 +00:00
|
|
|
|
2021-10-20 22:38:21 +00:00
|
|
|
class ScreenLogicSwitch(ScreenLogicCircuitEntity, SwitchEntity):
|
|
|
|
"""Class to represent a ScreenLogic Switch."""
|