Merge pull request #1222 from turbokongen/verisure-mouse

Support for Mousedetectors connected in Verisure systems
pull/1232/head
Paulus Schoutsen 2016-02-13 00:22:34 -08:00
commit 6d6cf886f3
2 changed files with 50 additions and 2 deletions

View File

@ -39,6 +39,13 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
hasattr(value, 'humidity') and value.humidity
])
sensors.extend([
VerisureMouseDetection(value)
for value in verisure.MOUSEDETECTION_STATUS.values()
if verisure.SHOW_MOUSEDETECTION and
hasattr(value, 'amountText') and value.amountText
])
add_devices(sensors)
@ -98,3 +105,31 @@ class VerisureHygrometer(Entity):
def update(self):
""" update sensor """
verisure.update_climate()
class VerisureMouseDetection(Entity):
""" represents a Verisure mousedetector within home assistant. """
def __init__(self, mousedetection_status):
self._id = mousedetection_status.deviceLabel
@property
def name(self):
""" Returns the name of the device. """
return '{} {}'.format(
verisure.MOUSEDETECTION_STATUS[self._id].location,
"Mouse")
@property
def state(self):
""" Returns the state of the device. """
return verisure.MOUSEDETECTION_STATUS[self._id].count
@property
def unit_of_measurement(self):
""" Unit of measurement of this entity """
return "Mice"
def update(self):
""" update sensor """
verisure.update_mousedetection()

View File

@ -38,6 +38,7 @@ ALARM_STATUS = {}
SMARTPLUG_STATUS = {}
CLIMATE_STATUS = {}
LOCK_STATUS = {}
MOUSEDETECTION_STATUS = {}
VERISURE_LOGIN_ERROR = None
VERISURE_ERROR = None
@ -47,6 +48,7 @@ SHOW_HYGROMETERS = True
SHOW_ALARM = True
SHOW_SMARTPLUGS = True
SHOW_LOCKS = True
SHOW_MOUSEDETECTION = True
CODE_DIGITS = 4
# if wrong password was given don't try again
@ -66,12 +68,14 @@ def setup(hass, config):
from verisure import MyPages, LoginError, Error
global SHOW_THERMOMETERS, SHOW_HYGROMETERS,\
SHOW_ALARM, SHOW_SMARTPLUGS, SHOW_LOCKS, CODE_DIGITS
SHOW_ALARM, SHOW_SMARTPLUGS, SHOW_LOCKS, SHOW_MOUSEDETECTION,\
CODE_DIGITS
SHOW_THERMOMETERS = int(config[DOMAIN].get('thermometers', '1'))
SHOW_HYGROMETERS = int(config[DOMAIN].get('hygrometers', '1'))
SHOW_ALARM = int(config[DOMAIN].get('alarm', '1'))
SHOW_SMARTPLUGS = int(config[DOMAIN].get('smartplugs', '1'))
SHOW_LOCKS = int(config[DOMAIN].get('locks', '1'))
SHOW_MOUSEDETECTION = int(config[DOMAIN].get('mouse', '1'))
CODE_DIGITS = int(config[DOMAIN].get('code_digits', '4'))
global MY_PAGES
@ -92,6 +96,7 @@ def setup(hass, config):
update_climate()
update_smartplug()
update_lock()
update_mousedetection()
# Load components for the devices in the ISY controller that we support
for comp_name, discovery in ((('sensor', DISCOVER_SENSORS),
@ -145,6 +150,11 @@ def update_lock():
update_component(MY_PAGES.lock.get, LOCK_STATUS)
def update_mousedetection():
""" Updates the status of mouse detectors. """
update_component(MY_PAGES.mousedetection.get, MOUSEDETECTION_STATUS)
def update_component(get_function, status):
""" Updates the status of verisure components. """
if WRONG_PASSWORD_GIVEN:
@ -152,7 +162,10 @@ def update_component(get_function, status):
return
try:
for overview in get_function():
status[overview.id] = overview
try:
status[overview.id] = overview
except AttributeError:
status[overview.deviceLabel] = overview
except (ConnectionError, VERISURE_ERROR) as ex:
_LOGGER.error('Caught connection error %s, tries to reconnect', ex)
reconnect()