1 """Support for Genius Hub switch/outlet devices."""
3 from __future__
import annotations
5 from datetime
import timedelta
8 import voluptuous
as vol
16 from .
import ATTR_DURATION, GeniusHubConfigEntry
17 from .entity
import GeniusZone
19 GH_ON_OFF_ZONE =
"on / off"
21 SVC_SET_SWITCH_OVERRIDE =
"set_switch_override"
23 SET_SWITCH_OVERRIDE_SCHEMA: VolDictType = {
24 vol.Optional(ATTR_DURATION): vol.All(
33 entry: GeniusHubConfigEntry,
34 async_add_entities: AddEntitiesCallback,
36 """Set up the Genius Hub switch entities."""
38 broker = entry.runtime_data
42 for z
in broker.client.zone_objs
43 if z.data.get(
"type") == GH_ON_OFF_ZONE
47 platform = entity_platform.async_get_current_platform()
49 platform.async_register_entity_service(
50 SVC_SET_SWITCH_OVERRIDE,
51 SET_SWITCH_OVERRIDE_SCHEMA,
57 """Representation of a Genius Hub switch."""
61 """Return the class of this device, from component DEVICE_CLASSES."""
62 return SwitchDeviceClass.OUTLET
66 """Return the current state of the on/off zone.
68 The zone is considered 'on' if the mode is either 'override' or 'timer'.
71 self.
_zone_zone.data[
"mode"]
in [
"override",
"timer"]
72 and self.
_zone_zone.data[
"setpoint"]
76 """Send the zone to Timer mode.
78 The zone is deemed 'off' in this mode, although the plugs may actually be on.
80 await self.
_zone_zone.set_mode(
"timer")
83 """Set the zone to override/on ({'setpoint': true}) for x seconds."""
84 await self.
_zone_zone.set_override(1, kwargs.get(ATTR_DURATION, 3600))
None async_turn_on(self, **Any kwargs)
None async_turn_off(self, **Any kwargs)
None async_setup_entry(HomeAssistant hass, GeniusHubConfigEntry entry, AddEntitiesCallback async_add_entities)