tests pass

This commit is contained in:
Per Sandström 2015-09-13 20:21:02 +02:00
parent c9bccadc40
commit 683a80f5f4
5 changed files with 44 additions and 36 deletions

View File

@ -1,5 +1,5 @@
""" """
homeassistant.components.sensor homeassistant.components.alarm_control_panel
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Component to interface with various sensors that can be monitored. Component to interface with various sensors that can be monitored.
""" """
@ -8,12 +8,10 @@ from homeassistant.helpers.entity import Entity
from homeassistant.helpers.entity_component import EntityComponent from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.components import verisure from homeassistant.components import verisure
from homeassistant.const import ( from homeassistant.const import (
STATE_UNKNOWN, ATTR_ENTITY_ID,
STATE_ALARM_DISARMED, STATE_ALARM_ARMED_HOME, STATE_ALARM_ARMED_AWAY,
ATTR_ENTITY_PICTURE,
SERVICE_ALARM_DISARM, SERVICE_ALARM_ARM_HOME, SERVICE_ALARM_ARM_AWAY) SERVICE_ALARM_DISARM, SERVICE_ALARM_ARM_HOME, SERVICE_ALARM_ARM_AWAY)
DOMAIN = 'alarm' DOMAIN = 'alarm_control_panel'
DEPENDENCIES = [] DEPENDENCIES = []
SCAN_INTERVAL = 30 SCAN_INTERVAL = 30
@ -36,6 +34,7 @@ ATTR_TO_PROPERTY = [
ATTR_CODE, ATTR_CODE,
] ]
def setup(hass, config): def setup(hass, config):
""" Track states and offer events for sensors. """ """ Track states and offer events for sensors. """
component = EntityComponent( component = EntityComponent(
@ -51,7 +50,7 @@ def setup(hass, config):
if ATTR_CODE not in service.data: if ATTR_CODE not in service.data:
return return
code = service.data[ATTR_CODE] code = service.data[ATTR_CODE]
method = SERVICE_TO_METHOD[service.service] method = SERVICE_TO_METHOD[service.service]
@ -83,6 +82,7 @@ def alarm_arm_home(hass, code, entity_id=None):
hass.services.call(DOMAIN, SERVICE_ALARM_ARM_HOME, data) hass.services.call(DOMAIN, SERVICE_ALARM_ARM_HOME, data)
def alarm_arm_away(hass, code, entity_id=None): def alarm_arm_away(hass, code, entity_id=None):
""" Send the alarm the command for arm away. """ """ Send the alarm the command for arm away. """
data = {ATTR_CODE: code} data = {ATTR_CODE: code}
@ -92,9 +92,11 @@ def alarm_arm_away(hass, code, entity_id=None):
hass.services.call(DOMAIN, SERVICE_ALARM_ARM_AWAY, data) hass.services.call(DOMAIN, SERVICE_ALARM_ARM_AWAY, data)
class AlarmControl(Entity):
class AlarmControlPanel(Entity):
""" ABC for alarm control devices. """
def alarm_disarm(self, code): def alarm_disarm(self, code):
""" Send disar command. """ """ Send disarm command. """
raise NotImplementedError() raise NotImplementedError()
def alarm_arm_home(self, code): def alarm_arm_home(self, code):

View File

@ -1,16 +1,16 @@
""" """
homeassistant.components.alarm.verisure homeassistant.components.alarm_control_panel.verisure
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Interfaces with Verisure alarm. Interfaces with Verisure alarm control panel.
""" """
import logging import logging
import homeassistant.components.verisure as verisure import homeassistant.components.verisure as verisure
import homeassistant.components.alarm as alarm import homeassistant.components.alarm_control_panel as alarm
from homeassistant.helpers.entity import Entity from homeassistant.const import (
from homeassistant.const import (STATE_UNKNOWN, STATE_UNKNOWN,
STATE_ALARM_DISARMED, STATE_ALARM_ARMED_HOME, STATE_ALARM_ARMED_AWAY) STATE_ALARM_DISARMED, STATE_ALARM_ARMED_HOME, STATE_ALARM_ARMED_AWAY)
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -33,7 +33,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
add_devices(alarms) add_devices(alarms)
class VerisureAlarm(alarm.AlarmControl): class VerisureAlarm(alarm.AlarmControlPanel):
""" represents a Verisure alarm status within home assistant. """ """ represents a Verisure alarm status within home assistant. """
def __init__(self, alarm_status): def __init__(self, alarm_status):
@ -56,7 +56,9 @@ class VerisureAlarm(alarm.AlarmControl):
elif verisure.STATUS[self._device][self._id].status == 'armedaway': elif verisure.STATUS[self._device][self._id].status == 'armedaway':
self._state = STATE_ALARM_ARMED_AWAY self._state = STATE_ALARM_ARMED_AWAY
elif verisure.STATUS[self._device][self._id].status != 'pending': elif verisure.STATUS[self._device][self._id].status != 'pending':
_LOGGER.error('Unknown alarm state ' + verisure.STATUS[self._device][self._id].status) _LOGGER.error(
'Unknown alarm state %s',
verisure.STATUS[self._device][self._id].status)
return self._state return self._state
def update(self): def update(self):
@ -65,15 +67,21 @@ class VerisureAlarm(alarm.AlarmControl):
def alarm_disarm(self, code): def alarm_disarm(self, code):
""" Send disarm command. """ """ Send disarm command. """
verisure.MY_PAGES.set_alarm_status(code, verisure.MY_PAGES.ALARM_DISARMED) verisure.MY_PAGES.set_alarm_status(
code,
verisure.MY_PAGES.ALARM_DISARMED)
_LOGGER.warning('disarming') _LOGGER.warning('disarming')
def alarm_arm_home(self, code): def alarm_arm_home(self, code):
""" Send arm home command. """ """ Send arm home command. """
verisure.MY_PAGES.set_alarm_status(code, verisure.MY_PAGES.ALARM_ARMED_HOME) verisure.MY_PAGES.set_alarm_status(
code,
verisure.MY_PAGES.ALARM_ARMED_HOME)
_LOGGER.warning('arming home') _LOGGER.warning('arming home')
def alarm_arm_away(self, code): def alarm_arm_away(self, code):
""" Send arm away command. """ """ Send arm away command. """
verisure.MY_PAGES.set_alarm_status(code, verisure.MY_PAGES.ALARM_ARMED_AWAY) verisure.MY_PAGES.set_alarm_status(
code,
verisure.MY_PAGES.ALARM_ARMED_AWAY)
_LOGGER.warning('arming away') _LOGGER.warning('arming away')

@ -1 +1 @@
Subproject commit b0b12e20e0f61df849c414c2dfbcf9923f784631 Subproject commit 1c82a536312e8321716ab7d80a5d17045d20d77f

View File

@ -58,9 +58,9 @@ from homeassistant.const import (
DOMAIN = "verisure" DOMAIN = "verisure"
DISCOVER_SENSORS = 'verisure.sensors' DISCOVER_SENSORS = 'verisure.sensors'
DISCOVER_SWITCHES = 'verisure.switches' DISCOVER_SWITCHES = 'verisure.switches'
DISCOVER_ALARMS = 'verisure.alarms' DISCOVER_ALARMS = 'verisure.alarms_control_panel'
DEPENDENCIES = ['alarm'] DEPENDENCIES = ['alarm_control_panel']
REQUIREMENTS = [ REQUIREMENTS = [
'https://github.com/persandstrom/python-verisure/archive/master.zip' 'https://github.com/persandstrom/python-verisure/archive/master.zip'
] ]

View File

@ -123,8 +123,6 @@ def get_component(comp_name):
# custom_components/switch/some_platform.py exists, # custom_components/switch/some_platform.py exists,
# the import custom_components.switch would succeeed. # the import custom_components.switch would succeeed.
if module.__spec__.origin == 'namespace': if module.__spec__.origin == 'namespace':
print("!!!!!!!!!!!!!!!!!!!!! " + module.__spec__.origin)
continue continue
_LOGGER.info("Loaded %s from %s", comp_name, path) _LOGGER.info("Loaded %s from %s", comp_name, path)