core/homeassistant/components/sensor/verisure.py

136 lines
3.7 KiB
Python
Raw Normal View History

2015-08-11 07:28:07 +00:00
"""
homeassistant.components.sensor.verisure
2015-10-20 19:31:25 +00:00
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
import homeassistant.components.verisure as verisure
from homeassistant.helpers.entity import Entity
2015-08-12 11:00:47 +00:00
from homeassistant.const import TEMP_CELCIUS
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):
""" Sets up the Verisure platform. """
if not verisure.MY_PAGES:
_LOGGER.error('A connection has not been made to Verisure mypages.')
return False
2015-08-12 11:00:47 +00:00
sensors = []
2015-08-11 07:28:07 +00:00
sensors.extend([
VerisureThermometer(value)
2015-12-25 19:16:51 +00:00
for value in verisure.CLIMATE_STATUS.values()
if verisure.SHOW_THERMOMETERS and
hasattr(value, 'temperature') and value.temperature
2015-08-12 11:00:47 +00:00
])
2015-08-11 07:28:07 +00:00
2015-08-12 11:00:47 +00:00
sensors.extend([
VerisureHygrometer(value)
2015-12-25 19:16:51 +00: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 07:28:07 +00:00
add_devices(sensors)
class VerisureThermometer(Entity):
""" represents a Verisure thermometer within home assistant. """
2015-08-11 07:28:07 +00:00
def __init__(self, climate_status):
2015-08-12 11:00:47 +00:00
self._id = climate_status.id
2015-08-11 07:28:07 +00:00
@property
def name(self):
""" Returns the name of the device. """
return '{} {}'.format(
2015-12-25 19:16:51 +00:00
verisure.CLIMATE_STATUS[self._id].location,
"Temperature")
2015-08-11 07:28:07 +00:00
@property
def state(self):
""" Returns the state of the device. """
2015-08-12 11:00:47 +00:00
# remove ° character
2015-12-25 19:16:51 +00:00
return verisure.CLIMATE_STATUS[self._id].temperature[:-1]
2015-08-12 11:00:47 +00:00
@property
def unit_of_measurement(self):
""" Unit of measurement of this entity """
return TEMP_CELCIUS # can verisure report in fahrenheit?
def update(self):
2016-01-18 01:50:20 +00:00
""" update sensor """
2015-12-25 19:16:51 +00:00
verisure.update_climate()
class VerisureHygrometer(Entity):
""" represents a Verisure hygrometer within home assistant. """
def __init__(self, climate_status):
self._id = climate_status.id
@property
def name(self):
""" Returns the name of the device. """
return '{} {}'.format(
2015-12-25 19:16:51 +00:00
verisure.CLIMATE_STATUS[self._id].location,
"Humidity")
@property
def state(self):
""" Returns the state of the device. """
# remove % character
2015-12-25 19:16:51 +00:00
return verisure.CLIMATE_STATUS[self._id].humidity[:-1]
@property
def unit_of_measurement(self):
""" Unit of measurement of this entity """
return "%"
def update(self):
2016-01-18 01:50:20 +00:00
""" update sensor """
2015-12-25 19:16:51 +00:00
verisure.update_climate()
class VerisureMouseDetection(Entity):
""" represents a Verisure mousedetector within home assistant. """
def __init__(self, mousedetection_status):
self._id = mousedetection_status.deviceLabel
@property
def name(self):
""" Returns the name of the device. """
return '{} {}'.format(
verisure.MOUSEDETECTION_STATUS[self._id].location,
"Mouse")
@property
def state(self):
""" Returns the state of the device. """
return verisure.MOUSEDETECTION_STATUS[self._id].count
@property
def unit_of_measurement(self):
""" Unit of measurement of this entity """
2016-02-13 08:05:18 +00:00
return "Mice"
def update(self):
""" update sensor """
verisure.update_mousedetection()