2015-08-11 07:28:07 +00:00
|
|
|
"""
|
|
|
|
homeassistant.components.sensor.verisure
|
2015-10-20 19:31:25 +00:00
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2015-08-11 07:28:07 +00:00
|
|
|
Interfaces with Verisure sensors.
|
2015-10-20 19:31:25 +00:00
|
|
|
|
2015-11-09 12:12:18 +00:00
|
|
|
For more details about this platform, please refer to the documentation at
|
|
|
|
documentation at https://home-assistant.io/components/verisure/
|
2015-08-11 07:28:07 +00:00
|
|
|
"""
|
|
|
|
import logging
|
|
|
|
|
|
|
|
import homeassistant.components.verisure as verisure
|
|
|
|
|
|
|
|
from homeassistant.helpers.entity import Entity
|
2015-08-12 11:00:47 +00:00
|
|
|
from homeassistant.const import TEMP_CELCIUS
|
2015-08-11 07:28:07 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2015-08-12 11:00:47 +00:00
|
|
|
|
2015-08-11 07:28:07 +00:00
|
|
|
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
|
|
|
|
|
2015-08-12 11:00:47 +00:00
|
|
|
sensors = []
|
2015-08-11 07:28:07 +00:00
|
|
|
|
|
|
|
sensors.extend([
|
2015-08-17 11:05:49 +00:00
|
|
|
VerisureThermometer(value)
|
2015-12-25 19:16:51 +00:00
|
|
|
for value in verisure.CLIMATE_STATUS.values()
|
2015-08-17 11:05:49 +00:00
|
|
|
if verisure.SHOW_THERMOMETERS and
|
|
|
|
hasattr(value, 'temperature') and value.temperature
|
2015-08-12 11:00:47 +00:00
|
|
|
])
|
2015-08-11 07:28:07 +00:00
|
|
|
|
2015-08-12 11:00:47 +00:00
|
|
|
sensors.extend([
|
2015-08-17 11:05:49 +00:00
|
|
|
VerisureHygrometer(value)
|
2015-12-25 19:16:51 +00:00
|
|
|
for value in verisure.CLIMATE_STATUS.values()
|
2015-08-17 11:05:49 +00:00
|
|
|
if verisure.SHOW_HYGROMETERS and
|
|
|
|
hasattr(value, 'humidity') and value.humidity
|
|
|
|
])
|
|
|
|
|
2016-02-12 19:52:02 +00:00
|
|
|
sensors.extend([
|
|
|
|
VerisureMouseDetection(value)
|
|
|
|
for value in verisure.MOUSEDETECTION_STATUS.values()
|
|
|
|
if verisure.SHOW_MOUSEDETECTION and
|
|
|
|
hasattr(value, 'amountText') and value.amountText
|
|
|
|
])
|
|
|
|
|
2015-08-11 07:28:07 +00:00
|
|
|
add_devices(sensors)
|
|
|
|
|
|
|
|
|
2015-08-17 11:05:49 +00:00
|
|
|
class VerisureThermometer(Entity):
|
|
|
|
""" represents a Verisure thermometer within home assistant. """
|
2015-08-11 07:28:07 +00:00
|
|
|
|
|
|
|
def __init__(self, climate_status):
|
2015-08-12 11:00:47 +00:00
|
|
|
self._id = climate_status.id
|
|
|
|
|
2015-08-11 07:28:07 +00:00
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
""" Returns the name of the device. """
|
2015-08-17 11:05:49 +00:00
|
|
|
return '{} {}'.format(
|
2015-12-25 19:16:51 +00:00
|
|
|
verisure.CLIMATE_STATUS[self._id].location,
|
2015-08-17 11:05:49 +00:00
|
|
|
"Temperature")
|
2015-08-11 07:28:07 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
|
|
|
""" Returns the state of the device. """
|
2015-08-12 11:00:47 +00:00
|
|
|
# remove ° character
|
2015-12-25 19:16:51 +00:00
|
|
|
return verisure.CLIMATE_STATUS[self._id].temperature[:-1]
|
2015-08-12 11:00:47 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def unit_of_measurement(self):
|
|
|
|
""" Unit of measurement of this entity """
|
|
|
|
return TEMP_CELCIUS # can verisure report in fahrenheit?
|
|
|
|
|
|
|
|
def update(self):
|
2016-01-18 01:50:20 +00:00
|
|
|
""" update sensor """
|
2015-12-25 19:16:51 +00:00
|
|
|
verisure.update_climate()
|
2015-08-17 11:05:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
class VerisureHygrometer(Entity):
|
|
|
|
""" represents a Verisure hygrometer within home assistant. """
|
|
|
|
|
|
|
|
def __init__(self, climate_status):
|
|
|
|
self._id = climate_status.id
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
""" Returns the name of the device. """
|
|
|
|
return '{} {}'.format(
|
2015-12-25 19:16:51 +00:00
|
|
|
verisure.CLIMATE_STATUS[self._id].location,
|
2015-08-17 11:05:49 +00:00
|
|
|
"Humidity")
|
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
|
|
|
""" Returns the state of the device. """
|
|
|
|
# remove % character
|
2015-12-25 19:16:51 +00:00
|
|
|
return verisure.CLIMATE_STATUS[self._id].humidity[:-1]
|
2015-08-17 11:05:49 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def unit_of_measurement(self):
|
|
|
|
""" Unit of measurement of this entity """
|
|
|
|
return "%"
|
|
|
|
|
|
|
|
def update(self):
|
2016-01-18 01:50:20 +00:00
|
|
|
""" update sensor """
|
2015-12-25 19:16:51 +00:00
|
|
|
verisure.update_climate()
|
2016-02-12 19:52:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
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 """
|
2016-02-13 08:05:18 +00:00
|
|
|
return "Mice"
|
2016-02-12 19:52:02 +00:00
|
|
|
|
|
|
|
def update(self):
|
|
|
|
""" update sensor """
|
|
|
|
verisure.update_mousedetection()
|