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