From 92fc7eab36dfc7823c7ea03fbff363d8f8c20c96 Mon Sep 17 00:00:00 2001 From: Per Sandstrom Date: Tue, 11 Aug 2015 09:28:07 +0200 Subject: [PATCH 1/7] added component and sensor --- .gitmodules | 3 + homeassistant/components/sensor/verisure.py | 65 +++++++++++++++++++++ homeassistant/components/verisure.py | 57 ++++++++++++++++++ requirements.txt | 2 + 4 files changed, 127 insertions(+) create mode 100644 homeassistant/components/sensor/verisure.py create mode 100644 homeassistant/components/verisure.py diff --git a/.gitmodules b/.gitmodules index a627e522d8f..2446411c57c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "homeassistant/components/frontend/www_static/home-assistant-polymer"] path = homeassistant/components/frontend/www_static/home-assistant-polymer url = https://github.com/balloob/home-assistant-polymer.git +[submodule "homeassistant/external/verisure"] + path = homeassistant/external/verisure + url = https://github.com/persandstrom/python-verisure.git diff --git a/homeassistant/components/sensor/verisure.py b/homeassistant/components/sensor/verisure.py new file mode 100644 index 00000000000..6f4f8054772 --- /dev/null +++ b/homeassistant/components/sensor/verisure.py @@ -0,0 +1,65 @@ +""" +homeassistant.components.sensor.verisure +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Interfaces with Verisure sensors. +""" +import logging + +import homeassistant.components.verisure as verisure + +from homeassistant.helpers.entity import Entity +from homeassistant.const import STATE_OPEN, STATE_CLOSED + +_LOGGER = logging.getLogger(__name__) + +def setup_platform(hass, config, add_devices, discovery_info=None): + """ Sets up the Verisure platform. """ + + if not verisure.MY_PAGES: + _LOGGER.error('A connection has not been made to Verisure mypages.') + return False + + sensors = [ + VerisureClimateDevice(status) for status + in verisure.MY_PAGES.get_climate_status()] + + sensors.extend([ + VerisureAlarmDevice(status) for status + in verisure.MY_PAGES.get_alarm_status()]) + + + add_devices(sensors) + + +class VerisureClimateDevice(Entity): + """ represents a Verisure climate sensor within home assistant. """ + + def __init__(self, climate_status): + self._status = climate_status + + @property + def name(self): + """ Returns the name of the device. """ + return self._status.location + + @property + def state(self): + """ Returns the state of the device. """ + return self._status.temperature + + +class VerisureAlarmDevice(Entity): + """ represents a Verisure alarm remote control within home assistant. """ + + def __init__(self, alarm_status): + self._status = alarm_status + + @property + def name(self): + """ Returns the name of the device. """ + return 'Alarm {}'.format(self._status.id) + + @property + def state(self): + """ Returns the state of the device. """ + return self._status.status diff --git a/homeassistant/components/verisure.py b/homeassistant/components/verisure.py new file mode 100644 index 00000000000..77a34ad979d --- /dev/null +++ b/homeassistant/components/verisure.py @@ -0,0 +1,57 @@ +""" +components.verisure +~~~~~~~~~~~~~~~~~~ +""" +import logging + +from homeassistant import bootstrap +from homeassistant.helpers import validate_config +from homeassistant.loader import get_component +from homeassistant.const import ( + EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP, + CONF_USERNAME, CONF_PASSWORD, + EVENT_PLATFORM_DISCOVERED, + ATTR_SERVICE, ATTR_DISCOVERED, ATTR_FRIENDLY_NAME) + +DOMAIN = "verisure" +DEPENDENCIES = [] +REQUIREMENTS = ['https://github.com/persandstrom/python-verisure/archive/master.zip'] + +MY_PAGES = None +_LOGGER = logging.getLogger(__name__) + +DISCOVER_SENSORS = "wink.sensors" + +def setup(hass, config): + """ Setup the Verisure component. """ + + if not validate_config(config, + {DOMAIN: [CONF_USERNAME, CONF_PASSWORD]}, + _LOGGER): + return False + + from verisure import MyPages + global MY_PAGES + MY_PAGES = MyPages(config[DOMAIN][CONF_USERNAME], config[DOMAIN][CONF_PASSWORD]) + MY_PAGES.login() + + component = get_component('sensor') + bootstrap.setup_component(hass, component.DOMAIN, config) + + # Fire discovery event + hass.bus.fire(EVENT_PLATFORM_DISCOVERED, { + ATTR_SERVICE: DISCOVER_SENSORS, + ATTR_DISCOVERED: {} + }) + + def stop_verisure(event): + """ Stop the Arduino service. """ + MY_PAGES.logout() + + def start_verisure(event): + """ Start the Arduino service. """ + hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_verisure) + + hass.bus.listen_once(EVENT_HOMEASSISTANT_START, start_verisure) + + return True diff --git a/requirements.txt b/requirements.txt index 445a2fe3657..24027be2d3b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -110,3 +110,5 @@ paho-mqtt>=1.1 # PyModbus (modbus) https://github.com/bashwork/pymodbus/archive/python3.zip#pymodbus>=1.2.0 +# Verisure +https://github.com/persandstrom/python-verisure/archive/master.zip From c7ca6e478426c3578c26d976b337881a3c4761ad Mon Sep 17 00:00:00 2001 From: Per Sandstrom Date: Wed, 12 Aug 2015 13:00:47 +0200 Subject: [PATCH 2/7] Added a switch --- homeassistant/components/sensor/verisure.py | 52 ++++++++++----- homeassistant/components/switch/verisure.py | 67 +++++++++++++++++++ homeassistant/components/verisure.py | 73 +++++++++++++++------ 3 files changed, 156 insertions(+), 36 deletions(-) create mode 100644 homeassistant/components/switch/verisure.py diff --git a/homeassistant/components/sensor/verisure.py b/homeassistant/components/sensor/verisure.py index 6f4f8054772..12ca073ceab 100644 --- a/homeassistant/components/sensor/verisure.py +++ b/homeassistant/components/sensor/verisure.py @@ -8,10 +8,13 @@ import logging import homeassistant.components.verisure as verisure from homeassistant.helpers.entity import Entity -from homeassistant.const import STATE_OPEN, STATE_CLOSED +from homeassistant.const import TEMP_CELCIUS _LOGGER = logging.getLogger(__name__) +DEPENDENCIES = ['verisure'] + + def setup_platform(hass, config, add_devices, discovery_info=None): """ Sets up the Verisure platform. """ @@ -19,14 +22,17 @@ def setup_platform(hass, config, add_devices, discovery_info=None): _LOGGER.error('A connection has not been made to Verisure mypages.') return False - sensors = [ - VerisureClimateDevice(status) for status - in verisure.MY_PAGES.get_climate_status()] + sensors = [] sensors.extend([ - VerisureAlarmDevice(status) for status - in verisure.MY_PAGES.get_alarm_status()]) + VerisureClimateDevice(value) + for value in verisure.get_climate_status().values() + ]) + sensors.extend([ + VerisureAlarmDevice(value) + for value in verisure.get_alarm_status().values() + ]) add_devices(sensors) @@ -35,31 +41,45 @@ class VerisureClimateDevice(Entity): """ represents a Verisure climate sensor within home assistant. """ def __init__(self, climate_status): - self._status = climate_status - + self._id = climate_status.id + self._device = verisure.MY_PAGES.DEVICE_CLIMATE + @property def name(self): """ Returns the name of the device. """ - return self._status.location + return verisure.STATUS[self._device][self._id].location @property def state(self): """ Returns the state of the device. """ - return self._status.temperature + # remove ° character + return verisure.STATUS[self._device][self._id].temperature[:-1] + + @property + def unit_of_measurement(self): + """ Unit of measurement of this entity """ + return TEMP_CELCIUS # can verisure report in fahrenheit? + + def update(self): + verisure.update() class VerisureAlarmDevice(Entity): - """ represents a Verisure alarm remote control within home assistant. """ - + """ represents a Verisure alarm status within home assistant. """ + def __init__(self, alarm_status): - self._status = alarm_status - + self._id = alarm_status.id + self._device = verisure.MY_PAGES.DEVICE_ALARM + @property def name(self): """ Returns the name of the device. """ - return 'Alarm {}'.format(self._status.id) + return 'Alarm {}'.format(self._id) @property def state(self): """ Returns the state of the device. """ - return self._status.status + return verisure.STATUS[self._device][self._id].status + + def update(self): + verisure.update() diff --git a/homeassistant/components/switch/verisure.py b/homeassistant/components/switch/verisure.py new file mode 100644 index 00000000000..98979b400ed --- /dev/null +++ b/homeassistant/components/switch/verisure.py @@ -0,0 +1,67 @@ +""" +homeassistant.components.switch.verisure +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Support for Verisure Smartplugs + +Configuration: + +switch: + platform: verisure + +Variables: + +""" +import logging + +import homeassistant.components.verisure as verisure +from homeassistant.components.switch import SwitchDevice + +DEPENDENCIES = ['verisure'] + +_LOGGER = logging.getLogger(__name__) + + +def setup_platform(hass, config, add_devices, discovery_info=None): + """ Sets up the Arduino platform. """ + + if not verisure.MY_PAGES: + _LOGGER.error('A connection has not been made to Verisure mypages.') + return False + + switches = [] + + switches.extend([ + VerisureSmartplug(value) + for value in verisure.get_smartplug_status().values() + ]) + + add_devices(switches) + + +class VerisureSmartplug(SwitchDevice): + """ Represents a Verisure smartplug. """ + def __init__(self, smartplug_status): + self._id = smartplug_status.id + + @property + def name(self): + """ Get the name (location) of the smartplug. """ + return verisure.get_smartplug_status()[self._id].location + + @property + def is_on(self): + """ Returns True if on """ + plug_status = verisure.get_smartplug_status()[self._id].status + return plug_status == verisure.MY_PAGES.SMARTPLUG_ON + + def turn_on(self): + """ Set smartplug status on """ + verisure.MY_PAGES.set_smartplug_status( + self._id, + verisure.MY_PAGES.SMARTPLUG_ON) + + def turn_off(self): + """ Set smartplug status off. """ + verisure.MY_PAGES.set_smartplug_status( + self._id, + verisure.MY_PAGES.SMARTPLUG_OFF) diff --git a/homeassistant/components/verisure.py b/homeassistant/components/verisure.py index 77a34ad979d..f902381fbb9 100644 --- a/homeassistant/components/verisure.py +++ b/homeassistant/components/verisure.py @@ -3,24 +3,27 @@ components.verisure ~~~~~~~~~~~~~~~~~~ """ import logging +from datetime import timedelta -from homeassistant import bootstrap from homeassistant.helpers import validate_config -from homeassistant.loader import get_component +from homeassistant.util import Throttle from homeassistant.const import ( EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP, - CONF_USERNAME, CONF_PASSWORD, - EVENT_PLATFORM_DISCOVERED, - ATTR_SERVICE, ATTR_DISCOVERED, ATTR_FRIENDLY_NAME) + CONF_USERNAME, CONF_PASSWORD) DOMAIN = "verisure" DEPENDENCIES = [] -REQUIREMENTS = ['https://github.com/persandstrom/python-verisure/archive/master.zip'] +REQUIREMENTS = [ + 'https://github.com/persandstrom/python-verisure/archive/master.zip' + ] -MY_PAGES = None _LOGGER = logging.getLogger(__name__) -DISCOVER_SENSORS = "wink.sensors" +MY_PAGES = None +STATUS = {} + +MIN_TIME_BETWEEN_REQUESTS = timedelta(seconds=5) + def setup(hass, config): """ Setup the Verisure component. """ @@ -31,27 +34,57 @@ def setup(hass, config): return False from verisure import MyPages + + STATUS[MyPages.DEVICE_ALARM] = {} + STATUS[MyPages.DEVICE_CLIMATE] = {} + STATUS[MyPages.DEVICE_SMARTPLUG] = {} + global MY_PAGES - MY_PAGES = MyPages(config[DOMAIN][CONF_USERNAME], config[DOMAIN][CONF_PASSWORD]) + MY_PAGES = MyPages( + config[DOMAIN][CONF_USERNAME], + config[DOMAIN][CONF_PASSWORD]) MY_PAGES.login() - - component = get_component('sensor') - bootstrap.setup_component(hass, component.DOMAIN, config) - - # Fire discovery event - hass.bus.fire(EVENT_PLATFORM_DISCOVERED, { - ATTR_SERVICE: DISCOVER_SENSORS, - ATTR_DISCOVERED: {} - }) + update() def stop_verisure(event): - """ Stop the Arduino service. """ + """ Stop the Verisure service. """ MY_PAGES.logout() def start_verisure(event): - """ Start the Arduino service. """ + """ Start the Verisure service. """ hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_verisure) hass.bus.listen_once(EVENT_HOMEASSISTANT_START, start_verisure) return True + + +def get_alarm_status(): + ''' return a list of status overviews for alarm components ''' + return STATUS[MY_PAGES.DEVICE_ALARM] + + +def get_climate_status(): + ''' return a list of status overviews for alarm components ''' + return STATUS[MY_PAGES.DEVICE_CLIMATE] + + +def get_smartplug_status(): + ''' return a list of status overviews for alarm components ''' + return STATUS[MY_PAGES.DEVICE_SMARTPLUG] + + +@Throttle(MIN_TIME_BETWEEN_REQUESTS) +def update(): + ''' Updates the status of verisure components ''' + try: + for overview in MY_PAGES.get_overview(MY_PAGES.DEVICE_ALARM): + STATUS[MY_PAGES.DEVICE_ALARM][overview.id] = overview + for overview in MY_PAGES.get_overview(MY_PAGES.DEVICE_CLIMATE): + STATUS[MY_PAGES.DEVICE_CLIMATE][overview.id] = overview + for overview in MY_PAGES.get_overview(MY_PAGES.DEVICE_SMARTPLUG): + STATUS[MY_PAGES.DEVICE_SMARTPLUG][overview.id] = overview + except ConnectionError as ex: + _LOGGER.error('Caught connection error {}, tries to reconnect'.format( + ex)) + MY_PAGES.login() From 1b59859681151cd85893ff3d1be48a99dddc3be2 Mon Sep 17 00:00:00 2001 From: Per Sandstrom Date: Wed, 12 Aug 2015 13:28:22 +0200 Subject: [PATCH 3/7] fixed pylint warning --- homeassistant/components/verisure.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/homeassistant/components/verisure.py b/homeassistant/components/verisure.py index f902381fbb9..6776766d20e 100644 --- a/homeassistant/components/verisure.py +++ b/homeassistant/components/verisure.py @@ -85,6 +85,5 @@ def update(): for overview in MY_PAGES.get_overview(MY_PAGES.DEVICE_SMARTPLUG): STATUS[MY_PAGES.DEVICE_SMARTPLUG][overview.id] = overview except ConnectionError as ex: - _LOGGER.error('Caught connection error {}, tries to reconnect'.format( - ex)) + _LOGGER.error('Caught connection error %, tries to reconnect', ex) MY_PAGES.login() From f20be1e7f88fce0f254f5d63e7eb06e9c584ab8a Mon Sep 17 00:00:00 2001 From: Per Sandstrom Date: Wed, 12 Aug 2015 13:32:15 +0200 Subject: [PATCH 4/7] fixed pylint warning --- homeassistant/components/verisure.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/verisure.py b/homeassistant/components/verisure.py index 6776766d20e..a2bdf688175 100644 --- a/homeassistant/components/verisure.py +++ b/homeassistant/components/verisure.py @@ -85,5 +85,5 @@ def update(): for overview in MY_PAGES.get_overview(MY_PAGES.DEVICE_SMARTPLUG): STATUS[MY_PAGES.DEVICE_SMARTPLUG][overview.id] = overview except ConnectionError as ex: - _LOGGER.error('Caught connection error %, tries to reconnect', ex) + _LOGGER.error('Caught connection error %s, tries to reconnect', ex) MY_PAGES.login() From ad327b64eddeb2abd31ab13e53c9e2bb967588fa Mon Sep 17 00:00:00 2001 From: Per Sandstrom Date: Sat, 15 Aug 2015 13:36:30 +0200 Subject: [PATCH 5/7] code reveiw --- .gitmodules | 3 - homeassistant/components/sensor/__init__.py | 5 +- homeassistant/components/switch/__init__.py | 3 +- homeassistant/components/switch/verisure.py | 11 +++- homeassistant/components/verisure.py | 63 +++++++++++++++++---- 5 files changed, 64 insertions(+), 21 deletions(-) diff --git a/.gitmodules b/.gitmodules index 2446411c57c..a627e522d8f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,6 +10,3 @@ [submodule "homeassistant/components/frontend/www_static/home-assistant-polymer"] path = homeassistant/components/frontend/www_static/home-assistant-polymer url = https://github.com/balloob/home-assistant-polymer.git -[submodule "homeassistant/external/verisure"] - path = homeassistant/external/verisure - url = https://github.com/persandstrom/python-verisure.git diff --git a/homeassistant/components/sensor/__init__.py b/homeassistant/components/sensor/__init__.py index 5cbd07d0e59..90317cdf90a 100644 --- a/homeassistant/components/sensor/__init__.py +++ b/homeassistant/components/sensor/__init__.py @@ -6,7 +6,7 @@ Component to interface with various sensors that can be monitored. import logging from homeassistant.helpers.entity_component import EntityComponent -from homeassistant.components import wink, zwave, isy994 +from homeassistant.components import wink, zwave, isy994, verisure DOMAIN = 'sensor' DEPENDENCIES = [] @@ -18,7 +18,8 @@ ENTITY_ID_FORMAT = DOMAIN + '.{}' DISCOVERY_PLATFORMS = { wink.DISCOVER_SENSORS: 'wink', zwave.DISCOVER_SENSORS: 'zwave', - isy994.DISCOVER_SENSORS: 'isy994' + isy994.DISCOVER_SENSORS: 'isy994', + verisure.DISCOVER_SENSORS: 'verisure' } diff --git a/homeassistant/components/switch/__init__.py b/homeassistant/components/switch/__init__.py index 1d6f0b79d52..424d4505d39 100644 --- a/homeassistant/components/switch/__init__.py +++ b/homeassistant/components/switch/__init__.py @@ -11,7 +11,7 @@ from homeassistant.helpers.entity import ToggleEntity from homeassistant.const import ( STATE_ON, SERVICE_TURN_ON, SERVICE_TURN_OFF, ATTR_ENTITY_ID) -from homeassistant.components import group, discovery, wink, isy994 +from homeassistant.components import group, discovery, wink, isy994, verisure DOMAIN = 'switch' DEPENDENCIES = [] @@ -32,6 +32,7 @@ DISCOVERY_PLATFORMS = { discovery.SERVICE_WEMO: 'wemo', wink.DISCOVER_SWITCHES: 'wink', isy994.DISCOVER_SWITCHES: 'isy994', + verisure.DISCOVER_SWITCHES: 'verisure' } PROP_TO_ATTR = { diff --git a/homeassistant/components/switch/verisure.py b/homeassistant/components/switch/verisure.py index 98979b400ed..52182bf94a9 100644 --- a/homeassistant/components/switch/verisure.py +++ b/homeassistant/components/switch/verisure.py @@ -42,6 +42,8 @@ class VerisureSmartplug(SwitchDevice): """ Represents a Verisure smartplug. """ def __init__(self, smartplug_status): self._id = smartplug_status.id + self.STATUS_ON = verisure.MY_PAGES.SMARTPLUG_ON + self.STATUS_OFF = verisure.MY_PAGES.SMARTPLUG_OFF @property def name(self): @@ -52,16 +54,19 @@ class VerisureSmartplug(SwitchDevice): def is_on(self): """ Returns True if on """ plug_status = verisure.get_smartplug_status()[self._id].status - return plug_status == verisure.MY_PAGES.SMARTPLUG_ON + return plug_status == self.STATUS_ON def turn_on(self): """ Set smartplug status on """ verisure.MY_PAGES.set_smartplug_status( self._id, - verisure.MY_PAGES.SMARTPLUG_ON) + self.STATUS_ON) def turn_off(self): """ Set smartplug status off. """ verisure.MY_PAGES.set_smartplug_status( self._id, - verisure.MY_PAGES.SMARTPLUG_OFF) + self.STATUS_OFF) + + def update(self): + verisure.update() diff --git a/homeassistant/components/verisure.py b/homeassistant/components/verisure.py index a2bdf688175..6e0d6a81539 100644 --- a/homeassistant/components/verisure.py +++ b/homeassistant/components/verisure.py @@ -5,13 +5,21 @@ components.verisure import logging from datetime import timedelta +from homeassistant import bootstrap +from homeassistant.loader import get_component + from homeassistant.helpers import validate_config from homeassistant.util import Throttle from homeassistant.const import ( - EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP, + EVENT_PLATFORM_DISCOVERED, + ATTR_SERVICE, ATTR_DISCOVERED, CONF_USERNAME, CONF_PASSWORD) + DOMAIN = "verisure" +DISCOVER_SENSORS = 'verisure.sensors' +DISCOVER_SWITCHES = 'verisure.switches' + DEPENDENCIES = [] REQUIREMENTS = [ 'https://github.com/persandstrom/python-verisure/archive/master.zip' @@ -22,6 +30,12 @@ _LOGGER = logging.getLogger(__name__) MY_PAGES = None STATUS = {} +VERISURE_LOGIN_ERROR = None +VERISURE_ERROR = None + +# if wrong password was given don't try again +WRONG_PASSWORD_GIVEN = False + MIN_TIME_BETWEEN_REQUESTS = timedelta(seconds=5) @@ -33,7 +47,7 @@ def setup(hass, config): _LOGGER): return False - from verisure import MyPages + from verisure import MyPages, LoginError, Error STATUS[MyPages.DEVICE_ALARM] = {} STATUS[MyPages.DEVICE_CLIMATE] = {} @@ -43,18 +57,27 @@ def setup(hass, config): MY_PAGES = MyPages( config[DOMAIN][CONF_USERNAME], config[DOMAIN][CONF_PASSWORD]) - MY_PAGES.login() + global VERISURE_LOGIN_ERROR, VERISURE_ERROR + VERISURE_LOGIN_ERROR = LoginError + VERISURE_ERROR = Error + + try: + MY_PAGES.login() + except (ConnectionError, Error) as ex: + _LOGGER.error('Could not log in to verisure mypages, %s', ex.message) + return False + update() - def stop_verisure(event): - """ Stop the Verisure service. """ - MY_PAGES.logout() + # Load components for the devices in the ISY controller that we support + for comp_name, discovery in ((('sensor', DISCOVER_SENSORS), + ('switch', DISCOVER_SWITCHES))): + component = get_component(comp_name) + bootstrap.setup_component(hass, component.DOMAIN, config) - def start_verisure(event): - """ Start the Verisure service. """ - hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_verisure) - - hass.bus.listen_once(EVENT_HOMEASSISTANT_START, start_verisure) + hass.bus.fire(EVENT_PLATFORM_DISCOVERED, + {ATTR_SERVICE: discovery, + ATTR_DISCOVERED: {}}) return True @@ -74,9 +97,25 @@ def get_smartplug_status(): return STATUS[MY_PAGES.DEVICE_SMARTPLUG] +def reconnect(): + ''' reconnect to verisure mypages ''' + try: + MY_PAGES.login() + except VERISURE_LOGIN_ERROR as ex: + _LOGGER.error("Could not login to Verisure mypages, %s", ex.message) + global WRONG_PASSWORD_GIVEN + WRONG_PASSWORD_GIVEN = True + except (ConnectionError, VERISURE_ERROR) as ex: + _LOGGER.error("Could not login to Verisure mypages, %s", ex.message) + + @Throttle(MIN_TIME_BETWEEN_REQUESTS) def update(): ''' Updates the status of verisure components ''' + if WRONG_PASSWORD_GIVEN: + # Is there any way to inform user? + return + try: for overview in MY_PAGES.get_overview(MY_PAGES.DEVICE_ALARM): STATUS[MY_PAGES.DEVICE_ALARM][overview.id] = overview @@ -86,4 +125,4 @@ def update(): STATUS[MY_PAGES.DEVICE_SMARTPLUG][overview.id] = overview except ConnectionError as ex: _LOGGER.error('Caught connection error %s, tries to reconnect', ex) - MY_PAGES.login() + reconnect() From a0f2f3814b22fd792eeb1d84d252f81abac1d32a Mon Sep 17 00:00:00 2001 From: Per Sandstrom Date: Sun, 16 Aug 2015 06:51:09 +0200 Subject: [PATCH 6/7] fixed flak8 --- homeassistant/components/switch/verisure.py | 10 +++++----- homeassistant/components/verisure.py | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/switch/verisure.py b/homeassistant/components/switch/verisure.py index 52182bf94a9..cc331f12fdb 100644 --- a/homeassistant/components/switch/verisure.py +++ b/homeassistant/components/switch/verisure.py @@ -42,8 +42,8 @@ class VerisureSmartplug(SwitchDevice): """ Represents a Verisure smartplug. """ def __init__(self, smartplug_status): self._id = smartplug_status.id - self.STATUS_ON = verisure.MY_PAGES.SMARTPLUG_ON - self.STATUS_OFF = verisure.MY_PAGES.SMARTPLUG_OFF + self.status_off = verisure.MY_PAGES.SMARTPLUG_ON + self.status_off = verisure.MY_PAGES.SMARTPLUG_OFF @property def name(self): @@ -54,19 +54,19 @@ class VerisureSmartplug(SwitchDevice): def is_on(self): """ Returns True if on """ plug_status = verisure.get_smartplug_status()[self._id].status - return plug_status == self.STATUS_ON + return plug_status == self.status_off def turn_on(self): """ Set smartplug status on """ verisure.MY_PAGES.set_smartplug_status( self._id, - self.STATUS_ON) + self.status_on) def turn_off(self): """ Set smartplug status off. """ verisure.MY_PAGES.set_smartplug_status( self._id, - self.STATUS_OFF) + self.status_off) def update(self): verisure.update() diff --git a/homeassistant/components/verisure.py b/homeassistant/components/verisure.py index 6e0d6a81539..18a7701a3ab 100644 --- a/homeassistant/components/verisure.py +++ b/homeassistant/components/verisure.py @@ -64,7 +64,7 @@ def setup(hass, config): try: MY_PAGES.login() except (ConnectionError, Error) as ex: - _LOGGER.error('Could not log in to verisure mypages, %s', ex.message) + _LOGGER.error('Could not log in to verisure mypages, %s', ex) return False update() @@ -102,11 +102,11 @@ def reconnect(): try: MY_PAGES.login() except VERISURE_LOGIN_ERROR as ex: - _LOGGER.error("Could not login to Verisure mypages, %s", ex.message) + _LOGGER.error("Could not login to Verisure mypages, %s", ex) global WRONG_PASSWORD_GIVEN WRONG_PASSWORD_GIVEN = True except (ConnectionError, VERISURE_ERROR) as ex: - _LOGGER.error("Could not login to Verisure mypages, %s", ex.message) + _LOGGER.error("Could not login to Verisure mypages, %s", ex) @Throttle(MIN_TIME_BETWEEN_REQUESTS) From e37869616bcbdc78ef9dabef6780f17c93f7e793 Mon Sep 17 00:00:00 2001 From: Per Sandstrom Date: Sun, 16 Aug 2015 08:03:19 +0200 Subject: [PATCH 7/7] no more duplicate sensors --- homeassistant/components/sensor/verisure.py | 4 +--- homeassistant/components/switch/verisure.py | 8 +++----- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/sensor/verisure.py b/homeassistant/components/sensor/verisure.py index 12ca073ceab..163d608d7d2 100644 --- a/homeassistant/components/sensor/verisure.py +++ b/homeassistant/components/sensor/verisure.py @@ -12,8 +12,6 @@ from homeassistant.const import TEMP_CELCIUS _LOGGER = logging.getLogger(__name__) -DEPENDENCIES = ['verisure'] - def setup_platform(hass, config, add_devices, discovery_info=None): """ Sets up the Verisure platform. """ @@ -79,7 +77,7 @@ class VerisureAlarmDevice(Entity): @property def state(self): """ Returns the state of the device. """ - return verisure.STATUS[self._device][self._id].status + return verisure.STATUS[self._device][self._id].label def update(self): verisure.update() diff --git a/homeassistant/components/switch/verisure.py b/homeassistant/components/switch/verisure.py index cc331f12fdb..f71ca7550a7 100644 --- a/homeassistant/components/switch/verisure.py +++ b/homeassistant/components/switch/verisure.py @@ -16,8 +16,6 @@ import logging import homeassistant.components.verisure as verisure from homeassistant.components.switch import SwitchDevice -DEPENDENCIES = ['verisure'] - _LOGGER = logging.getLogger(__name__) @@ -42,7 +40,7 @@ class VerisureSmartplug(SwitchDevice): """ Represents a Verisure smartplug. """ def __init__(self, smartplug_status): self._id = smartplug_status.id - self.status_off = verisure.MY_PAGES.SMARTPLUG_ON + self.status_on = verisure.MY_PAGES.SMARTPLUG_ON self.status_off = verisure.MY_PAGES.SMARTPLUG_OFF @property @@ -54,7 +52,7 @@ class VerisureSmartplug(SwitchDevice): def is_on(self): """ Returns True if on """ plug_status = verisure.get_smartplug_status()[self._id].status - return plug_status == self.status_off + return plug_status == self.status_on def turn_on(self): """ Set smartplug status on """ @@ -63,7 +61,7 @@ class VerisureSmartplug(SwitchDevice): self.status_on) def turn_off(self): - """ Set smartplug status off. """ + """ Set smartplug status off """ verisure.MY_PAGES.set_smartplug_status( self._id, self.status_off)