hass-core/homeassistant/components/sensor/verisure.py

133 lines
3.5 KiB
Python
Raw Normal View History

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
])
2015-08-11 09:28:07 +02:00
add_devices(sensors)
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."""
return '{} {}'.format(
2016-02-27 21:50:19 +01:00
hub.climate_status[self._id].location,
"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()
class VerisureHygrometer(Entity):
2016-02-23 06:21:49 +01:00
"""Represents a Verisure hygrometer."""
2016-02-27 21:50:19 +01:00
def __init__(self, device_id):
self._id = device_id
@property
def name(self):
2016-02-23 06:21:49 +01:00
"""Returns the name of the sensor."""
return '{} {}'.format(
2016-02-27 21:50:19 +01:00
hub.climate_status[self._id].location,
"Humidity")
@property
def state(self):
2016-02-23 06:21:49 +01:00
"""Returns the state of the sensor."""
# remove % character
2016-02-27 21:50:19 +01:00
return hub.climate_status[self._id].humidity[:-1]
@property
def unit_of_measurement(self):
2016-02-23 06:21:49 +01:00
"""Unit of measurement of this sensor."""
return "%"
def update(self):
2016-02-27 21:50:19 +01:00
"""Update the sensor."""
hub.update_climate()
class VerisureMouseDetection(Entity):
2016-02-23 06:21:49 +01:00
""" Represents a Verisure mouse detector."""
2016-02-27 21:50:19 +01:00
def __init__(self, device_id):
self._id = device_id
@property
def name(self):
2016-02-23 06:21:49 +01:00
"""Returns the name of the sensor."""
return '{} {}'.format(
2016-02-27 21:50:19 +01:00
hub.mouse_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-27 21:50:19 +01:00
return hub.mouse_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"
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()