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

132 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
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([
VerisureThermometer(value)
2015-12-25 20:16:51 +01:00
for value in verisure.CLIMATE_STATUS.values()
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([
VerisureHygrometer(value)
2015-12-25 20:16:51 +01:00
for value in verisure.CLIMATE_STATUS.values()
if verisure.SHOW_HYGROMETERS and
hasattr(value, 'humidity') and value.humidity
])
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)
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."""
return '{} {}'.format(
2015-12-25 20:16:51 +01:00
verisure.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
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()
class VerisureHygrometer(Entity):
2016-02-23 06:21:49 +01:00
"""Represents a Verisure hygrometer."""
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."""
return '{} {}'.format(
2015-12-25 20:16:51 +01:00
verisure.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
2015-12-25 20:16:51 +01:00
return verisure.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-23 06:21:49 +01:00
"""Update sensor the sensor."""
2015-12-25 20:16:51 +01:00
verisure.update_climate()
class VerisureMouseDetection(Entity):
2016-02-23 06:21:49 +01:00
""" Represents a Verisure mouse detector."""
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."""
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."""
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"
def update(self):
2016-02-23 06:21:49 +01:00
"""Update the sensor."""
verisure.update_mousedetection()