* build: bump teslajsonpy to 0.2.0 * Remove tests * feat: add config flow * feat: add async * perf: convert unnecessary async calls to sync * feat: add charger voltage and current sensor * feat: add options flow * build: bump teslajsonpy to 0.2.0 * Remove icon property * Revert climate mode change * Remove charger sensor * Simplify async_setup_platform * Update homeassistant/components/tesla/sensor.py Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/tesla/binary_sensor.py Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io> * Address requested changes * Fix pylint error * Address requested changes * Update codeowners * Fix pylint error * Address requested changes * Address requested change * Remove unnecessary check for existing config entry * Load scan_interval in async_setup_entry * Include coverage of config_flow * Add tests for full coverage * Address requested test changes * Remove unnecessary init lines * Remove unnecessary init Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
62 lines
1.8 KiB
Python
62 lines
1.8 KiB
Python
"""Support for Tesla binary sensor."""
|
|
import logging
|
|
|
|
from homeassistant.components.binary_sensor import BinarySensorDevice
|
|
|
|
from . import DOMAIN as TESLA_DOMAIN, TeslaDevice
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
|
"""Set up the Tesla binary sensor."""
|
|
pass
|
|
|
|
|
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
|
"""Set up the Tesla binary_sensors by config_entry."""
|
|
async_add_entities(
|
|
[
|
|
TeslaBinarySensor(
|
|
device,
|
|
hass.data[TESLA_DOMAIN][config_entry.entry_id]["controller"],
|
|
"connectivity",
|
|
config_entry,
|
|
)
|
|
for device in hass.data[TESLA_DOMAIN][config_entry.entry_id]["devices"][
|
|
"binary_sensor"
|
|
]
|
|
],
|
|
True,
|
|
)
|
|
|
|
|
|
class TeslaBinarySensor(TeslaDevice, BinarySensorDevice):
|
|
"""Implement an Tesla binary sensor for parking and charger."""
|
|
|
|
def __init__(self, tesla_device, controller, sensor_type, config_entry):
|
|
"""Initialise of a Tesla binary sensor."""
|
|
super().__init__(tesla_device, controller, config_entry)
|
|
self._state = False
|
|
self._sensor_type = sensor_type
|
|
|
|
@property
|
|
def device_class(self):
|
|
"""Return the class of this binary sensor."""
|
|
return self._sensor_type
|
|
|
|
@property
|
|
def name(self):
|
|
"""Return the name of the binary sensor."""
|
|
return self._name
|
|
|
|
@property
|
|
def is_on(self):
|
|
"""Return the state of the binary sensor."""
|
|
return self._state
|
|
|
|
async def async_update(self):
|
|
"""Update the state of the device."""
|
|
_LOGGER.debug("Updating sensor: %s", self._name)
|
|
await super().async_update()
|
|
self._state = self.tesla_device.get_value()
|