Bump teslajsonpy and add update switch (#27957)

* bump teslajsonpy to 0.0.26
breaking change

* add update switch to tesla

* bump requirements_all.txt for teslajsonpy

* address requested style changes

* fix bug where update switch not loaded
pull/28054/head
Alan Tse 2019-10-21 01:59:58 -07:00 committed by Fabian Affolter
parent d1fcc5762b
commit 1e832dc9ec
3 changed files with 39 additions and 10 deletions

View File

@ -2,11 +2,7 @@
"domain": "tesla",
"name": "Tesla",
"documentation": "https://www.home-assistant.io/integrations/tesla",
"requirements": [
"teslajsonpy==0.0.25"
],
"requirements": ["teslajsonpy==0.0.26"],
"dependencies": [],
"codeowners": [
"@zabuldon"
]
"codeowners": ["@zabuldon"]
}

View File

@ -11,11 +11,12 @@ _LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Tesla switch platform."""
controller = hass.data[TESLA_DOMAIN]["devices"]["controller"]
controller = hass.data[TESLA_DOMAIN]["controller"]
devices = []
for device in hass.data[TESLA_DOMAIN]["devices"]["switch"]:
if device.bin_type == 0x8:
devices.append(ChargerSwitch(device, controller))
devices.append(UpdateSwitch(device, controller))
elif device.bin_type == 0x9:
devices.append(RangeSwitch(device, controller))
add_entities(devices, True)
@ -72,10 +73,42 @@ class RangeSwitch(TeslaDevice, SwitchDevice):
@property
def is_on(self):
"""Get whether the switch is in on state."""
return self._state == STATE_ON
return self._state
def update(self):
"""Update the state of the switch."""
_LOGGER.debug("Updating state for: %s", self._name)
self.tesla_device.update()
self._state = STATE_ON if self.tesla_device.is_maxrange() else STATE_OFF
self._state = bool(self.tesla_device.is_maxrange())
class UpdateSwitch(TeslaDevice, SwitchDevice):
"""Representation of a Tesla update switch."""
def __init__(self, tesla_device, controller):
"""Initialise of the switch."""
self._state = None
super().__init__(tesla_device, controller)
self._name = self._name.replace("charger", "update")
self.tesla_id = self.tesla_id.replace("charger", "update")
def turn_on(self, **kwargs):
"""Send the on command."""
_LOGGER.debug("Enable updates: %s %s", self._name, self.tesla_device.id())
self.controller.set_updates(self.tesla_device.id(), True)
def turn_off(self, **kwargs):
"""Send the off command."""
_LOGGER.debug("Disable updates: %s %s", self._name, self.tesla_device.id())
self.controller.set_updates(self.tesla_device.id(), False)
@property
def is_on(self):
"""Get whether the switch is in on state."""
return self._state
def update(self):
"""Update the state of the switch."""
car_id = self.tesla_device.id()
_LOGGER.debug("Updating state for: %s %s", self._name, car_id)
self._state = bool(self.controller.get_updates(car_id))

View File

@ -1876,7 +1876,7 @@ temperusb==1.5.3
# tensorflow==1.13.2
# homeassistant.components.tesla
teslajsonpy==0.0.25
teslajsonpy==0.0.26
# homeassistant.components.thermoworks_smoke
thermoworks_smoke==0.1.8