Envisalink Fixes + Enhancements (#3460)

* Added the ability to trigger the alarm.

* Bump version of pyenvisalink to 1.3

* Fixed an issue where the panic_type was not passed to the sub-components properly.

* Bump pyenvisalink version, and make default panic mode = police.

* Pass in event loop to pyenvisalink.

* Made the components play nicely with asyncio.

* Bump pyenvisalink to 1.6

* Bump up pyenvisalink, and better handle synchronous setup.
This commit is contained in:
Dan Cinnamon 2016-09-21 01:51:10 -05:00 committed by Paulus Schoutsen
parent a310599a03
commit edf812c0ea
5 changed files with 27 additions and 15 deletions

View File

@ -10,6 +10,7 @@ from homeassistant.components.envisalink import (EVL_CONTROLLER,
EnvisalinkDevice,
PARTITION_SCHEMA,
CONF_CODE,
CONF_PANIC,
CONF_PARTITIONNAME,
SIGNAL_PARTITION_UPDATE,
SIGNAL_KEYPAD_UPDATE)
@ -26,6 +27,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
"""Perform the setup for Envisalink alarm panels."""
_configured_partitions = discovery_info['partitions']
_code = discovery_info[CONF_CODE]
_panic_type = discovery_info[CONF_PANIC]
for part_num in _configured_partitions:
_device_config_data = PARTITION_SCHEMA(
_configured_partitions[part_num])
@ -33,6 +35,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
part_num,
_device_config_data[CONF_PARTITIONNAME],
_code,
_panic_type,
EVL_CONTROLLER.alarm_state['partition'][part_num],
EVL_CONTROLLER)
add_devices_callback([_device])
@ -44,11 +47,13 @@ class EnvisalinkAlarm(EnvisalinkDevice, alarm.AlarmControlPanel):
"""Represents the Envisalink-based alarm panel."""
# pylint: disable=too-many-arguments
def __init__(self, partition_number, alarm_name, code, info, controller):
def __init__(self, partition_number, alarm_name,
code, panic_type, info, controller):
"""Initialize the alarm panel."""
from pydispatch import dispatcher
self._partition_number = partition_number
self._code = code
self._panic_type = panic_type
_LOGGER.debug('Setting up alarm: ' + alarm_name)
EnvisalinkDevice.__init__(self, alarm_name, info, controller)
dispatcher.connect(self._update_callback,
@ -61,7 +66,7 @@ class EnvisalinkAlarm(EnvisalinkDevice, alarm.AlarmControlPanel):
def _update_callback(self, partition):
"""Update HA state, if needed."""
if partition is None or int(partition) == self._partition_number:
self.update_ha_state()
self.hass.async_add_job(self.update_ha_state)
@property
def code_format(self):
@ -101,5 +106,6 @@ class EnvisalinkAlarm(EnvisalinkDevice, alarm.AlarmControlPanel):
self._partition_number)
def alarm_trigger(self, code=None):
"""Alarm trigger command. Not possible for us."""
raise NotImplementedError()
"""Alarm trigger command. Will be used to trigger a panic alarm."""
if self._code:
EVL_CONTROLLER.panic_alarm(self._panic_type)

View File

@ -68,4 +68,4 @@ class EnvisalinkBinarySensor(EnvisalinkDevice, BinarySensorDevice):
def _update_callback(self, zone):
"""Update the zone's state, if needed."""
if zone is None or int(zone) == self._zone_number:
self.update_ha_state()
self.hass.async_add_job(self.update_ha_state)

View File

@ -12,7 +12,7 @@ from homeassistant.const import EVENT_HOMEASSISTANT_STOP
from homeassistant.helpers.entity import Entity
from homeassistant.components.discovery import load_platform
REQUIREMENTS = ['pyenvisalink==1.5', 'pydispatcher==2.0.5']
REQUIREMENTS = ['pyenvisalink==1.7', 'pydispatcher==2.0.5']
_LOGGER = logging.getLogger(__name__)
DOMAIN = 'envisalink'
@ -34,12 +34,14 @@ CONF_PARTITIONS = 'partitions'
CONF_ZONENAME = 'name'
CONF_ZONETYPE = 'type'
CONF_PARTITIONNAME = 'name'
CONF_PANIC = 'panic_type'
DEFAULT_PORT = 4025
DEFAULT_EVL_VERSION = 3
DEFAULT_KEEPALIVE = 60
DEFAULT_ZONEDUMP_INTERVAL = 30
DEFAULT_ZONETYPE = 'opening'
DEFAULT_PANIC = 'Police'
SIGNAL_ZONE_UPDATE = 'zones_updated'
SIGNAL_PARTITION_UPDATE = 'partition_updated'
@ -60,6 +62,7 @@ CONFIG_SCHEMA = vol.Schema({
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASS): cv.string,
vol.Required(CONF_CODE): cv.string,
vol.Optional(CONF_PANIC, default=DEFAULT_PANIC): cv.string,
vol.Optional(CONF_ZONES): {vol.Coerce(int): ZONE_SCHEMA},
vol.Optional(CONF_PARTITIONS): {vol.Coerce(int): PARTITION_SCHEMA},
vol.Optional(CONF_EVL_PORT, default=DEFAULT_PORT): cv.port,
@ -89,6 +92,7 @@ def setup(hass, base_config):
_port = config.get(CONF_EVL_PORT)
_code = config.get(CONF_CODE)
_panel_type = config.get(CONF_PANEL_TYPE)
_panic_type = config.get(CONF_PANIC)
_version = config.get(CONF_EVL_VERSION)
_user = config.get(CONF_USERNAME)
_pass = config.get(CONF_PASS)
@ -104,7 +108,8 @@ def setup(hass, base_config):
_user,
_pass,
_zone_dump,
_keep_alive)
_keep_alive,
hass.loop)
def login_fail_callback(data):
"""Callback for when the evl rejects our login."""
@ -149,7 +154,7 @@ def setup(hass, base_config):
def start_envisalink(event):
"""Startup process for the Envisalink."""
EVL_CONTROLLER.start()
hass.loop.call_soon_threadsafe(EVL_CONTROLLER.start)
for _ in range(10):
if 'success' in _connect_status:
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_envisalink)
@ -177,14 +182,15 @@ def setup(hass, base_config):
# Load sub-components for Envisalink
if _partitions:
load_platform(hass, 'alarm_control_panel', 'envisalink',
{'partitions': _partitions,
'code': _code}, config)
{CONF_PARTITIONS: _partitions,
CONF_CODE: _code,
CONF_PANIC: _panic_type}, config)
load_platform(hass, 'sensor', 'envisalink',
{'partitions': _partitions,
'code': _code}, config)
{CONF_PARTITIONS: _partitions,
CONF_CODE: _code}, config)
if _zones:
load_platform(hass, 'binary_sensor', 'envisalink',
{'zones': _zones}, config)
{CONF_ZONES: _zones}, config)
return True

View File

@ -65,4 +65,4 @@ class EnvisalinkSensor(EnvisalinkDevice):
def _update_callback(self, partition):
"""Update the partition state in HA, if needed."""
if partition is None or int(partition) == self._partition_number:
self.update_ha_state()
self.hass.async_add_job(self.update_ha_state)

View File

@ -319,7 +319,7 @@ pycmus==0.1.0
pydispatcher==2.0.5
# homeassistant.components.envisalink
pyenvisalink==1.5
pyenvisalink==1.7
# homeassistant.components.ifttt
pyfttt==0.3