binary occupancy sensor (#2869)
This commit is contained in:
parent
bafc9413a3
commit
2a563e1604
3 changed files with 75 additions and 7 deletions
72
homeassistant/components/binary_sensor/ecobee.py
Normal file
72
homeassistant/components/binary_sensor/ecobee.py
Normal 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']
|
|
@ -72,6 +72,7 @@ def setup_ecobee(hass, network, config):
|
||||||
discovery.load_platform(hass, 'thermostat', DOMAIN,
|
discovery.load_platform(hass, 'thermostat', DOMAIN,
|
||||||
{'hold_temp': hold_temp}, config)
|
{'hold_temp': hold_temp}, config)
|
||||||
discovery.load_platform(hass, 'sensor', DOMAIN, {}, config)
|
discovery.load_platform(hass, 'sensor', DOMAIN, {}, config)
|
||||||
|
discovery.load_platform(hass, 'binary_sensor', DOMAIN, {}, config)
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
|
|
|
@ -4,8 +4,6 @@ Support for Ecobee sensors.
|
||||||
For more details about this platform, please refer to the documentation at
|
For more details about this platform, please refer to the documentation at
|
||||||
https://home-assistant.io/components/sensor.ecobee/
|
https://home-assistant.io/components/sensor.ecobee/
|
||||||
"""
|
"""
|
||||||
import logging
|
|
||||||
|
|
||||||
from homeassistant.components import ecobee
|
from homeassistant.components import ecobee
|
||||||
from homeassistant.const import TEMP_FAHRENHEIT
|
from homeassistant.const import TEMP_FAHRENHEIT
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
@ -13,11 +11,9 @@ from homeassistant.helpers.entity import Entity
|
||||||
DEPENDENCIES = ['ecobee']
|
DEPENDENCIES = ['ecobee']
|
||||||
SENSOR_TYPES = {
|
SENSOR_TYPES = {
|
||||||
'temperature': ['Temperature', TEMP_FAHRENHEIT],
|
'temperature': ['Temperature', TEMP_FAHRENHEIT],
|
||||||
'humidity': ['Humidity', '%'],
|
'humidity': ['Humidity', '%']
|
||||||
'occupancy': ['Occupancy', None]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
|
||||||
ECOBEE_CONFIG_FILE = 'ecobee.conf'
|
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 index in range(len(data.ecobee.thermostats)):
|
||||||
for sensor in data.ecobee.get_remote_sensors(index):
|
for sensor in data.ecobee.get_remote_sensors(index):
|
||||||
for item in sensor['capability']:
|
for item in sensor['capability']:
|
||||||
if item['type'] not in ('temperature',
|
if item['type'] not in ('temperature', 'humidity'):
|
||||||
'humidity', 'occupancy'):
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
dev.append(EcobeeSensor(sensor['name'], item['type'], index))
|
dev.append(EcobeeSensor(sensor['name'], item['type'], index))
|
||||||
|
|
Loading…
Add table
Reference in a new issue