mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Updating Alarm.com Component for async and no Selenium (#6752)
* Updating Alarm.com Component for async and no Selenium * Fixed gen_all_requirements
This commit is contained in:
parent
e1ed076015
commit
d1b519a418
@ -1,13 +1,13 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
Interfaces with Alarm.com alarm control panels.
|
Interfaces with Alarm.com alarm control panels.
|
||||||
|
|
||||||
For more details about this platform, please refer to the documentation at
|
For more details about this platform, please refer to the documentation at
|
||||||
https://home-assistant.io/components/alarm_control_panel.alarmdotcom/
|
https://home-assistant.io/components/alarm_control_panel.alarmdotcom/
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
import asyncio
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
import homeassistant.components.alarm_control_panel as alarm
|
import homeassistant.components.alarm_control_panel as alarm
|
||||||
from homeassistant.components.alarm_control_panel import PLATFORM_SCHEMA
|
from homeassistant.components.alarm_control_panel import PLATFORM_SCHEMA
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@ -15,10 +15,9 @@ from homeassistant.const import (
|
|||||||
STATE_ALARM_ARMED_HOME, STATE_ALARM_DISARMED, STATE_UNKNOWN, CONF_CODE,
|
STATE_ALARM_ARMED_HOME, STATE_ALARM_DISARMED, STATE_UNKNOWN, CONF_CODE,
|
||||||
CONF_NAME)
|
CONF_NAME)
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
|
|
||||||
REQUIREMENTS = ['https://github.com/Xorso/pyalarmdotcom'
|
REQUIREMENTS = ['pyalarmdotcom==0.2.9']
|
||||||
'/archive/0.1.1.zip'
|
|
||||||
'#pyalarmdotcom==0.1.1']
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -32,14 +31,17 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
@asyncio.coroutine
|
||||||
"""Setup an Alarm.com control panel."""
|
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
||||||
|
"""Setup a Alarm.com control panel."""
|
||||||
name = config.get(CONF_NAME)
|
name = config.get(CONF_NAME)
|
||||||
code = config.get(CONF_CODE)
|
code = config.get(CONF_CODE)
|
||||||
username = config.get(CONF_USERNAME)
|
username = config.get(CONF_USERNAME)
|
||||||
password = config.get(CONF_PASSWORD)
|
password = config.get(CONF_PASSWORD)
|
||||||
|
|
||||||
add_devices([AlarmDotCom(hass, name, code, username, password)], True)
|
alarmdotcom = AlarmDotCom(hass, name, code, username, password)
|
||||||
|
yield from alarmdotcom.async_login()
|
||||||
|
async_add_devices([alarmdotcom])
|
||||||
|
|
||||||
|
|
||||||
class AlarmDotCom(alarm.AlarmControlPanel):
|
class AlarmDotCom(alarm.AlarmControlPanel):
|
||||||
@ -47,18 +49,30 @@ class AlarmDotCom(alarm.AlarmControlPanel):
|
|||||||
|
|
||||||
def __init__(self, hass, name, code, username, password):
|
def __init__(self, hass, name, code, username, password):
|
||||||
"""Initialize the Alarm.com status."""
|
"""Initialize the Alarm.com status."""
|
||||||
from pyalarmdotcom.pyalarmdotcom import Alarmdotcom
|
from pyalarmdotcom import Alarmdotcom
|
||||||
self._alarm = Alarmdotcom(username, password, timeout=10)
|
_LOGGER.debug('Setting up Alarm.com...')
|
||||||
self._hass = hass
|
self._hass = hass
|
||||||
self._name = name
|
self._name = name
|
||||||
self._code = str(code) if code else None
|
self._code = str(code) if code else None
|
||||||
self._username = username
|
self._username = username
|
||||||
self._password = password
|
self._password = password
|
||||||
|
self._websession = async_get_clientsession(self._hass)
|
||||||
self._state = STATE_UNKNOWN
|
self._state = STATE_UNKNOWN
|
||||||
|
self._alarm = Alarmdotcom(username,
|
||||||
|
password,
|
||||||
|
self._websession,
|
||||||
|
hass.loop)
|
||||||
|
|
||||||
def update(self):
|
@asyncio.coroutine
|
||||||
|
def async_login(self):
|
||||||
|
"""Login to Alarm.com."""
|
||||||
|
yield from self._alarm.async_login()
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
|
def async_update(self):
|
||||||
"""Fetch the latest state."""
|
"""Fetch the latest state."""
|
||||||
self._state = self._alarm.state
|
yield from self._alarm.async_update()
|
||||||
|
return self._alarm.state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@ -73,45 +87,36 @@ class AlarmDotCom(alarm.AlarmControlPanel):
|
|||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Return the state of the device."""
|
"""Return the state of the device."""
|
||||||
if self._state == 'Disarmed':
|
if self._alarm.state.lower() == 'disarmed':
|
||||||
return STATE_ALARM_DISARMED
|
return STATE_ALARM_DISARMED
|
||||||
elif self._state == 'Armed Stay':
|
elif self._alarm.state.lower() == 'armed stay':
|
||||||
return STATE_ALARM_ARMED_HOME
|
return STATE_ALARM_ARMED_HOME
|
||||||
elif self._state == 'Armed Away':
|
elif self._alarm.state.lower() == 'armed away':
|
||||||
return STATE_ALARM_ARMED_AWAY
|
return STATE_ALARM_ARMED_AWAY
|
||||||
else:
|
else:
|
||||||
return STATE_UNKNOWN
|
return STATE_UNKNOWN
|
||||||
|
|
||||||
def alarm_disarm(self, code=None):
|
@asyncio.coroutine
|
||||||
|
def async_alarm_disarm(self, code=None):
|
||||||
"""Send disarm command."""
|
"""Send disarm command."""
|
||||||
if not self._validate_code(code, 'disarming home'):
|
if self._validate_code(code):
|
||||||
return
|
yield from self._alarm.async_alarm_disarm()
|
||||||
from pyalarmdotcom.pyalarmdotcom import Alarmdotcom
|
|
||||||
# Open another session to alarm.com to fire off the command
|
|
||||||
_alarm = Alarmdotcom(self._username, self._password, timeout=10)
|
|
||||||
_alarm.disarm()
|
|
||||||
|
|
||||||
def alarm_arm_home(self, code=None):
|
@asyncio.coroutine
|
||||||
"""Send arm home command."""
|
def async_alarm_arm_home(self, code=None):
|
||||||
if not self._validate_code(code, 'arming home'):
|
"""Send arm hom command."""
|
||||||
return
|
if self._validate_code(code):
|
||||||
from pyalarmdotcom.pyalarmdotcom import Alarmdotcom
|
yield from self._alarm.async_alarm_arm_home()
|
||||||
# Open another session to alarm.com to fire off the command
|
|
||||||
_alarm = Alarmdotcom(self._username, self._password, timeout=10)
|
|
||||||
_alarm.arm_stay()
|
|
||||||
|
|
||||||
def alarm_arm_away(self, code=None):
|
@asyncio.coroutine
|
||||||
|
def async_alarm_arm_away(self, code=None):
|
||||||
"""Send arm away command."""
|
"""Send arm away command."""
|
||||||
if not self._validate_code(code, 'arming home'):
|
if self._validate_code(code):
|
||||||
return
|
yield from self._alarm.async_alarm_arm_away()
|
||||||
from pyalarmdotcom.pyalarmdotcom import Alarmdotcom
|
|
||||||
# Open another session to alarm.com to fire off the command
|
|
||||||
_alarm = Alarmdotcom(self._username, self._password, timeout=10)
|
|
||||||
_alarm.arm_away()
|
|
||||||
|
|
||||||
def _validate_code(self, code, state):
|
def _validate_code(self, code):
|
||||||
"""Validate given code."""
|
"""Validate given code."""
|
||||||
check = self._code is None or code == self._code
|
check = self._code is None or code == self._code
|
||||||
if not check:
|
if not check:
|
||||||
_LOGGER.warning('Wrong code entered for %s', state)
|
_LOGGER.warning('Wrong code entered.')
|
||||||
return check
|
return check
|
||||||
|
@ -236,9 +236,6 @@ https://github.com/TheRealLink/pylgtv/archive/v0.1.4.zip#pylgtv==0.1.4
|
|||||||
# homeassistant.components.switch.thinkingcleaner
|
# homeassistant.components.switch.thinkingcleaner
|
||||||
https://github.com/TheRealLink/pythinkingcleaner/archive/v0.0.2.zip#pythinkingcleaner==0.0.2
|
https://github.com/TheRealLink/pythinkingcleaner/archive/v0.0.2.zip#pythinkingcleaner==0.0.2
|
||||||
|
|
||||||
# homeassistant.components.alarm_control_panel.alarmdotcom
|
|
||||||
https://github.com/Xorso/pyalarmdotcom/archive/0.1.1.zip#pyalarmdotcom==0.1.1
|
|
||||||
|
|
||||||
# homeassistant.components.media_player.braviatv
|
# homeassistant.components.media_player.braviatv
|
||||||
https://github.com/aparraga/braviarc/archive/0.3.6.zip#braviarc==0.3.6
|
https://github.com/aparraga/braviarc/archive/0.3.6.zip#braviarc==0.3.6
|
||||||
|
|
||||||
@ -464,6 +461,9 @@ pyHS100==0.2.4.1
|
|||||||
# homeassistant.components.rfxtrx
|
# homeassistant.components.rfxtrx
|
||||||
pyRFXtrx==0.17.0
|
pyRFXtrx==0.17.0
|
||||||
|
|
||||||
|
# homeassistant.components.alarm_control_panel.alarmdotcom
|
||||||
|
pyalarmdotcom==0.2.9
|
||||||
|
|
||||||
# homeassistant.components.notify.xmpp
|
# homeassistant.components.notify.xmpp
|
||||||
pyasn1-modules==0.0.8
|
pyasn1-modules==0.0.8
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user