core/homeassistant/components/sensor/ecobee.py

97 lines
3.1 KiB
Python
Raw Normal View History

"""
homeassistant.components.sensor.ecobee
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2016-02-03 14:13:53 +00:00
Sensor platform for Ecobee sensors.
2016-02-03 14:13:53 +00:00
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.ecobee/
"""
2015-11-29 21:49:05 +00:00
import logging
2015-11-24 14:29:33 +00:00
from homeassistant.components import ecobee
from homeassistant.const import TEMP_FAHRENHEIT
2016-02-19 05:27:50 +00:00
from homeassistant.helpers.entity import Entity
DEPENDENCIES = ['ecobee']
SENSOR_TYPES = {
'temperature': ['Temperature', TEMP_FAHRENHEIT],
'humidity': ['Humidity', '%'],
2016-01-18 01:50:20 +00:00
'occupancy': ['Occupancy', None]
}
_LOGGER = logging.getLogger(__name__)
ECOBEE_CONFIG_FILE = 'ecobee.conf'
def setup_platform(hass, config, add_devices, discovery_info=None):
2016-02-03 14:13:53 +00:00
""" Sets up the Ecobee sensors. """
if discovery_info is None:
return
data = ecobee.NETWORK
dev = list()
for index in range(len(data.ecobee.thermostats)):
for sensor in data.ecobee.get_remote_sensors(index):
for item in sensor['capability']:
if item['type'] not in ('temperature',
'humidity', 'occupancy'):
continue
dev.append(EcobeeSensor(sensor['name'], item['type'], index))
add_devices(dev)
class EcobeeSensor(Entity):
2016-02-03 14:13:53 +00:00
""" An Ecobee sensor. """
def __init__(self, sensor_name, sensor_type, sensor_index):
self._name = sensor_name + ' ' + SENSOR_TYPES[sensor_type][0]
self.sensor_name = sensor_name
self.type = sensor_type
self.index = sensor_index
self._state = None
self._unit_of_measurement = SENSOR_TYPES[sensor_type][1]
self.update()
@property
def name(self):
2016-02-03 14:13:53 +00:00
""" Returns the name of the Ecobee sensor.. """
return self._name.rstrip()
@property
def state(self):
""" Returns the state of the device. """
return self._state
2016-02-09 04:39:09 +00:00
@property
def unique_id(self):
"""Unique id of this sensor."""
2016-02-12 22:24:00 +00:00
return "sensor_ecobee_{}_{}".format(self._name, self.index)
2016-02-09 04:39:09 +00:00
@property
def unit_of_measurement(self):
2016-02-03 14:13:53 +00:00
""" Unit of measurement this sensor expresses itself in. """
return self._unit_of_measurement
def update(self):
2016-02-03 14:13:53 +00:00
""" Get the latest state of the sensor. """
data = ecobee.NETWORK
data.update()
for sensor in data.ecobee.get_remote_sensors(self.index):
for item in sensor['capability']:
if (
item['type'] == self.type and
self.type == 'temperature' and
self.sensor_name == sensor['name']):
self._state = float(item['value']) / 10
elif (
item['type'] == self.type and
self.type == 'humidity' and
self.sensor_name == sensor['name']):
self._state = item['value']
elif (
item['type'] == self.type and
self.type == 'occupancy' and
self.sensor_name == sensor['name']):
self._state = item['value']