2019-02-13 20:21:14 +00:00
|
|
|
"""Support for Tesla binary sensor."""
|
2017-08-31 04:13:02 +00:00
|
|
|
|
2020-07-26 18:00:07 +00:00
|
|
|
from homeassistant.components.binary_sensor import DEVICE_CLASSES, BinarySensorEntity
|
2019-03-21 05:56:46 +00:00
|
|
|
|
|
|
|
from . import DOMAIN as TESLA_DOMAIN, TeslaDevice
|
2017-08-31 04:13:02 +00:00
|
|
|
|
|
|
|
|
2019-12-23 20:54:25 +00:00
|
|
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
|
|
|
"""Set up the Tesla binary_sensors by config_entry."""
|
|
|
|
async_add_entities(
|
|
|
|
[
|
|
|
|
TeslaBinarySensor(
|
2020-08-27 11:56:20 +00:00
|
|
|
device,
|
|
|
|
hass.data[TESLA_DOMAIN][config_entry.entry_id]["coordinator"],
|
2019-12-23 20:54:25 +00:00
|
|
|
)
|
|
|
|
for device in hass.data[TESLA_DOMAIN][config_entry.entry_id]["devices"][
|
|
|
|
"binary_sensor"
|
|
|
|
]
|
|
|
|
],
|
|
|
|
True,
|
|
|
|
)
|
2017-08-31 04:13:02 +00:00
|
|
|
|
|
|
|
|
2020-04-23 19:57:07 +00:00
|
|
|
class TeslaBinarySensor(TeslaDevice, BinarySensorEntity):
|
2017-08-31 04:13:02 +00:00
|
|
|
"""Implement an Tesla binary sensor for parking and charger."""
|
|
|
|
|
|
|
|
@property
|
|
|
|
def device_class(self):
|
|
|
|
"""Return the class of this binary sensor."""
|
2020-08-08 03:16:28 +00:00
|
|
|
return (
|
|
|
|
self.tesla_device.sensor_type
|
|
|
|
if self.tesla_device.sensor_type in DEVICE_CLASSES
|
|
|
|
else None
|
|
|
|
)
|
2017-08-31 04:13:02 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
|
|
|
"""Return the state of the binary sensor."""
|
2020-08-08 03:16:28 +00:00
|
|
|
return self.tesla_device.get_value()
|