mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Add (un)bypass services to Risco (#39292)
* Add (un)bypass services to Risco * Simplify service registration
This commit is contained in:
parent
a83c778c4f
commit
24db31fa28
@ -3,13 +3,23 @@ from homeassistant.components.binary_sensor import (
|
|||||||
DEVICE_CLASS_MOTION,
|
DEVICE_CLASS_MOTION,
|
||||||
BinarySensorEntity,
|
BinarySensorEntity,
|
||||||
)
|
)
|
||||||
|
from homeassistant.helpers import entity_platform
|
||||||
|
|
||||||
from .const import DATA_COORDINATOR, DOMAIN
|
from .const import DATA_COORDINATOR, DOMAIN
|
||||||
from .entity import RiscoEntity
|
from .entity import RiscoEntity
|
||||||
|
|
||||||
|
SERVICE_BYPASS_ZONE = "bypass_zone"
|
||||||
|
SERVICE_UNBYPASS_ZONE = "unbypass_zone"
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
"""Set up the Risco alarm control panel."""
|
"""Set up the Risco alarm control panel."""
|
||||||
|
platform = entity_platform.current_platform.get()
|
||||||
|
platform.async_register_entity_service(SERVICE_BYPASS_ZONE, {}, "async_bypass_zone")
|
||||||
|
platform.async_register_entity_service(
|
||||||
|
SERVICE_UNBYPASS_ZONE, {}, "async_unbypass_zone"
|
||||||
|
)
|
||||||
|
|
||||||
coordinator = hass.data[DOMAIN][config_entry.entry_id][DATA_COORDINATOR]
|
coordinator = hass.data[DOMAIN][config_entry.entry_id][DATA_COORDINATOR]
|
||||||
entities = [
|
entities = [
|
||||||
RiscoBinarySensor(coordinator, zone_id, zone)
|
RiscoBinarySensor(coordinator, zone_id, zone)
|
||||||
@ -64,3 +74,16 @@ class RiscoBinarySensor(BinarySensorEntity, RiscoEntity):
|
|||||||
def device_class(self):
|
def device_class(self):
|
||||||
"""Return the class of this sensor, from DEVICE_CLASSES."""
|
"""Return the class of this sensor, from DEVICE_CLASSES."""
|
||||||
return DEVICE_CLASS_MOTION
|
return DEVICE_CLASS_MOTION
|
||||||
|
|
||||||
|
async def _bypass(self, bypass):
|
||||||
|
alarm = await self._risco.bypass_zone(self._zone_id, bypass)
|
||||||
|
self._zone = alarm.zones[self._zone_id]
|
||||||
|
self.async_write_ha_state()
|
||||||
|
|
||||||
|
async def async_bypass_zone(self):
|
||||||
|
"""Bypass this zone."""
|
||||||
|
await self._bypass(True)
|
||||||
|
|
||||||
|
async def async_unbypass_zone(self):
|
||||||
|
"""Unbypass this zone."""
|
||||||
|
await self._bypass(False)
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/risco",
|
"documentation": "https://www.home-assistant.io/integrations/risco",
|
||||||
"requirements": [
|
"requirements": [
|
||||||
"pyrisco==0.2.1"
|
"pyrisco==0.2.3"
|
||||||
],
|
],
|
||||||
"codeowners": [
|
"codeowners": [
|
||||||
"@OnFreund"
|
"@OnFreund"
|
||||||
|
15
homeassistant/components/risco/services.yaml
Normal file
15
homeassistant/components/risco/services.yaml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# Describes the format for available Risco services
|
||||||
|
|
||||||
|
bypass_zone:
|
||||||
|
description: Bypass a Risco Zone
|
||||||
|
fields:
|
||||||
|
entity_id:
|
||||||
|
description: Entity ID of the zone to bypass
|
||||||
|
example: "binary_sensor.living_room_motion"
|
||||||
|
|
||||||
|
unbypass_zone:
|
||||||
|
description: Unbypass a Risco Zone
|
||||||
|
fields:
|
||||||
|
entity_id:
|
||||||
|
description: Entity ID of the zone to unbypass
|
||||||
|
example: "binary_sensor.living_room_motion"
|
@ -1582,7 +1582,7 @@ pyrecswitch==1.0.2
|
|||||||
pyrepetier==3.0.5
|
pyrepetier==3.0.5
|
||||||
|
|
||||||
# homeassistant.components.risco
|
# homeassistant.components.risco
|
||||||
pyrisco==0.2.1
|
pyrisco==0.2.3
|
||||||
|
|
||||||
# homeassistant.components.sabnzbd
|
# homeassistant.components.sabnzbd
|
||||||
pysabnzbd==1.1.0
|
pysabnzbd==1.1.0
|
||||||
|
@ -757,7 +757,7 @@ pyps4-2ndscreen==1.1.1
|
|||||||
pyqwikswitch==0.93
|
pyqwikswitch==0.93
|
||||||
|
|
||||||
# homeassistant.components.risco
|
# homeassistant.components.risco
|
||||||
pyrisco==0.2.1
|
pyrisco==0.2.3
|
||||||
|
|
||||||
# homeassistant.components.acer_projector
|
# homeassistant.components.acer_projector
|
||||||
# homeassistant.components.zha
|
# homeassistant.components.zha
|
||||||
|
@ -163,3 +163,29 @@ async def test_states(hass, two_zone_alarm):
|
|||||||
await _check_state(hass, two_zone_alarm, True, False, SECOND_ENTITY_ID, 1)
|
await _check_state(hass, two_zone_alarm, True, False, SECOND_ENTITY_ID, 1)
|
||||||
await _check_state(hass, two_zone_alarm, False, True, SECOND_ENTITY_ID, 1)
|
await _check_state(hass, two_zone_alarm, False, True, SECOND_ENTITY_ID, 1)
|
||||||
await _check_state(hass, two_zone_alarm, False, False, SECOND_ENTITY_ID, 1)
|
await _check_state(hass, two_zone_alarm, False, False, SECOND_ENTITY_ID, 1)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_bypass(hass, two_zone_alarm):
|
||||||
|
"""Test bypassing a zone."""
|
||||||
|
await _setup_risco(hass)
|
||||||
|
with patch("homeassistant.components.risco.RiscoAPI.bypass_zone") as mock:
|
||||||
|
data = {"entity_id": FIRST_ENTITY_ID}
|
||||||
|
|
||||||
|
await hass.services.async_call(
|
||||||
|
DOMAIN, "bypass_zone", service_data=data, blocking=True
|
||||||
|
)
|
||||||
|
|
||||||
|
mock.assert_awaited_once_with(0, True)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_unbypass(hass, two_zone_alarm):
|
||||||
|
"""Test unbypassing a zone."""
|
||||||
|
await _setup_risco(hass)
|
||||||
|
with patch("homeassistant.components.risco.RiscoAPI.bypass_zone") as mock:
|
||||||
|
data = {"entity_id": FIRST_ENTITY_ID}
|
||||||
|
|
||||||
|
await hass.services.async_call(
|
||||||
|
DOMAIN, "unbypass_zone", service_data=data, blocking=True
|
||||||
|
)
|
||||||
|
|
||||||
|
mock.assert_awaited_once_with(0, False)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user