From 683a80f5f4a8fbd5de1278ea4b33077a54bb3b85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20Sandstr=C3=B6m?= Date: Sun, 13 Sep 2015 20:21:02 +0200 Subject: [PATCH] tests pass --- .../__init__.py | 30 ++++++------- .../verisure.py | 42 +++++++++++-------- .../www_static/home-assistant-polymer | 2 +- homeassistant/components/verisure.py | 4 +- homeassistant/loader.py | 2 - 5 files changed, 44 insertions(+), 36 deletions(-) rename homeassistant/components/{alarm => alarm_control_panel}/__init__.py (88%) rename homeassistant/components/{alarm => alarm_control_panel}/verisure.py (66%) diff --git a/homeassistant/components/alarm/__init__.py b/homeassistant/components/alarm_control_panel/__init__.py similarity index 88% rename from homeassistant/components/alarm/__init__.py rename to homeassistant/components/alarm_control_panel/__init__.py index 449cbbbe452..f31be44e64f 100644 --- a/homeassistant/components/alarm/__init__.py +++ b/homeassistant/components/alarm_control_panel/__init__.py @@ -1,5 +1,5 @@ """ -homeassistant.components.sensor +homeassistant.components.alarm_control_panel ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 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.components import verisure from homeassistant.const import ( - STATE_UNKNOWN, - STATE_ALARM_DISARMED, STATE_ALARM_ARMED_HOME, STATE_ALARM_ARMED_AWAY, - ATTR_ENTITY_PICTURE, + ATTR_ENTITY_ID, SERVICE_ALARM_DISARM, SERVICE_ALARM_ARM_HOME, SERVICE_ALARM_ARM_AWAY) -DOMAIN = 'alarm' +DOMAIN = 'alarm_control_panel' DEPENDENCIES = [] SCAN_INTERVAL = 30 @@ -30,12 +28,13 @@ SERVICE_TO_METHOD = { SERVICE_ALARM_ARM_AWAY: 'alarm_arm_away', } -ATTR_CODE = 'code' +ATTR_CODE = 'code' ATTR_TO_PROPERTY = [ ATTR_CODE, ] + def setup(hass, config): """ Track states and offer events for sensors. """ component = EntityComponent( @@ -43,15 +42,15 @@ def setup(hass, config): DISCOVERY_PLATFORMS) component.setup(config) - + def alarm_service_handler(service): """ Maps services to methods on Alarm. """ target_alarms = component.extract_from_service(service) - + if ATTR_CODE not in service.data: return - code = service.data[ATTR_CODE] + code = service.data[ATTR_CODE] method = SERVICE_TO_METHOD[service.service] @@ -72,7 +71,7 @@ def alarm_disarm(hass, code, entity_id=None): data[ATTR_ENTITY_ID] = entity_id hass.services.call(DOMAIN, SERVICE_ALARM_DISARM, data) - + def alarm_arm_home(hass, code, entity_id=None): """ Send the alarm the command for arm home. """ @@ -83,6 +82,7 @@ def alarm_arm_home(hass, code, entity_id=None): hass.services.call(DOMAIN, SERVICE_ALARM_ARM_HOME, data) + def alarm_arm_away(hass, code, entity_id=None): """ Send the alarm the command for arm away. """ data = {ATTR_CODE: code} @@ -92,15 +92,17 @@ def alarm_arm_away(hass, code, entity_id=None): 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): - """ Send disar command. """ + """ Send disarm command. """ raise NotImplementedError() - + def alarm_arm_home(self, code): """ Send pause command. """ raise NotImplementedError() - + def alarm_arm_away(self, code): """ Send pause command. """ raise NotImplementedError() diff --git a/homeassistant/components/alarm/verisure.py b/homeassistant/components/alarm_control_panel/verisure.py similarity index 66% rename from homeassistant/components/alarm/verisure.py rename to homeassistant/components/alarm_control_panel/verisure.py index 1969273dfd1..52d5a21a8b4 100644 --- a/homeassistant/components/alarm/verisure.py +++ b/homeassistant/components/alarm_control_panel/verisure.py @@ -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 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 (STATE_UNKNOWN, - STATE_ALARM_DISARMED, STATE_ALARM_ARMED_HOME, STATE_ALARM_ARMED_AWAY) +from homeassistant.const import ( + STATE_UNKNOWN, + STATE_ALARM_DISARMED, STATE_ALARM_ARMED_HOME, STATE_ALARM_ARMED_AWAY) _LOGGER = logging.getLogger(__name__) @@ -33,7 +33,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): add_devices(alarms) -class VerisureAlarm(alarm.AlarmControl): +class VerisureAlarm(alarm.AlarmControlPanel): """ represents a Verisure alarm status within home assistant. """ def __init__(self, alarm_status): @@ -56,24 +56,32 @@ class VerisureAlarm(alarm.AlarmControl): elif verisure.STATUS[self._device][self._id].status == 'armedaway': self._state = STATE_ALARM_ARMED_AWAY 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 def update(self): ''' update alarm status ''' verisure.update() - + def alarm_disarm(self, code): """ Send disarm command. """ - verisure.MY_PAGES.set_alarm_status(code, verisure.MY_PAGES.ALARM_DISARMED) - _LOGGER.warning('disarming') - + verisure.MY_PAGES.set_alarm_status( + code, + verisure.MY_PAGES.ALARM_DISARMED) + _LOGGER.warning('disarming') + def alarm_arm_home(self, code): """ Send arm home command. """ - verisure.MY_PAGES.set_alarm_status(code, verisure.MY_PAGES.ALARM_ARMED_HOME) - _LOGGER.warning('arming home') - + verisure.MY_PAGES.set_alarm_status( + code, + verisure.MY_PAGES.ALARM_ARMED_HOME) + _LOGGER.warning('arming home') + def alarm_arm_away(self, code): """ Send arm away command. """ - verisure.MY_PAGES.set_alarm_status(code, verisure.MY_PAGES.ALARM_ARMED_AWAY) - _LOGGER.warning('arming away') + verisure.MY_PAGES.set_alarm_status( + code, + verisure.MY_PAGES.ALARM_ARMED_AWAY) + _LOGGER.warning('arming away') diff --git a/homeassistant/components/frontend/www_static/home-assistant-polymer b/homeassistant/components/frontend/www_static/home-assistant-polymer index b0b12e20e0f..1c82a536312 160000 --- a/homeassistant/components/frontend/www_static/home-assistant-polymer +++ b/homeassistant/components/frontend/www_static/home-assistant-polymer @@ -1 +1 @@ -Subproject commit b0b12e20e0f61df849c414c2dfbcf9923f784631 +Subproject commit 1c82a536312e8321716ab7d80a5d17045d20d77f diff --git a/homeassistant/components/verisure.py b/homeassistant/components/verisure.py index 895a984cf86..4e97cca0cd4 100644 --- a/homeassistant/components/verisure.py +++ b/homeassistant/components/verisure.py @@ -58,9 +58,9 @@ from homeassistant.const import ( DOMAIN = "verisure" DISCOVER_SENSORS = 'verisure.sensors' DISCOVER_SWITCHES = 'verisure.switches' -DISCOVER_ALARMS = 'verisure.alarms' +DISCOVER_ALARMS = 'verisure.alarms_control_panel' -DEPENDENCIES = ['alarm'] +DEPENDENCIES = ['alarm_control_panel'] REQUIREMENTS = [ 'https://github.com/persandstrom/python-verisure/archive/master.zip' ] diff --git a/homeassistant/loader.py b/homeassistant/loader.py index 356d20c0620..7b755214252 100644 --- a/homeassistant/loader.py +++ b/homeassistant/loader.py @@ -123,8 +123,6 @@ def get_component(comp_name): # custom_components/switch/some_platform.py exists, # the import custom_components.switch would succeeed. if module.__spec__.origin == 'namespace': - - print("!!!!!!!!!!!!!!!!!!!!! " + module.__spec__.origin) continue _LOGGER.info("Loaded %s from %s", comp_name, path)