Add (un)bypass services to Risco (#39292)
* Add (un)bypass services to Risco * Simplify service registration
This commit is contained in:
1 parent
a83c778c4f
commit
24db31fa28
6 files changed
+67
-3
No files matched your search
@@ -3,13 +3,23 @@ from homeassistant.components.binary_sensor import (
|
||||
DEVICE_CLASS_MOTION,
|
||||
BinarySensorEntity,
|
||||
)
|
||||
from homeassistant.helpers import entity_platform
|
||||
|
||||
from .const import DATA_COORDINATOR, DOMAIN
|
||||
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):
|
||||
"""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]
|
||||
entities = [
|
||||
RiscoBinarySensor(coordinator, zone_id, zone)
|
||||
@@ -64,3 +74,16 @@ class RiscoBinarySensor(BinarySensorEntity, RiscoEntity):
|
||||
def device_class(self):
|
||||
"""Return the class of this sensor, from DEVICE_CLASSES."""
|
||||
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)
|
||||
Reference in new issue
Block a user