binary occupancy sensor (#2869)

This commit is contained in:
Nolan Gilley 2016-08-19 03:11:56 -04:00 committed by Paulus Schoutsen
parent bafc9413a3
commit 2a563e1604
3 changed files with 75 additions and 7 deletions

View file

@ -0,0 +1,72 @@
"""
Support for Ecobee sensors.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.ecobee/
"""
from homeassistant.components import ecobee
from homeassistant.components.binary_sensor import BinarySensorDevice
DEPENDENCIES = ['ecobee']
ECOBEE_CONFIG_FILE = 'ecobee.conf'
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup 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'] != 'occupancy':
continue
dev.append(EcobeeBinarySensor(sensor['name'], index))
add_devices(dev)
class EcobeeBinarySensor(BinarySensorDevice):
"""Representation of an Ecobee sensor."""
def __init__(self, sensor_name, sensor_index):
"""Initialize the sensor."""
self._name = sensor_name + ' Occupancy'
self.sensor_name = sensor_name
self.index = sensor_index
self._state = None
self._sensor_class = 'motion'
self.update()
@property
def name(self):
"""Return the name of the Ecobee sensor."""
return self._name.rstrip()
@property
def is_on(self):
"""Return the status of the sensor."""
return self._state == 'true'
@property
def unique_id(self):
"""Return the unique ID of this sensor."""
return "binary_sensor_ecobee_{}_{}".format(self._name, self.index)
@property
def sensor_class(self):
"""Return the class of this sensor, from SENSOR_CLASSES."""
return self._sensor_class
def update(self):
"""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'] == 'occupancy' and
self.sensor_name == sensor['name']):
self._state = item['value']

View file

@ -72,6 +72,7 @@ def setup_ecobee(hass, network, config):
discovery.load_platform(hass, 'thermostat', DOMAIN,
{'hold_temp': hold_temp}, config)
discovery.load_platform(hass, 'sensor', DOMAIN, {}, config)
discovery.load_platform(hass, 'binary_sensor', DOMAIN, {}, config)
# pylint: disable=too-few-public-methods

View file

@ -4,8 +4,6 @@ Support for Ecobee sensors.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.ecobee/
"""
import logging
from homeassistant.components import ecobee
from homeassistant.const import TEMP_FAHRENHEIT
from homeassistant.helpers.entity import Entity
@ -13,11 +11,9 @@ from homeassistant.helpers.entity import Entity
DEPENDENCIES = ['ecobee']
SENSOR_TYPES = {
'temperature': ['Temperature', TEMP_FAHRENHEIT],
'humidity': ['Humidity', '%'],
'occupancy': ['Occupancy', None]
'humidity': ['Humidity', '%']
}
_LOGGER = logging.getLogger(__name__)
ECOBEE_CONFIG_FILE = 'ecobee.conf'
@ -30,8 +26,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
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'):
if item['type'] not in ('temperature', 'humidity'):
continue
dev.append(EcobeeSensor(sensor['name'], item['type'], index))