Add override duration for genius hub switches (#45558)

This commit is contained in:
GeoffAtHome 2021-01-29 11:44:56 +00:00 committed by GitHub
parent 71c169c84f
commit da713e206d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 3 deletions

View File

@ -26,3 +26,15 @@ set_zone_override:
description: >-
The duration of the override. Optional, default 1 hour, maximum 24 hours.
example: '{"minutes": 135}'
set_switch_override:
description: >-
Override switch for a given duration.
fields:
entity_id:
description: The zone's entity_id.
example: switch.study
duration:
description: >-
The duration of the override. Optional, default 1 hour, maximum 24 hours.
example: '{"minutes": 135}'

View File

@ -1,13 +1,29 @@
"""Support for Genius Hub switch/outlet devices."""
from datetime import timedelta
import voluptuous as vol
from homeassistant.components.switch import DEVICE_CLASS_OUTLET, SwitchEntity
from homeassistant.const import ATTR_ENTITY_ID
from homeassistant.helpers import config_validation as cv, entity_platform
from homeassistant.helpers.typing import ConfigType, HomeAssistantType
from . import DOMAIN, GeniusZone
ATTR_DURATION = "duration"
from . import ATTR_DURATION, DOMAIN, GeniusZone
GH_ON_OFF_ZONE = "on / off"
SVC_SET_SWITCH_OVERRIDE = "set_switch_override"
SET_SWITCH_OVERRIDE_SCHEMA = vol.Schema(
{
vol.Required(ATTR_ENTITY_ID): cv.entity_id,
vol.Optional(ATTR_DURATION): vol.All(
cv.time_period,
vol.Range(min=timedelta(minutes=5), max=timedelta(days=1)),
),
}
)
async def async_setup_platform(
hass: HomeAssistantType, config: ConfigType, async_add_entities, discovery_info=None
@ -26,6 +42,15 @@ async def async_setup_platform(
]
)
# Register custom services
platform = entity_platform.current_platform.get()
platform.async_register_entity_service(
SVC_SET_SWITCH_OVERRIDE,
SET_SWITCH_OVERRIDE_SCHEMA,
"async_turn_on",
)
class GeniusSwitch(GeniusZone, SwitchEntity):
"""Representation of a Genius Hub switch."""