2019-02-13 20:21:14 +00:00
|
|
|
"""Support for Ecobee sensors."""
|
2015-11-24 14:29:33 +00:00
|
|
|
from homeassistant.components import ecobee
|
2018-05-05 13:37:40 +00:00
|
|
|
from homeassistant.const import (
|
|
|
|
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_TEMPERATURE, TEMP_FAHRENHEIT)
|
2016-02-19 05:27:50 +00:00
|
|
|
from homeassistant.helpers.entity import Entity
|
2015-11-18 00:14:29 +00:00
|
|
|
|
2015-11-23 16:15:19 +00:00
|
|
|
DEPENDENCIES = ['ecobee']
|
2017-06-05 19:28:13 +00:00
|
|
|
|
|
|
|
ECOBEE_CONFIG_FILE = 'ecobee.conf'
|
|
|
|
|
2015-11-18 00:14:29 +00:00
|
|
|
SENSOR_TYPES = {
|
2015-11-23 16:15:19 +00:00
|
|
|
'temperature': ['Temperature', TEMP_FAHRENHEIT],
|
2016-08-19 07:11:56 +00:00
|
|
|
'humidity': ['Humidity', '%']
|
2015-11-18 00:14:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Set up the Ecobee sensors."""
|
2015-11-23 16:15:19 +00:00
|
|
|
if discovery_info is None:
|
|
|
|
return
|
2015-12-02 21:22:25 +00:00
|
|
|
data = ecobee.NETWORK
|
2015-12-02 22:42:53 +00:00
|
|
|
dev = list()
|
2015-12-02 21:22:25 +00: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 07:11:56 +00:00
|
|
|
if item['type'] not in ('temperature', 'humidity'):
|
2015-12-03 13:57:28 +00:00
|
|
|
continue
|
|
|
|
|
|
|
|
dev.append(EcobeeSensor(sensor['name'], item['type'], index))
|
2015-11-18 00:14:29 +00:00
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
add_entities(dev, True)
|
2015-11-18 00:14:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EcobeeSensor(Entity):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Representation of an Ecobee sensor."""
|
2015-11-18 00:14:29 +00:00
|
|
|
|
2015-12-02 21:22:25 +00:00
|
|
|
def __init__(self, sensor_name, sensor_type, sensor_index):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Initialize the sensor."""
|
2017-06-05 19:28:13 +00:00
|
|
|
self._name = '{} {}'.format(sensor_name, SENSOR_TYPES[sensor_type][0])
|
2015-11-18 00:14:29 +00:00
|
|
|
self.sensor_name = sensor_name
|
|
|
|
self.type = sensor_type
|
2015-12-02 21:22:25 +00:00
|
|
|
self.index = sensor_index
|
2015-11-18 00:14:29 +00:00
|
|
|
self._state = None
|
|
|
|
self._unit_of_measurement = SENSOR_TYPES[sensor_type][1]
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Return the name of the Ecobee sensor."""
|
2018-01-30 09:39:39 +00:00
|
|
|
return self._name
|
2015-11-18 00:14:29 +00:00
|
|
|
|
2018-04-20 13:38:27 +00:00
|
|
|
@property
|
|
|
|
def device_class(self):
|
|
|
|
"""Return the device class of the sensor."""
|
2018-05-05 13:37:40 +00:00
|
|
|
if self.type in (DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_TEMPERATURE):
|
2018-04-20 13:38:27 +00:00
|
|
|
return self.type
|
|
|
|
return None
|
|
|
|
|
2015-11-18 00:14:29 +00:00
|
|
|
@property
|
|
|
|
def state(self):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Return the state of the sensor."""
|
2015-11-18 00:14:29 +00:00
|
|
|
return self._state
|
|
|
|
|
|
|
|
@property
|
|
|
|
def unit_of_measurement(self):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Return the unit of measurement this sensor expresses itself in."""
|
2015-11-18 00:14:29 +00:00
|
|
|
return self._unit_of_measurement
|
|
|
|
|
|
|
|
def update(self):
|
2016-02-23 05:21:49 +00:00
|
|
|
"""Get the latest state of the sensor."""
|
2015-12-02 21:22:25 +00:00
|
|
|
data = ecobee.NETWORK
|
2015-12-02 22:42:53 +00:00
|
|
|
data.update()
|
2015-12-02 21:22:25 +00:00
|
|
|
for sensor in data.ecobee.get_remote_sensors(self.index):
|
|
|
|
for item in sensor['capability']:
|
2016-05-07 01:50:32 +00:00
|
|
|
if (item['type'] == self.type and
|
2015-12-02 22:42:53 +00:00
|
|
|
self.sensor_name == sensor['name']):
|
2016-05-07 01:50:32 +00:00
|
|
|
if (self.type == 'temperature' and
|
|
|
|
item['value'] != 'unknown'):
|
|
|
|
self._state = float(item['value']) / 10
|
|
|
|
else:
|
|
|
|
self._state = item['value']
|