Skip to content
Snippets Groups Projects
Commit c584b6b2 authored by John Arild Berentsen's avatar John Arild Berentsen
Browse files

Support for Mousedetectors connected in Verisure systems

parent 4ce1a67c
No related branches found
No related tags found
No related merge requests found
......@@ -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,34 @@ 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 """
if verisure.MOUSEDETECTION_STATUS[self._id].count >= 1:
return "Mice"
else:
return "Mouse"
def update(self):
""" update sensor """
verisure.update_mousedetection()
......@@ -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 IndexError:
status[overview.deviceLabel] = overview
except (ConnectionError, VERISURE_ERROR) as ex:
_LOGGER.error('Caught connection error %s, tries to reconnect', ex)
reconnect()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment