1 """Light support for switch entities."""
3 from __future__
import annotations
7 import voluptuous
as vol
10 PLATFORM_SCHEMA
as LIGHT_PLATFORM_SCHEMA,
30 from .const
import DOMAIN
as SWITCH_DOMAIN
32 DEFAULT_NAME =
"Light Switch"
34 PLATFORM_SCHEMA = LIGHT_PLATFORM_SCHEMA.extend(
36 vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
37 vol.Required(CONF_ENTITY_ID): cv.entity_domain(SWITCH_DOMAIN),
45 async_add_entities: AddEntitiesCallback,
46 discovery_info: DiscoveryInfoType |
None =
None,
48 """Initialize Light Switch platform."""
49 registry = er.async_get(hass)
50 wrapped_switch = registry.async_get(config[CONF_ENTITY_ID])
51 unique_id = wrapped_switch.unique_id
if wrapped_switch
else None
57 config[CONF_ENTITY_ID],
65 """Represents a Switch as a Light."""
67 _attr_color_mode = ColorMode.ONOFF
68 _attr_should_poll =
False
69 _attr_supported_color_modes = {ColorMode.ONOFF}
71 def __init__(self, name: str, switch_entity_id: str, unique_id: str |
None) ->
None:
72 """Initialize Light Switch."""
78 """Forward the turn_on command to the switch in this light switch."""
79 await self.
hasshass.services.async_call(
88 """Forward the turn_off command to the switch in this light switch."""
89 await self.
hasshass.services.async_call(
98 """Register callbacks."""
101 def async_state_changed_listener(
102 event: Event[EventStateChangedData] |
None =
None,
104 """Handle child updates."""
107 )
is None or state.state == STATE_UNAVAILABLE:
120 async_state_changed_listener()
None async_turn_off(self, **Any kwargs)
None async_added_to_hass(self)
None __init__(self, str name, str switch_entity_id, str|None unique_id)
None async_turn_on(self, **Any kwargs)
None async_write_ha_state(self)
None async_on_remove(self, CALLBACK_TYPE func)
None async_setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback async_add_entities, DiscoveryInfoType|None discovery_info=None)
CALLBACK_TYPE async_track_state_change_event(HomeAssistant hass, str|Iterable[str] entity_ids, Callable[[Event[EventStateChangedData]], Any] action, HassJobType|None job_type=None)