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/sensor.volvooncall/
|
|
|
|
|
|
|
|
"""
|
|
|
|
import logging
|
|
|
|
|
2017-02-22 22:39:59 +00:00
|
|
|
from homeassistant.components.volvooncall import VolvoEntity, RESOURCES
|
2017-02-19 01:09:25 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
|
|
|
"""Setup Volvo sensors."""
|
|
|
|
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):
|
|
|
|
"""Representation of a Volvo sensor."""
|
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
|
|
|
"""Return the state of the sensor."""
|
2017-02-22 22:39:59 +00:00
|
|
|
val = getattr(self.vehicle, self._attribute)
|
|
|
|
if self._attribute == 'odometer':
|
2017-02-19 01:09:25 +00:00
|
|
|
return round(val / 1000) # km
|
|
|
|
else:
|
|
|
|
return val
|
|
|
|
|
|
|
|
@property
|
|
|
|
def unit_of_measurement(self):
|
|
|
|
"""Return the unit of measurement."""
|
2017-02-23 12:27:17 +00:00
|
|
|
return RESOURCES[self._attribute][3]
|
2017-02-19 01:09:25 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def icon(self):
|
|
|
|
"""Return the icon."""
|
2017-02-23 12:27:17 +00:00
|
|
|
return RESOURCES[self._attribute][2]
|