2019-04-03 15:40:03 +00:00
|
|
|
"""Interfaces with TotalConnect alarm control panels."""
|
2017-04-04 10:21:53 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
import homeassistant.components.alarm_control_panel as alarm
|
|
|
|
from homeassistant.const import (
|
2019-07-31 19:25:30 +00:00
|
|
|
STATE_ALARM_ARMED_AWAY,
|
|
|
|
STATE_ALARM_ARMED_HOME,
|
|
|
|
STATE_ALARM_ARMED_NIGHT,
|
|
|
|
STATE_ALARM_DISARMED,
|
|
|
|
STATE_ALARM_ARMING,
|
|
|
|
STATE_ALARM_DISARMING,
|
|
|
|
STATE_ALARM_TRIGGERED,
|
|
|
|
STATE_ALARM_ARMED_CUSTOM_BYPASS,
|
|
|
|
)
|
2019-07-14 07:24:40 +00:00
|
|
|
|
|
|
|
from . import DOMAIN as TOTALCONNECT_DOMAIN
|
2017-04-04 10:21:53 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2019-07-14 07:24:40 +00:00
|
|
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
|
|
|
"""Set up an alarm control panel for a TotalConnect device."""
|
|
|
|
if discovery_info is None:
|
|
|
|
return
|
2017-04-04 10:21:53 +00:00
|
|
|
|
2019-07-14 07:24:40 +00:00
|
|
|
alarms = []
|
2017-04-04 10:21:53 +00:00
|
|
|
|
2019-07-14 07:24:40 +00:00
|
|
|
client = hass.data[TOTALCONNECT_DOMAIN].client
|
2017-04-04 10:21:53 +00:00
|
|
|
|
2019-07-14 07:24:40 +00:00
|
|
|
for location in client.locations:
|
2019-07-31 19:25:30 +00:00
|
|
|
location_id = location.get("LocationID")
|
|
|
|
name = location.get("LocationName")
|
2019-07-14 07:24:40 +00:00
|
|
|
alarms.append(TotalConnectAlarm(name, location_id, client))
|
|
|
|
add_entities(alarms)
|
2017-04-04 10:21:53 +00:00
|
|
|
|
|
|
|
|
2019-07-14 07:24:40 +00:00
|
|
|
class TotalConnectAlarm(alarm.AlarmControlPanel):
|
2017-04-04 10:21:53 +00:00
|
|
|
"""Represent an TotalConnect status."""
|
|
|
|
|
2019-07-14 07:24:40 +00:00
|
|
|
def __init__(self, name, location_id, client):
|
2017-04-04 10:21:53 +00:00
|
|
|
"""Initialize the TotalConnect status."""
|
|
|
|
self._name = name
|
2019-07-14 07:24:40 +00:00
|
|
|
self._location_id = location_id
|
|
|
|
self._client = client
|
2019-01-24 07:20:20 +00:00
|
|
|
self._state = None
|
2019-06-01 20:12:58 +00:00
|
|
|
self._device_state_attributes = {}
|
2017-04-04 10:21:53 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
"""Return the name of the device."""
|
|
|
|
return self._name
|
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
|
|
|
"""Return the state of the device."""
|
|
|
|
return self._state
|
|
|
|
|
2019-06-01 20:12:58 +00:00
|
|
|
@property
|
|
|
|
def device_state_attributes(self):
|
|
|
|
"""Return the state attributes of the device."""
|
|
|
|
return self._device_state_attributes
|
|
|
|
|
2017-04-04 10:21:53 +00:00
|
|
|
def update(self):
|
|
|
|
"""Return the state of the device."""
|
2019-07-14 07:24:40 +00:00
|
|
|
status = self._client.get_armed_status(self._name)
|
|
|
|
attr = {
|
2019-07-31 19:25:30 +00:00
|
|
|
"location_name": self._name,
|
|
|
|
"location_id": self._location_id,
|
|
|
|
"ac_loss": self._client.ac_loss,
|
|
|
|
"low_battery": self._client.low_battery,
|
|
|
|
"triggered_source": None,
|
|
|
|
"triggered_zone": None,
|
2019-07-14 07:24:40 +00:00
|
|
|
}
|
2017-04-04 10:21:53 +00:00
|
|
|
|
|
|
|
if status == self._client.DISARMED:
|
|
|
|
state = STATE_ALARM_DISARMED
|
2019-07-14 07:24:40 +00:00
|
|
|
elif status == self._client.DISARMED_BYPASS:
|
|
|
|
state = STATE_ALARM_DISARMED
|
2017-04-04 10:21:53 +00:00
|
|
|
elif status == self._client.ARMED_STAY:
|
|
|
|
state = STATE_ALARM_ARMED_HOME
|
2019-07-14 07:24:40 +00:00
|
|
|
elif status == self._client.ARMED_STAY_INSTANT:
|
|
|
|
state = STATE_ALARM_ARMED_HOME
|
|
|
|
elif status == self._client.ARMED_STAY_INSTANT_BYPASS:
|
|
|
|
state = STATE_ALARM_ARMED_HOME
|
2017-08-13 17:57:48 +00:00
|
|
|
elif status == self._client.ARMED_STAY_NIGHT:
|
|
|
|
state = STATE_ALARM_ARMED_NIGHT
|
2019-07-14 07:24:40 +00:00
|
|
|
elif status == self._client.ARMED_AWAY:
|
|
|
|
state = STATE_ALARM_ARMED_AWAY
|
|
|
|
elif status == self._client.ARMED_AWAY_BYPASS:
|
|
|
|
state = STATE_ALARM_ARMED_AWAY
|
|
|
|
elif status == self._client.ARMED_AWAY_INSTANT:
|
|
|
|
state = STATE_ALARM_ARMED_AWAY
|
|
|
|
elif status == self._client.ARMED_AWAY_INSTANT_BYPASS:
|
|
|
|
state = STATE_ALARM_ARMED_AWAY
|
2017-12-10 21:02:12 +00:00
|
|
|
elif status == self._client.ARMED_CUSTOM_BYPASS:
|
|
|
|
state = STATE_ALARM_ARMED_CUSTOM_BYPASS
|
2017-08-13 17:57:48 +00:00
|
|
|
elif status == self._client.ARMING:
|
|
|
|
state = STATE_ALARM_ARMING
|
|
|
|
elif status == self._client.DISARMING:
|
|
|
|
state = STATE_ALARM_DISARMING
|
2019-06-01 20:12:58 +00:00
|
|
|
elif status == self._client.ALARMING:
|
|
|
|
state = STATE_ALARM_TRIGGERED
|
2019-07-31 19:25:30 +00:00
|
|
|
attr["triggered_source"] = "Police/Medical"
|
2019-06-01 20:12:58 +00:00
|
|
|
elif status == self._client.ALARMING_FIRE_SMOKE:
|
|
|
|
state = STATE_ALARM_TRIGGERED
|
2019-07-31 19:25:30 +00:00
|
|
|
attr["triggered_source"] = "Fire/Smoke"
|
2019-06-01 20:12:58 +00:00
|
|
|
elif status == self._client.ALARMING_CARBON_MONOXIDE:
|
|
|
|
state = STATE_ALARM_TRIGGERED
|
2019-07-31 19:25:30 +00:00
|
|
|
attr["triggered_source"] = "Carbon Monoxide"
|
2017-04-04 10:21:53 +00:00
|
|
|
else:
|
2019-07-31 19:25:30 +00:00
|
|
|
logging.info(
|
|
|
|
"Total Connect Client returned unknown " "status code: %s", status
|
|
|
|
)
|
2019-01-24 07:20:20 +00:00
|
|
|
state = None
|
2017-04-04 10:21:53 +00:00
|
|
|
|
|
|
|
self._state = state
|
2019-06-01 20:12:58 +00:00
|
|
|
self._device_state_attributes = attr
|
2017-04-04 10:21:53 +00:00
|
|
|
|
|
|
|
def alarm_disarm(self, code=None):
|
|
|
|
"""Send disarm command."""
|
2019-07-14 07:24:40 +00:00
|
|
|
self._client.disarm(self._name)
|
2017-04-04 10:21:53 +00:00
|
|
|
|
|
|
|
def alarm_arm_home(self, code=None):
|
|
|
|
"""Send arm home command."""
|
2019-07-14 07:24:40 +00:00
|
|
|
self._client.arm_stay(self._name)
|
2017-04-04 10:21:53 +00:00
|
|
|
|
|
|
|
def alarm_arm_away(self, code=None):
|
|
|
|
"""Send arm away command."""
|
2019-07-14 07:24:40 +00:00
|
|
|
self._client.arm_away(self._name)
|
2017-08-13 17:57:48 +00:00
|
|
|
|
|
|
|
def alarm_arm_night(self, code=None):
|
|
|
|
"""Send arm night command."""
|
2019-07-14 07:24:40 +00:00
|
|
|
self._client.arm_stay_night(self._name)
|