2015-11-17 19:14:29 -05:00
|
|
|
"""
|
2016-02-23 06:21:49 +01:00
|
|
|
Support for Ecobee sensors.
|
2015-11-23 11:15:19 -05:00
|
|
|
|
2016-02-03 15:13:53 +01:00
|
|
|
For more details about this platform, please refer to the documentation at
|
|
|
|
https://home-assistant.io/components/sensor.ecobee/
|
2015-11-17 19:14:29 -05:00
|
|
|
"""
|
2015-11-24 09:29:33 -05:00
|
|
|
from homeassistant.components import ecobee
|
2015-11-23 11:15:19 -05:00
|
|
|
from homeassistant.const import TEMP_FAHRENHEIT
|
2016-02-18 21:27:50 -08:00
|
|
|
from homeassistant.helpers.entity import Entity
|
2015-11-17 19:14:29 -05:00
|
|
|
|
2015-11-23 11:15:19 -05:00
|
|
|
DEPENDENCIES = ['ecobee']
|
2015-11-17 19:14:29 -05:00
|
|
|
SENSOR_TYPES = {
|
2015-11-23 11:15:19 -05:00
|
|
|
'temperature': ['Temperature', TEMP_FAHRENHEIT],
|
2016-08-19 03:11:56 -04:00
|
|
|
'humidity': ['Humidity', '%']
|
2015-11-17 19:14:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
ECOBEE_CONFIG_FILE = 'ecobee.conf'
|
|
|
|
|
|
|
|
|
|
|
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
2016-03-08 16:46:34 +01:00
|
|
|
"""Setup the Ecobee sensors."""
|
2015-11-23 11:15:19 -05:00
|
|
|
if discovery_info is None:
|
|
|
|
return
|
2015-12-02 16:22:25 -05:00
|
|
|
data = ecobee.NETWORK
|
2015-12-02 17:42:53 -05:00
|
|
|
dev = list()
|
2015-12-02 16:22:25 -05:00
|
|
|
for index in range(len(data.ecobee.thermostats)):
|
|
|
|
for sensor in data.ecobee.get_remote_sensors(index):
|
|
|
|
for item in sensor['capability']:
|
2016-08-19 03:11:56 -04:00
|
|
|
if item['type'] not in ('temperature', 'humidity'):
|
2015-12-03 08:57:28 -05:00
|
|
|
continue
|
|
|
|
|
|
|
|
dev.append(EcobeeSensor(sensor['name'], item['type'], index))
|
2015-11-17 19:14:29 -05:00
|
|
|
|
|
|
|
add_devices(dev)
|
|
|
|
|
|
|
|
|
|
|
|
class EcobeeSensor(Entity):
|
2016-03-08 16:46:34 +01:00
|
|
|
"""Representation of an Ecobee sensor."""
|
2015-11-17 19:14:29 -05:00
|
|
|
|
2015-12-02 16:22:25 -05:00
|
|
|
def __init__(self, sensor_name, sensor_type, sensor_index):
|
2016-03-08 16:46:34 +01:00
|
|
|
"""Initialize the sensor."""
|
2015-11-17 19:14:29 -05:00
|
|
|
self._name = sensor_name + ' ' + SENSOR_TYPES[sensor_type][0]
|
|
|
|
self.sensor_name = sensor_name
|
|
|
|
self.type = sensor_type
|
2015-12-02 16:22:25 -05:00
|
|
|
self.index = sensor_index
|
2015-11-17 19:14:29 -05:00
|
|
|
self._state = None
|
|
|
|
self._unit_of_measurement = SENSOR_TYPES[sensor_type][1]
|
|
|
|
self.update()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
2016-03-08 16:46:34 +01:00
|
|
|
"""Return the name of the Ecobee sensor."""
|
2015-11-17 19:14:29 -05:00
|
|
|
return self._name.rstrip()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
2016-03-08 16:46:34 +01:00
|
|
|
"""Return the state of the sensor."""
|
2015-11-17 19:14:29 -05:00
|
|
|
return self._state
|
|
|
|
|
2016-02-08 20:39:09 -08:00
|
|
|
@property
|
|
|
|
def unique_id(self):
|
2016-03-08 16:46:34 +01:00
|
|
|
"""Return the unique ID of this sensor."""
|
2016-02-12 17:24:00 -05:00
|
|
|
return "sensor_ecobee_{}_{}".format(self._name, self.index)
|
2016-02-08 20:39:09 -08:00
|
|
|
|
2015-11-17 19:14:29 -05:00
|
|
|
@property
|
|
|
|
def unit_of_measurement(self):
|
2016-03-08 16:46:34 +01:00
|
|
|
"""Return the unit of measurement this sensor expresses itself in."""
|
2015-11-17 19:14:29 -05:00
|
|
|
return self._unit_of_measurement
|
|
|
|
|
|
|
|
def update(self):
|
2016-02-23 06:21:49 +01:00
|
|
|
"""Get the latest state of the sensor."""
|
2015-12-02 16:22:25 -05:00
|
|
|
data = ecobee.NETWORK
|
2015-12-02 17:42:53 -05:00
|
|
|
data.update()
|
2015-12-02 16:22:25 -05:00
|
|
|
for sensor in data.ecobee.get_remote_sensors(self.index):
|
|
|
|
for item in sensor['capability']:
|
2016-05-06 21:50:32 -04:00
|
|
|
if (item['type'] == self.type and
|
2015-12-02 17:42:53 -05:00
|
|
|
self.sensor_name == sensor['name']):
|
2016-05-06 21:50:32 -04:00
|
|
|
if (self.type == 'temperature' and
|
|
|
|
item['value'] != 'unknown'):
|
|
|
|
self._state = float(item['value']) / 10
|
|
|
|
else:
|
|
|
|
self._state = item['value']
|