Add Hive Alarm Support (#59670)
* Add alarm support * Update code coverage * Update homeassistant/components/hive/alarm_control_panel.py Co-authored-by: Allen Porter <allen.porter@gmail.com> * Add alarm support * Update code coverage * Update homeassistant/components/hive/alarm_control_panel.py Co-authored-by: Allen Porter <allen.porter@gmail.com> * Update icon and device info Co-authored-by: Allen Porter <allen.porter@gmail.com>pull/59787/head
parent
1bcd62cd32
commit
e9c8de25df
|
@ -431,8 +431,9 @@ omit =
|
|||
homeassistant/components/hisense_aehw4a1/climate.py
|
||||
homeassistant/components/hitron_coda/device_tracker.py
|
||||
homeassistant/components/hive/__init__.py
|
||||
homeassistant/components/hive/climate.py
|
||||
homeassistant/components/hive/alarm_control_panel.py
|
||||
homeassistant/components/hive/binary_sensor.py
|
||||
homeassistant/components/hive/climate.py
|
||||
homeassistant/components/hive/light.py
|
||||
homeassistant/components/hive/sensor.py
|
||||
homeassistant/components/hive/switch.py
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
"""Support for the Hive alarm."""
|
||||
from datetime import timedelta
|
||||
|
||||
from homeassistant.components.alarm_control_panel import AlarmControlPanelEntity
|
||||
from homeassistant.components.alarm_control_panel.const import (
|
||||
SUPPORT_ALARM_ARM_AWAY,
|
||||
SUPPORT_ALARM_ARM_NIGHT,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
STATE_ALARM_ARMED_AWAY,
|
||||
STATE_ALARM_ARMED_NIGHT,
|
||||
STATE_ALARM_DISARMED,
|
||||
STATE_ALARM_TRIGGERED,
|
||||
)
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
|
||||
from . import HiveEntity
|
||||
from .const import DOMAIN
|
||||
|
||||
ICON = "mdi:security"
|
||||
PARALLEL_UPDATES = 0
|
||||
SCAN_INTERVAL = timedelta(seconds=15)
|
||||
HIVETOHA = {
|
||||
"home": STATE_ALARM_DISARMED,
|
||||
"asleep": STATE_ALARM_ARMED_NIGHT,
|
||||
"away": STATE_ALARM_ARMED_AWAY,
|
||||
}
|
||||
|
||||
|
||||
async def async_setup_entry(hass, entry, async_add_entities):
|
||||
"""Set up Hive thermostat based on a config entry."""
|
||||
|
||||
hive = hass.data[DOMAIN][entry.entry_id]
|
||||
devices = hive.session.deviceList.get("alarm_control_panel")
|
||||
if devices:
|
||||
async_add_entities(
|
||||
[HiveAlarmControlPanelEntity(hive, dev) for dev in devices], True
|
||||
)
|
||||
|
||||
|
||||
class HiveAlarmControlPanelEntity(HiveEntity, AlarmControlPanelEntity):
|
||||
"""Representation of a Hive alarm."""
|
||||
|
||||
_attr_icon = ICON
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return unique ID of entity."""
|
||||
return self._unique_id
|
||||
|
||||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return device information about this AdGuard Home instance."""
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, self.device["device_id"])},
|
||||
model=self.device["deviceData"]["model"],
|
||||
manufacturer=self.device["deviceData"]["manufacturer"],
|
||||
name=self.device["device_name"],
|
||||
sw_version=self.device["deviceData"]["version"],
|
||||
via_device=(DOMAIN, self.device["parentDevice"]),
|
||||
)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the alarm."""
|
||||
return self.device["haName"]
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
"""Return if the device is available."""
|
||||
return self.device["deviceData"]["online"]
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""Return state of alarm."""
|
||||
if self.device["status"]["state"]:
|
||||
return STATE_ALARM_TRIGGERED
|
||||
return HIVETOHA[self.device["status"]["mode"]]
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
"""Return the list of supported features."""
|
||||
return SUPPORT_ALARM_ARM_NIGHT | SUPPORT_ALARM_ARM_AWAY
|
||||
|
||||
async def async_alarm_disarm(self, code=None):
|
||||
"""Send disarm command."""
|
||||
await self.hive.alarm.setMode(self.device, "home")
|
||||
|
||||
async def async_alarm_arm_night(self, code=None):
|
||||
"""Send arm night command."""
|
||||
await self.hive.alarm.setMode(self.device, "asleep")
|
||||
|
||||
async def async_alarm_arm_away(self, code=None):
|
||||
"""Send arm away command."""
|
||||
await self.hive.alarm.setMode(self.device, "away")
|
||||
|
||||
async def async_update(self):
|
||||
"""Update all Node data from Hive."""
|
||||
await self.hive.session.updateData(self.device)
|
||||
self.device = await self.hive.alarm.getAlarm(self.device)
|
|
@ -6,8 +6,17 @@ CONF_CODE = "2fa"
|
|||
CONFIG_ENTRY_VERSION = 1
|
||||
DEFAULT_NAME = "Hive"
|
||||
DOMAIN = "hive"
|
||||
PLATFORMS = ["binary_sensor", "climate", "light", "sensor", "switch", "water_heater"]
|
||||
PLATFORMS = [
|
||||
"alarm_control_panel",
|
||||
"binary_sensor",
|
||||
"climate",
|
||||
"light",
|
||||
"sensor",
|
||||
"switch",
|
||||
"water_heater",
|
||||
]
|
||||
PLATFORM_LOOKUP = {
|
||||
"alarm_control_panel": "alarm_control_panel",
|
||||
"binary_sensor": "binary_sensor",
|
||||
"climate": "climate",
|
||||
"light": "light",
|
||||
|
|
Loading…
Reference in New Issue