hass-core/homeassistant/components/binary_sensor/nest.py

57 lines
1.9 KiB
Python
Raw Normal View History

2016-01-14 10:48:24 -07:00
"""
2016-01-27 09:00:01 +01:00
homeassistant.components.binary_sensor.nest
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2016-01-14 10:48:24 -07:00
Support for Nest Thermostat Binary Sensors.
For more details about this platform, please refer to the documentation at
2016-01-27 09:00:01 +01:00
https://home-assistant.io/components/binary_sensor.nest/
2016-01-14 10:48:24 -07:00
"""
import logging
import socket
import homeassistant.components.nest as nest
2016-01-14 14:17:28 -07:00
from homeassistant.components.sensor.nest import NestSensor
from homeassistant.components.binary_sensor import BinarySensorDevice
2016-01-14 10:48:24 -07:00
DEPENDENCIES = ['nest']
2016-01-14 10:48:24 -07:00
BINARY_TYPES = ['fan',
'hvac_ac_state',
'hvac_aux_heater_state',
'hvac_heater_state',
2016-01-14 10:48:24 -07:00
'hvac_heat_x2_state',
'hvac_heat_x3_state',
'hvac_alt_heat_state',
'hvac_alt_heat_x2_state',
'hvac_emer_heat_state',
'online']
2016-01-14 14:19:35 -07:00
2016-01-14 10:48:24 -07:00
def setup_platform(hass, config, add_devices, discovery_info=None):
2016-01-27 09:00:01 +01:00
""" Setup Nest binary sensors. """
2016-01-14 14:17:28 -07:00
2016-01-14 10:48:24 -07:00
logger = logging.getLogger(__name__)
try:
for structure in nest.NEST.structures:
for device in structure.devices:
for variable in config['monitored_conditions']:
if variable in BINARY_TYPES:
2016-01-14 14:19:35 -07:00
add_devices([NestBinarySensor(structure,
2016-01-14 14:17:28 -07:00
device,
variable)])
2016-01-14 10:48:24 -07:00
else:
2016-01-14 14:17:28 -07:00
logger.error('Nest sensor type: "%s" does not exist',
variable)
2016-01-14 10:48:24 -07:00
except socket.error:
logger.error(
"Connection error logging into the nest web service."
)
2016-01-14 14:19:35 -07:00
2016-01-16 12:52:22 -07:00
class NestBinarySensor(NestSensor, BinarySensorDevice):
2016-01-27 09:00:01 +01:00
""" Represents a Nest binary sensor. """
2016-01-14 10:48:24 -07:00
@property
2016-01-14 14:17:28 -07:00
def is_on(self):
2016-01-27 09:00:01 +01:00
""" True if the binary sensor is on. """
2016-01-14 14:17:28 -07:00
return bool(getattr(self.device, self.variable))