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
|
|
|
|
|
2016-02-27 21:50:19 +01:00
|
|
|
from homeassistant.components.verisure import HUB as hub
|
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
|
|
|
|
2015-08-12 13:00:47 +02:00
|
|
|
sensors = []
|
2015-08-11 09:28:07 +02:00
|
|
|
|
2016-02-27 21:50:19 +01:00
|
|
|
if int(hub.config.get('temperature', '1')):
|
|
|
|
hub.update_climate()
|
|
|
|
sensors.extend([
|
|
|
|
VerisureThermometer(value.id)
|
|
|
|
for value in hub.climate_status.values()
|
|
|
|
if hasattr(value, 'temperature') and value.temperature
|
|
|
|
])
|
|
|
|
|
|
|
|
if int(hub.config.get('hygrometers', '1')):
|
|
|
|
hub.update_climate()
|
|
|
|
sensors.extend([
|
|
|
|
VerisureHygrometer(value.id)
|
|
|
|
for value in hub.climate_status.values()
|
|
|
|
if hasattr(value, 'humidity') and value.humidity
|
|
|
|
])
|
|
|
|
|
|
|
|
if int(hub.config.get('mouse', '1')):
|
|
|
|
hub.update_mousedetection()
|
|
|
|
sensors.extend([
|
|
|
|
VerisureMouseDetection(value.deviceLabel)
|
|
|
|
for value in hub.mouse_status.values()
|
|
|
|
# is this if needed?
|
|
|
|
if hasattr(value, 'amountText') and value.amountText
|
|
|
|
])
|
2016-02-12 20:52:02 +01:00
|
|
|
|
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
|
|
|
|
2016-02-27 21:50:19 +01:00
|
|
|
def __init__(self, device_id):
|
|
|
|
self._id = device_id
|
2015-08-12 13:00:47 +02:00
|
|
|
|
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(
|
2016-02-27 21:50:19 +01:00
|
|
|
hub.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
|
2016-02-27 21:50:19 +01:00
|
|
|
return hub.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."""
|
2016-02-27 21:50:19 +01:00
|
|
|
hub.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
|
|
|
|
2016-02-27 21:50:19 +01:00
|
|
|
def __init__(self, device_id):
|
|
|
|
self._id = device_id
|
2015-08-17 13:05:49 +02:00
|
|
|
|
|
|
|
@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(
|
2016-02-27 21:50:19 +01:00
|
|
|
hub.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
|
2016-02-27 21:50:19 +01:00
|
|
|
return hub.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-27 21:50:19 +01:00
|
|
|
"""Update the sensor."""
|
|
|
|
hub.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
|
|
|
|
2016-02-27 21:50:19 +01:00
|
|
|
def __init__(self, device_id):
|
|
|
|
self._id = device_id
|
2016-02-12 20:52:02 +01:00
|
|
|
|
|
|
|
@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(
|
2016-02-27 21:50:19 +01:00
|
|
|
hub.mouse_status[self._id].location,
|
2016-02-12 20:52:02 +01:00
|
|
|
"Mouse")
|
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
2016-02-23 06:21:49 +01:00
|
|
|
"""Returns the state of the sensor."""
|
2016-02-27 21:50:19 +01:00
|
|
|
return hub.mouse_status[self._id].count
|
2016-02-12 20:52:02 +01:00
|
|
|
|
|
|
|
@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-27 21:50:19 +01:00
|
|
|
hub.update_mousedetection()
|