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
|
|
|
|
|
2016-02-27 20:50:19 +00:00
|
|
|
from homeassistant.components.verisure import HUB as hub
|
2015-08-12 11:00:47 +00:00
|
|
|
from homeassistant.const import TEMP_CELCIUS
|
2016-02-19 05:27:50 +00:00
|
|
|
from homeassistant.helpers.entity import Entity
|
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):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Setup the Verisure platform."""
|
2015-08-12 11:00:47 +00:00
|
|
|
sensors = []
|
2015-08-11 07:28:07 +00:00
|
|
|
|
2016-03-08 13:10:47 +00:00
|
|
|
if int(hub.config.get('thermometers', '1')):
|
2016-02-27 20:50:19 +00:00
|
|
|
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 19:52:02 +00:00
|
|
|
|
2015-08-11 07:28:07 +00:00
|
|
|
add_devices(sensors)
|
|
|
|
|
|
|
|
|
2015-08-17 11:05:49 +00:00
|
|
|
class VerisureThermometer(Entity):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Representation of a Verisure thermometer."""
|
2015-08-11 07:28:07 +00:00
|
|
|
|
2016-02-27 20:50:19 +00:00
|
|
|
def __init__(self, device_id):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Initialize the sensor."""
|
2016-02-27 20:50:19 +00:00
|
|
|
self._id = device_id
|
2015-08-12 11:00:47 +00:00
|
|
|
|
2015-08-11 07:28:07 +00:00
|
|
|
@property
|
|
|
|
def name(self):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Return the name of the device."""
|
2015-08-17 11:05:49 +00:00
|
|
|
return '{} {}'.format(
|
2016-02-27 20:50:19 +00:00
|
|
|
hub.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):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Return the state of the device."""
|
|
|
|
# Remove ° character
|
2016-02-27 20:50:19 +00:00
|
|
|
return hub.climate_status[self._id].temperature[:-1]
|
2015-08-12 11:00:47 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def unit_of_measurement(self):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Return the unit of measurement of this entity."""
|
|
|
|
return TEMP_CELCIUS
|
2015-08-12 11:00:47 +00:00
|
|
|
|
|
|
|
def update(self):
|
2016-02-23 05:21:49 +00:00
|
|
|
"""Update the sensor."""
|
2016-02-27 20:50:19 +00:00
|
|
|
hub.update_climate()
|
2015-08-17 11:05:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
class VerisureHygrometer(Entity):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Representation of a Verisure hygrometer."""
|
2015-08-17 11:05:49 +00:00
|
|
|
|
2016-02-27 20:50:19 +00:00
|
|
|
def __init__(self, device_id):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Initialize the sensor."""
|
2016-02-27 20:50:19 +00:00
|
|
|
self._id = device_id
|
2015-08-17 11:05:49 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Return the name of the sensor."""
|
2015-08-17 11:05:49 +00:00
|
|
|
return '{} {}'.format(
|
2016-02-27 20:50:19 +00:00
|
|
|
hub.climate_status[self._id].location,
|
2015-08-17 11:05:49 +00:00
|
|
|
"Humidity")
|
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Return the state of the sensor."""
|
2015-08-17 11:05:49 +00:00
|
|
|
# remove % character
|
2016-02-27 20:50:19 +00:00
|
|
|
return hub.climate_status[self._id].humidity[:-1]
|
2015-08-17 11:05:49 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def unit_of_measurement(self):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Return the unit of measurement of this sensor."""
|
2015-08-17 11:05:49 +00:00
|
|
|
return "%"
|
|
|
|
|
|
|
|
def update(self):
|
2016-02-27 20:50:19 +00:00
|
|
|
"""Update the sensor."""
|
|
|
|
hub.update_climate()
|
2016-02-12 19:52:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
class VerisureMouseDetection(Entity):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Representation of a Verisure mouse detector."""
|
2016-02-12 19:52:02 +00:00
|
|
|
|
2016-02-27 20:50:19 +00:00
|
|
|
def __init__(self, device_id):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Initialize the sensor."""
|
2016-02-27 20:50:19 +00:00
|
|
|
self._id = device_id
|
2016-02-12 19:52:02 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Return the name of the sensor."""
|
2016-02-12 19:52:02 +00:00
|
|
|
return '{} {}'.format(
|
2016-02-27 20:50:19 +00:00
|
|
|
hub.mouse_status[self._id].location,
|
2016-02-12 19:52:02 +00:00
|
|
|
"Mouse")
|
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Return the state of the sensor."""
|
2016-02-27 20:50:19 +00:00
|
|
|
return hub.mouse_status[self._id].count
|
2016-02-12 19:52:02 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def unit_of_measurement(self):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Return the unit of measurement of this sensor."""
|
2016-02-13 08:05:18 +00:00
|
|
|
return "Mice"
|
2016-02-12 19:52:02 +00:00
|
|
|
|
|
|
|
def update(self):
|
2016-02-23 05:21:49 +00:00
|
|
|
"""Update the sensor."""
|
2016-02-27 20:50:19 +00:00
|
|
|
hub.update_mousedetection()
|