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
@@ -7,53 +7,36 @@ https://home-assistant.io/components/sensor.volvooncall/
|
||||
"""
|
||||
import logging
|
||||
|
||||
from homeassistant.components.volvooncall import VolvoEntity
|
||||
from homeassistant.components.volvooncall import VolvoEntity, RESOURCES
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
SENSORS = [('odometer', 'Odometer', 'km', 'mdi:speedometer'),
|
||||
('fuel_amount', 'Fuel', 'L', 'mdi:gas-station'),
|
||||
('fuel_amount_level', 'Fuel', '%', 'mdi:water-percent'),
|
||||
('distance_to_empty', 'Range', 'km', 'mdi:ruler')]
|
||||
|
||||
|
||||
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):
|
||||
"""Representation of a Volvo sensor."""
|
||||
|
||||
def __init__(self, hass, vehicle, sensor):
|
||||
"""Initialize sensor."""
|
||||
super().__init__(hass, vehicle)
|
||||
self._sensor = sensor
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""Return the state of the sensor."""
|
||||
attr = self._sensor[0]
|
||||
val = getattr(self.vehicle, attr)
|
||||
if attr == 'odometer':
|
||||
val = getattr(self.vehicle, self._attribute)
|
||||
if self._attribute == 'odometer':
|
||||
return round(val / 1000) # km
|
||||
else:
|
||||
return val
|
||||
|
||||
@property
|
||||
def _name(self):
|
||||
"""Name of quantity."""
|
||||
return self._sensor[1]
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return the unit of measurement."""
|
||||
return self._sensor[2]
|
||||
return RESOURCES[self._attribute][2]
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
"""Return the icon."""
|
||||
return self._sensor[3]
|
||||
return RESOURCES[self._attribute][3]
|
||||
Reference in new issue
Block a user