From 7198c85fe56bdbae3a10ff9f80e39b5bbb196a97 Mon Sep 17 00:00:00 2001 From: Kostas Chatzikokolakis Date: Fri, 1 Jul 2022 15:54:10 +0300 Subject: [PATCH] Add bypass/unbypass services (#18) --- custom_components/ultrasync/__init__.py | 12 ++++++++++ custom_components/ultrasync/const.py | 2 ++ custom_components/ultrasync/services.yaml | 28 +++++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/custom_components/ultrasync/__init__.py b/custom_components/ultrasync/__init__.py index 35c089b..d312882 100644 --- a/custom_components/ultrasync/__init__.py +++ b/custom_components/ultrasync/__init__.py @@ -19,6 +19,8 @@ SERVICE_AWAY, SERVICE_DISARM, SERVICE_STAY, + SERVICE_BYPASS, + SERVICE_UNBYPASS, ) from .coordinator import UltraSyncDataUpdateCoordinator @@ -108,9 +110,19 @@ def disarm(call) -> None: """Service call to disable alarm in UltraSync Hub.""" coordinator.hub.set_alarm(state=AlarmScene.DISARMED) + def bypass(call) -> None: + """Service call to bypass a zone in UltraSync Hub.""" + coordinator.hub.set_zone_bypass(state=True, zone=call.data['zone']) + + def unbypass(call) -> None: + """Service call to unbypass a zone in UltraSync Hub.""" + coordinator.hub.set_zone_bypass(state=False, zone=call.data['zone']) + hass.services.async_register(DOMAIN, SERVICE_AWAY, away, schema=vol.Schema({})) hass.services.async_register(DOMAIN, SERVICE_STAY, stay, schema=vol.Schema({})) hass.services.async_register(DOMAIN, SERVICE_DISARM, disarm, schema=vol.Schema({})) + hass.services.async_register(DOMAIN, SERVICE_BYPASS, bypass) + hass.services.async_register(DOMAIN, SERVICE_UNBYPASS, unbypass) async def _async_update_listener(hass: HomeAssistantType, entry: ConfigEntry) -> None: diff --git a/custom_components/ultrasync/const.py b/custom_components/ultrasync/const.py index a55952d..9b10ddc 100644 --- a/custom_components/ultrasync/const.py +++ b/custom_components/ultrasync/const.py @@ -11,6 +11,8 @@ SERVICE_AWAY = "away" SERVICE_STAY = "stay" SERVICE_DISARM = "disarm" +SERVICE_BYPASS = "bypass" +SERVICE_UNBYPASS = "unbypass" # Index used for managing loaded sensors SENSORS = "sensors" diff --git a/custom_components/ultrasync/services.yaml b/custom_components/ultrasync/services.yaml index 4e33745..e4a83ea 100644 --- a/custom_components/ultrasync/services.yaml +++ b/custom_components/ultrasync/services.yaml @@ -8,3 +8,31 @@ stay: disarm: description: Disarm the Alarm + +bypass: + description: Bypass a zone + fields: + zone: + name: Zone + description: The zone to bypass + required: true + example: 1 + selector: + number: + mode: box + min: 1 + max: 100 + +unbypass: + description: Unbypass a zone + fields: + zone: + name: Zone + description: The zone to unbypass + required: true + example: 1 + selector: + number: + mode: box + min: 1 + max: 100 \ No newline at end of file