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

84 lines
2.2 KiB
Python
Raw Normal View History

2015-08-11 09:28:07 +02:00
"""
homeassistant.components.sensor.verisure
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Interfaces with Verisure sensors.
"""
import logging
import homeassistant.components.verisure as verisure
from homeassistant.helpers.entity import Entity
2015-08-12 13:00:47 +02:00
from homeassistant.const import TEMP_CELCIUS
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):
""" 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 13:00:47 +02:00
sensors = []
2015-08-11 09:28:07 +02:00
sensors.extend([
2015-08-12 13:00:47 +02:00
VerisureClimateDevice(value)
for value in verisure.get_climate_status().values()
])
2015-08-11 09:28:07 +02:00
2015-08-12 13:00:47 +02:00
sensors.extend([
VerisureAlarmDevice(value)
for value in verisure.get_alarm_status().values()
])
2015-08-11 09:28:07 +02:00
add_devices(sensors)
class VerisureClimateDevice(Entity):
""" represents a Verisure climate sensor within home assistant. """
def __init__(self, climate_status):
2015-08-12 13:00:47 +02:00
self._id = climate_status.id
self._device = verisure.MY_PAGES.DEVICE_CLIMATE
2015-08-11 09:28:07 +02:00
@property
def name(self):
""" Returns the name of the device. """
2015-08-12 13:00:47 +02:00
return verisure.STATUS[self._device][self._id].location
2015-08-11 09:28:07 +02:00
@property
def state(self):
""" Returns the state of the device. """
2015-08-12 13:00:47 +02:00
# remove ° character
return verisure.STATUS[self._device][self._id].temperature[:-1]
@property
def unit_of_measurement(self):
""" Unit of measurement of this entity """
return TEMP_CELCIUS # can verisure report in fahrenheit?
def update(self):
verisure.update()
2015-08-11 09:28:07 +02:00
class VerisureAlarmDevice(Entity):
2015-08-12 13:00:47 +02:00
""" represents a Verisure alarm status within home assistant. """
2015-08-11 09:28:07 +02:00
def __init__(self, alarm_status):
2015-08-12 13:00:47 +02:00
self._id = alarm_status.id
self._device = verisure.MY_PAGES.DEVICE_ALARM
2015-08-11 09:28:07 +02:00
@property
def name(self):
""" Returns the name of the device. """
2015-08-12 13:00:47 +02:00
return 'Alarm {}'.format(self._id)
2015-08-11 09:28:07 +02:00
@property
def state(self):
""" Returns the state of the device. """
2015-08-16 08:03:19 +02:00
return verisure.STATUS[self._device][self._id].label
2015-08-12 13:00:47 +02:00
def update(self):
verisure.update()