Add update available binary sensor to Tesla (#37991)

* Add update available binary sensor to Tesla

* Bump teslajsonpy to 0.10.1

* Add check for DEVICE_CLASS

* Change to relative import
This commit is contained in:
Alan Tse 2020-07-26 11:00:07 -07:00 committed by GitHub
parent 2d6eb5c05d
commit 093bd863ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 13 deletions

View file

@ -1,7 +1,7 @@
"""Support for Tesla binary sensor.""" """Support for Tesla binary sensor."""
import logging import logging
from homeassistant.components.binary_sensor import BinarySensorEntity from homeassistant.components.binary_sensor import DEVICE_CLASSES, BinarySensorEntity
from . import DOMAIN as TESLA_DOMAIN, TeslaDevice from . import DOMAIN as TESLA_DOMAIN, TeslaDevice
@ -15,7 +15,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
TeslaBinarySensor( TeslaBinarySensor(
device, device,
hass.data[TESLA_DOMAIN][config_entry.entry_id]["controller"], hass.data[TESLA_DOMAIN][config_entry.entry_id]["controller"],
"connectivity",
config_entry, config_entry,
) )
for device in hass.data[TESLA_DOMAIN][config_entry.entry_id]["devices"][ for device in hass.data[TESLA_DOMAIN][config_entry.entry_id]["devices"][
@ -29,22 +28,19 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
class TeslaBinarySensor(TeslaDevice, BinarySensorEntity): class TeslaBinarySensor(TeslaDevice, BinarySensorEntity):
"""Implement an Tesla binary sensor for parking and charger.""" """Implement an Tesla binary sensor for parking and charger."""
def __init__(self, tesla_device, controller, sensor_type, config_entry): def __init__(self, tesla_device, controller, config_entry):
"""Initialise of a Tesla binary sensor.""" """Initialise of a Tesla binary sensor."""
super().__init__(tesla_device, controller, config_entry) super().__init__(tesla_device, controller, config_entry)
self._state = False self._state = None
self._sensor_type = sensor_type self._sensor_type = None
if tesla_device.sensor_type in DEVICE_CLASSES:
self._sensor_type = tesla_device.sensor_type
@property @property
def device_class(self): def device_class(self):
"""Return the class of this binary sensor.""" """Return the class of this binary sensor."""
return self._sensor_type return self._sensor_type
@property
def name(self):
"""Return the name of the binary sensor."""
return self._name
@property @property
def is_on(self): def is_on(self):
"""Return the state of the binary sensor.""" """Return the state of the binary sensor."""

View file

@ -3,6 +3,6 @@
"name": "Tesla", "name": "Tesla",
"config_flow": true, "config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/tesla", "documentation": "https://www.home-assistant.io/integrations/tesla",
"requirements": ["teslajsonpy==0.9.3"], "requirements": ["teslajsonpy==0.10.1"],
"codeowners": ["@zabuldon", "@alandtse"] "codeowners": ["@zabuldon", "@alandtse"]
} }

View file

@ -2101,7 +2101,7 @@ temperusb==1.5.3
tesla-powerwall==0.2.11 tesla-powerwall==0.2.11
# homeassistant.components.tesla # homeassistant.components.tesla
teslajsonpy==0.9.3 teslajsonpy==0.10.1
# homeassistant.components.thermoworks_smoke # homeassistant.components.thermoworks_smoke
thermoworks_smoke==0.1.8 thermoworks_smoke==0.1.8

View file

@ -927,7 +927,7 @@ tellduslive==0.10.11
tesla-powerwall==0.2.11 tesla-powerwall==0.2.11
# homeassistant.components.tesla # homeassistant.components.tesla
teslajsonpy==0.9.3 teslajsonpy==0.10.1
# homeassistant.components.toon # homeassistant.components.toon
toonapi==0.1.0 toonapi==0.1.0