1 """Support for deCONZ switches."""
3 from __future__
import annotations
7 from pydeconz.models.event
import EventType
8 from pydeconz.models.light.light
import Light
15 from .const
import POWER_PLUGS
16 from .entity
import DeconzDevice
17 from .hub
import DeconzHub
22 config_entry: ConfigEntry,
23 async_add_entities: AddEntitiesCallback,
25 """Set up switches for deCONZ component.
27 Switches are based on the same device class as lights in deCONZ.
29 hub = DeconzHub.get_hub(hass, config_entry)
30 hub.entities[SWITCH_DOMAIN] = set()
33 def async_add_switch(_: EventType, switch_id: str) ->
None:
34 """Add switch from deCONZ."""
35 switch = hub.api.lights.lights[switch_id]
36 if switch.type
not in POWER_PLUGS:
40 hub.register_platform_add_device_callback(
42 hub.api.lights.lights,
47 """Representation of a deCONZ power plug."""
53 """Return true if switch is on."""
54 return self._device.on
58 await self.hub.api.lights.lights.set_state(
59 id=self._device.resource_id,
64 """Turn off switch."""
65 await self.hub.api.lights.lights.set_state(
66 id=self._device.resource_id,
None async_turn_on(self, **Any kwargs)
None async_turn_off(self, **Any kwargs)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)