2017-02-19 01:09:25 +00:00
|
|
|
"""
|
|
|
|
Support for VOC.
|
|
|
|
|
|
|
|
For more details about this platform, please refer to the documentation at
|
|
|
|
https://home-assistant.io/components/binary_sensor.volvooncall/
|
|
|
|
"""
|
|
|
|
import logging
|
|
|
|
|
|
|
|
from homeassistant.components.volvooncall import VolvoEntity
|
|
|
|
from homeassistant.components.binary_sensor import BinarySensorDevice
|
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
2017-04-30 05:04:49 +00:00
|
|
|
"""Set up the Volvo sensors."""
|
2017-02-19 01:09:25 +00:00
|
|
|
if discovery_info is None:
|
|
|
|
return
|
2017-02-22 22:39:59 +00:00
|
|
|
add_devices([VolvoSensor(hass, *discovery_info)])
|
2017-02-19 01:09:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
class VolvoSensor(VolvoEntity, BinarySensorDevice):
|
|
|
|
"""Representation of a Volvo sensor."""
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
|
|
|
"""Return True if the binary sensor is on."""
|
2017-02-22 22:39:59 +00:00
|
|
|
val = getattr(self.vehicle, self._attribute)
|
|
|
|
if self._attribute == 'bulb_failures':
|
2017-04-24 03:41:09 +00:00
|
|
|
return bool(val)
|
2017-02-22 22:39:59 +00:00
|
|
|
elif self._attribute in ['doors', 'windows']:
|
2017-02-19 01:09:25 +00:00
|
|
|
return any([val[key] for key in val if 'Open' in key])
|
2017-07-06 06:30:01 +00:00
|
|
|
return val != 'Normal'
|
2017-02-19 01:09:25 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def device_class(self):
|
2017-07-29 23:46:27 +00:00
|
|
|
"""Return the class of this sensor, from DEVICE_CLASSES."""
|
2017-02-19 01:09:25 +00:00
|
|
|
return 'safety'
|