1 """Support for SCSGate lights."""
3 from __future__
import annotations
8 from scsgate.tasks
import ToggleStatusTask
9 import voluptuous
as vol
12 PLATFORM_SCHEMA
as LIGHT_PLATFORM_SCHEMA,
22 from .
import CONF_SCS_ID, DOMAIN, SCSGATE_SCHEMA
24 PLATFORM_SCHEMA = LIGHT_PLATFORM_SCHEMA.extend(
25 {vol.Required(CONF_DEVICES): cv.schema_with_slug_keys(SCSGATE_SCHEMA)}
32 add_entities: AddEntitiesCallback,
33 discovery_info: DiscoveryInfoType |
None =
None,
35 """Set up the SCSGate switches."""
36 devices = config.get(CONF_DEVICES)
38 logger = logging.getLogger(__name__)
39 scsgate = hass.data[DOMAIN]
42 for entity_info
in devices.values():
43 if entity_info[CONF_SCS_ID]
in scsgate.devices:
46 name = entity_info[CONF_NAME]
47 scs_id = entity_info[CONF_SCS_ID]
49 logger.info(
"Adding %s scsgate.light", name)
52 name=name, scs_id=scs_id, logger=logger, scsgate=scsgate
57 scsgate.add_devices_to_register(lights)
61 """Representation of a SCSGate light."""
63 _attr_color_mode = ColorMode.ONOFF
64 _attr_supported_color_modes = {ColorMode.ONOFF}
65 _attr_should_poll =
False
67 def __init__(self, scs_id, name, logger, scsgate):
68 """Initialize the light."""
77 """Return the SCS ID."""
82 """Return true if light is on."""
86 """Turn the device on."""
88 self.
_scsgate_scsgate.append_task(ToggleStatusTask(target=self.
_scs_id_scs_id, toggled=
True))
94 """Turn the device off."""
96 self.
_scsgate_scsgate.append_task(ToggleStatusTask(target=self.
_scs_id_scs_id, toggled=
False))
102 """Handle a SCSGate message related with this light."""
103 if self.
_toggled_toggled == message.toggled:
105 "Light %s, ignoring message %s because state already active",
112 self.
_toggled_toggled = message.toggled
119 self.
hasshass.bus.fire(
120 "button_pressed", {ATTR_ENTITY_ID: self.
_scs_id_scs_id, ATTR_STATE: command}
None turn_off(self, **Any kwargs)
def __init__(self, scs_id, name, logger, scsgate)
def process_event(self, message)
None turn_on(self, **Any kwargs)
None schedule_update_ha_state(self, bool force_refresh=False)
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)