Fix updating of Tesla switches after command (#43754)

closes #43454
This commit is contained in:
Alan Tse 2020-11-30 00:57:32 -08:00 committed by GitHub
parent aade4e63b8
commit e307e1315a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -30,11 +30,13 @@ class ChargerSwitch(TeslaDevice, SwitchEntity):
"""Send the on command.""" """Send the on command."""
_LOGGER.debug("Enable charging: %s", self.name) _LOGGER.debug("Enable charging: %s", self.name)
await self.tesla_device.start_charge() await self.tesla_device.start_charge()
self.async_write_ha_state()
async def async_turn_off(self, **kwargs): async def async_turn_off(self, **kwargs):
"""Send the off command.""" """Send the off command."""
_LOGGER.debug("Disable charging for: %s", self.name) _LOGGER.debug("Disable charging for: %s", self.name)
await self.tesla_device.stop_charge() await self.tesla_device.stop_charge()
self.async_write_ha_state()
@property @property
def is_on(self): def is_on(self):
@ -51,11 +53,13 @@ class RangeSwitch(TeslaDevice, SwitchEntity):
"""Send the on command.""" """Send the on command."""
_LOGGER.debug("Enable max range charging: %s", self.name) _LOGGER.debug("Enable max range charging: %s", self.name)
await self.tesla_device.set_max() await self.tesla_device.set_max()
self.async_write_ha_state()
async def async_turn_off(self, **kwargs): async def async_turn_off(self, **kwargs):
"""Send the off command.""" """Send the off command."""
_LOGGER.debug("Disable max range charging: %s", self.name) _LOGGER.debug("Disable max range charging: %s", self.name)
await self.tesla_device.set_standard() await self.tesla_device.set_standard()
self.async_write_ha_state()
@property @property
def is_on(self): def is_on(self):
@ -87,11 +91,13 @@ class UpdateSwitch(TeslaDevice, SwitchEntity):
"""Send the on command.""" """Send the on command."""
_LOGGER.debug("Enable updates: %s %s", self.name, self.tesla_device.id()) _LOGGER.debug("Enable updates: %s %s", self.name, self.tesla_device.id())
self.controller.set_updates(self.tesla_device.id(), True) self.controller.set_updates(self.tesla_device.id(), True)
self.async_write_ha_state()
async def async_turn_off(self, **kwargs): async def async_turn_off(self, **kwargs):
"""Send the off command.""" """Send the off command."""
_LOGGER.debug("Disable updates: %s %s", self.name, self.tesla_device.id()) _LOGGER.debug("Disable updates: %s %s", self.name, self.tesla_device.id())
self.controller.set_updates(self.tesla_device.id(), False) self.controller.set_updates(self.tesla_device.id(), False)
self.async_write_ha_state()
@property @property
def is_on(self): def is_on(self):
@ -108,11 +114,13 @@ class SentryModeSwitch(TeslaDevice, SwitchEntity):
"""Send the on command.""" """Send the on command."""
_LOGGER.debug("Enable sentry mode: %s", self.name) _LOGGER.debug("Enable sentry mode: %s", self.name)
await self.tesla_device.enable_sentry_mode() await self.tesla_device.enable_sentry_mode()
self.async_write_ha_state()
async def async_turn_off(self, **kwargs): async def async_turn_off(self, **kwargs):
"""Send the off command.""" """Send the off command."""
_LOGGER.debug("Disable sentry mode: %s", self.name) _LOGGER.debug("Disable sentry mode: %s", self.name)
await self.tesla_device.disable_sentry_mode() await self.tesla_device.disable_sentry_mode()
self.async_write_ha_state()
@property @property
def is_on(self): def is_on(self):