mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 04:50:05 +00:00
Black
This commit is contained in:
@@ -5,43 +5,38 @@ import logging
|
||||
from homeassistant.components.binary_sensor import BinarySensorDevice
|
||||
from homeassistant.const import CONF_MONITORED_CONDITIONS
|
||||
|
||||
from . import (
|
||||
CONF_BINARY_SENSORS, DATA_NEST, DATA_NEST_CONFIG, NestSensorDevice)
|
||||
from . import CONF_BINARY_SENSORS, DATA_NEST, DATA_NEST_CONFIG, NestSensorDevice
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
BINARY_TYPES = {'online': 'connectivity'}
|
||||
BINARY_TYPES = {"online": "connectivity"}
|
||||
|
||||
CLIMATE_BINARY_TYPES = {
|
||||
'fan': None,
|
||||
'is_using_emergency_heat': 'heat',
|
||||
'is_locked': None,
|
||||
'has_leaf': None,
|
||||
"fan": None,
|
||||
"is_using_emergency_heat": "heat",
|
||||
"is_locked": None,
|
||||
"has_leaf": None,
|
||||
}
|
||||
|
||||
CAMERA_BINARY_TYPES = {
|
||||
'motion_detected': 'motion',
|
||||
'sound_detected': 'sound',
|
||||
'person_detected': 'occupancy',
|
||||
"motion_detected": "motion",
|
||||
"sound_detected": "sound",
|
||||
"person_detected": "occupancy",
|
||||
}
|
||||
|
||||
STRUCTURE_BINARY_TYPES = {
|
||||
'away': None,
|
||||
}
|
||||
STRUCTURE_BINARY_TYPES = {"away": None}
|
||||
|
||||
STRUCTURE_BINARY_STATE_MAP = {
|
||||
'away': {'away': True, 'home': False},
|
||||
}
|
||||
STRUCTURE_BINARY_STATE_MAP = {"away": {"away": True, "home": False}}
|
||||
|
||||
_BINARY_TYPES_DEPRECATED = [
|
||||
'hvac_ac_state',
|
||||
'hvac_aux_heater_state',
|
||||
'hvac_heater_state',
|
||||
'hvac_heat_x2_state',
|
||||
'hvac_heat_x3_state',
|
||||
'hvac_alt_heat_state',
|
||||
'hvac_alt_heat_x2_state',
|
||||
'hvac_emer_heat_state',
|
||||
"hvac_ac_state",
|
||||
"hvac_aux_heater_state",
|
||||
"hvac_heater_state",
|
||||
"hvac_heat_x2_state",
|
||||
"hvac_heat_x3_state",
|
||||
"hvac_alt_heat_state",
|
||||
"hvac_alt_heat_x2_state",
|
||||
"hvac_emer_heat_state",
|
||||
]
|
||||
|
||||
_VALID_BINARY_SENSOR_TYPES = {
|
||||
@@ -63,8 +58,7 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
||||
"""Set up a Nest binary sensor based on a config entry."""
|
||||
nest = hass.data[DATA_NEST]
|
||||
|
||||
discovery_info = \
|
||||
hass.data.get(DATA_NEST_CONFIG, {}).get(CONF_BINARY_SENSORS, {})
|
||||
discovery_info = hass.data.get(DATA_NEST_CONFIG, {}).get(CONF_BINARY_SENSORS, {})
|
||||
|
||||
# Add all available binary sensors if no Nest binary sensor config is set
|
||||
if discovery_info == {}:
|
||||
@@ -74,37 +68,46 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
||||
|
||||
for variable in conditions:
|
||||
if variable in _BINARY_TYPES_DEPRECATED:
|
||||
wstr = (variable + " is no a longer supported "
|
||||
"monitored_conditions. See "
|
||||
"https://home-assistant.io/components/binary_sensor.nest/ "
|
||||
"for valid options.")
|
||||
wstr = (
|
||||
variable + " is no a longer supported "
|
||||
"monitored_conditions. See "
|
||||
"https://home-assistant.io/components/binary_sensor.nest/ "
|
||||
"for valid options."
|
||||
)
|
||||
_LOGGER.error(wstr)
|
||||
|
||||
def get_binary_sensors():
|
||||
"""Get the Nest binary sensors."""
|
||||
sensors = []
|
||||
for structure in nest.structures():
|
||||
sensors += [NestBinarySensor(structure, None, variable)
|
||||
for variable in conditions
|
||||
if variable in STRUCTURE_BINARY_TYPES]
|
||||
device_chain = chain(
|
||||
nest.thermostats(), nest.smoke_co_alarms(), nest.cameras())
|
||||
sensors += [
|
||||
NestBinarySensor(structure, None, variable)
|
||||
for variable in conditions
|
||||
if variable in STRUCTURE_BINARY_TYPES
|
||||
]
|
||||
device_chain = chain(nest.thermostats(), nest.smoke_co_alarms(), nest.cameras())
|
||||
for structure, device in device_chain:
|
||||
sensors += [NestBinarySensor(structure, device, variable)
|
||||
for variable in conditions
|
||||
if variable in BINARY_TYPES]
|
||||
sensors += [NestBinarySensor(structure, device, variable)
|
||||
for variable in conditions
|
||||
if variable in CLIMATE_BINARY_TYPES
|
||||
and device.is_thermostat]
|
||||
sensors += [
|
||||
NestBinarySensor(structure, device, variable)
|
||||
for variable in conditions
|
||||
if variable in BINARY_TYPES
|
||||
]
|
||||
sensors += [
|
||||
NestBinarySensor(structure, device, variable)
|
||||
for variable in conditions
|
||||
if variable in CLIMATE_BINARY_TYPES and device.is_thermostat
|
||||
]
|
||||
|
||||
if device.is_camera:
|
||||
sensors += [NestBinarySensor(structure, device, variable)
|
||||
for variable in conditions
|
||||
if variable in CAMERA_BINARY_TYPES]
|
||||
sensors += [
|
||||
NestBinarySensor(structure, device, variable)
|
||||
for variable in conditions
|
||||
if variable in CAMERA_BINARY_TYPES
|
||||
]
|
||||
for activity_zone in device.activity_zones:
|
||||
sensors += [NestActivityZoneSensor(
|
||||
structure, device, activity_zone)]
|
||||
sensors += [
|
||||
NestActivityZoneSensor(structure, device, activity_zone)
|
||||
]
|
||||
|
||||
return sensors
|
||||
|
||||
@@ -128,8 +131,7 @@ class NestBinarySensor(NestSensorDevice, BinarySensorDevice):
|
||||
"""Retrieve latest state."""
|
||||
value = getattr(self.device, self.variable)
|
||||
if self.variable in STRUCTURE_BINARY_TYPES:
|
||||
self._state = bool(STRUCTURE_BINARY_STATE_MAP
|
||||
[self.variable].get(value))
|
||||
self._state = bool(STRUCTURE_BINARY_STATE_MAP[self.variable].get(value))
|
||||
else:
|
||||
self._state = bool(value)
|
||||
|
||||
@@ -151,7 +153,7 @@ class NestActivityZoneSensor(NestBinarySensor):
|
||||
@property
|
||||
def device_class(self):
|
||||
"""Return the device class of the binary sensor."""
|
||||
return 'motion'
|
||||
return "motion"
|
||||
|
||||
def update(self):
|
||||
"""Retrieve latest state."""
|
||||
|
||||
Reference in New Issue
Block a user