Skip nest security state sensor if no Nest Cam exists (#15112)

pull/15143/head
Jason Hu 2018-06-25 10:13:41 -07:00 committed by Paulus Schoutsen
parent b2d37ccef6
commit e681a7929c
1 changed files with 14 additions and 2 deletions

View File

@ -24,10 +24,14 @@ PROTECT_SENSOR_TYPES = ['co_status',
# color_status: "gray", "green", "yellow", "red"
'color_status']
STRUCTURE_SENSOR_TYPES = ['eta', 'security_state']
STRUCTURE_SENSOR_TYPES = ['eta']
# security_state is structure level sensor, but only meaningful when
# Nest Cam exist
STRUCTURE_CAMERA_SENSOR_TYPES = ['security_state']
_VALID_SENSOR_TYPES = SENSOR_TYPES + TEMP_SENSOR_TYPES + PROTECT_SENSOR_TYPES \
+ STRUCTURE_SENSOR_TYPES
+ STRUCTURE_SENSOR_TYPES + STRUCTURE_CAMERA_SENSOR_TYPES
SENSOR_UNITS = {'humidity': '%'}
@ -105,6 +109,14 @@ async def async_setup_entry(hass, entry, async_add_devices):
for variable in conditions
if variable in PROTECT_SENSOR_TYPES]
structures_has_camera = {}
for structure, device in nest.cameras():
structures_has_camera[structure] = True
for structure in structures_has_camera:
all_sensors += [NestBasicSensor(structure, None, variable)
for variable in conditions
if variable in STRUCTURE_CAMERA_SENSOR_TYPES]
return all_sensors
async_add_devices(await hass.async_add_job(get_sensors), True)