2019-02-13 20:21:14 +00:00
|
|
|
"""Support for VOC."""
|
2022-01-03 12:13:03 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2020-04-23 19:57:07 +00:00
|
|
|
from homeassistant.components.binary_sensor import DEVICE_CLASSES, BinarySensorEntity
|
2022-01-03 12:13:03 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
2019-03-21 05:56:46 +00:00
|
|
|
|
|
|
|
from . import DATA_KEY, VolvoEntity
|
2017-02-19 01:09:25 +00:00
|
|
|
|
|
|
|
|
2022-01-03 12:13:03 +00:00
|
|
|
async def async_setup_platform(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
config: ConfigType,
|
|
|
|
async_add_entities: AddEntitiesCallback,
|
|
|
|
discovery_info: DiscoveryInfoType | None = None,
|
|
|
|
) -> 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
|
2018-11-30 18:07:42 +00:00
|
|
|
async_add_entities([VolvoSensor(hass.data[DATA_KEY], *discovery_info)])
|
2017-02-19 01:09:25 +00:00
|
|
|
|
|
|
|
|
2020-04-23 19:57:07 +00:00
|
|
|
class VolvoSensor(VolvoEntity, BinarySensorEntity):
|
2017-02-19 01:09:25 +00:00
|
|
|
"""Representation of a Volvo sensor."""
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
2021-05-22 17:33:02 +00:00
|
|
|
"""Return True if the binary sensor is on, but invert for the 'Door lock'."""
|
|
|
|
if self.instrument.attr == "is_locked":
|
|
|
|
return not self.instrument.is_on
|
2018-11-30 18:07:42 +00:00
|
|
|
return self.instrument.is_on
|
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."""
|
2018-11-30 18:07:42 +00:00
|
|
|
if self.instrument.device_class in DEVICE_CLASSES:
|
|
|
|
return self.instrument.device_class
|
|
|
|
return None
|