Support for naming vehicle. Support for selecting what resources to display
This commit is contained in:
1 parent
827e3c4395
commit
1c6ba989a9
7 files changed
+69
-93
No files matched your search
@@ -12,43 +12,24 @@ from homeassistant.components.binary_sensor import BinarySensorDevice
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
SENSORS = [('washer_fluid_level', 'Washer fluid'),
|
||||
('brake_fluid', 'Brake Fluid'),
|
||||
('service_warning_status', 'Service'),
|
||||
('bulb_failures', 'Bulbs'),
|
||||
('doors', 'Doors'),
|
||||
('windows', 'Windows')]
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Setup Volvo sensors."""
|
||||
if discovery_info is None:
|
||||
return
|
||||
add_devices(VolvoSensor(hass, discovery_info, sensor)
|
||||
for sensor in SENSORS)
|
||||
add_devices([VolvoSensor(hass, *discovery_info)])
|
||||
|
||||
|
||||
class VolvoSensor(VolvoEntity, BinarySensorDevice):
|
||||
"""Representation of a Volvo sensor."""
|
||||
|
||||
def __init__(self, hass, vehicle, sensor):
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(hass, vehicle)
|
||||
self._sensor = sensor
|
||||
|
||||
@property
|
||||
def _name(self):
|
||||
"""Name of sensor."""
|
||||
return self._sensor[1]
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return True if the binary sensor is on."""
|
||||
attr = self._sensor[0]
|
||||
val = getattr(self.vehicle, attr)
|
||||
if attr == 'bulb_failures':
|
||||
val = getattr(self.vehicle, self._attribute)
|
||||
if self._attribute == 'bulb_failures':
|
||||
return len(val) > 0
|
||||
elif attr in ['doors', 'windows']:
|
||||
elif self._attribute in ['doors', 'windows']:
|
||||
return any([val[key] for key in val if 'Open' in key])
|
||||
else:
|
||||
return val != 'Normal'
|
||||
|
||||
Reference in new issue
Block a user