Skip to content

Commit

Permalink
fix: use async_write vs async_update (#626)
Browse files Browse the repository at this point in the history
closes #606
  • Loading branch information
InTheDaylight14 authored Jun 2, 2023
1 parent 423e616 commit 78b0641
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion custom_components/tesla_custom/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ async def async_set_temperature(self, **kwargs):
temp = round(temperature, 1)

await self._car.set_temperature(temp)
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_set_hvac_mode(self, hvac_mode):
"""Set new target hvac mode."""
Expand Down
16 changes: 8 additions & 8 deletions custom_components/tesla_custom/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ async def async_close_cover(self, **kwargs):
"""Send close cover command."""
_LOGGER.debug("Closing cover: %s", self.name)
await self._car.charge_port_door_close()
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_open_cover(self, **kwargs):
"""Send open cover command."""
_LOGGER.debug("Opening cover: %s", self.name)
await self._car.charge_port_door_open()
await self.async_update_ha_state()
self.async_write_ha_state()

@property
def is_closed(self):
Expand All @@ -86,14 +86,14 @@ async def async_close_cover(self, **kwargs):
_LOGGER.debug("Closing cover: %s", self.name)
if self.is_closed is False:
await self._car.toggle_frunk()
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_open_cover(self, **kwargs):
"""Send open cover command."""
_LOGGER.debug("Opening cover: %s", self.name)
if self.is_closed is True:
await self._car.toggle_frunk()
await self.async_update_ha_state()
self.async_write_ha_state()

@property
def is_closed(self):
Expand Down Expand Up @@ -130,14 +130,14 @@ async def async_close_cover(self, **kwargs):
_LOGGER.debug("Closing cover: %s", self.name)
if self.is_closed is False:
await self._car.toggle_trunk()
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_open_cover(self, **kwargs):
"""Send open cover command."""
_LOGGER.debug("Opening cover: %s", self.name)
if self.is_closed is True:
await self._car.toggle_trunk()
await self.async_update_ha_state()
self.async_write_ha_state()

@property
def is_closed(self):
Expand Down Expand Up @@ -176,14 +176,14 @@ async def async_close_cover(self, **kwargs):
_LOGGER.debug("Closing cover: %s", self.name)
if self.is_closed is False:
await self._car.close_windows()
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_open_cover(self, **kwargs):
"""Send open cover command."""
_LOGGER.debug("Opening cover: %s", self.name)
if self.is_closed is True:
await self._car.vent_windows()
await self.async_update_ha_state()
self.async_write_ha_state()

@property
def is_closed(self):
Expand Down
8 changes: 4 additions & 4 deletions custom_components/tesla_custom/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ async def async_lock(self, **kwargs):
"""Send lock command."""
_LOGGER.debug("Locking: %s", self.name)
await self._car.lock()
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_unlock(self, **kwargs):
"""Send unlock command."""
_LOGGER.debug("Unlocking: %s", self.name)
await self._car.unlock()
await self.async_update_ha_state()
self.async_write_ha_state()

@property
def is_locked(self):
Expand All @@ -77,13 +77,13 @@ async def async_open(self, **kwargs):
"""Send open command."""
_LOGGER.debug("Opening: %s", self.name)
await self._car.charge_port_door_open()
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_unlock(self, **kwargs):
"""Send unlock command."""
_LOGGER.debug("Unlocking: %s", self.name)
await self._car.charge_port_door_open()
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_lock(self, **kwargs):
"""Log lock command not possible."""
Expand Down
6 changes: 3 additions & 3 deletions custom_components/tesla_custom/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(
async def async_set_native_value(self, value: int) -> None:
"""Update charge limit."""
await self._car.change_charge_limit(value)
await self.async_update_ha_state()
self.async_write_ha_state()

@property
def native_value(self) -> int:
Expand Down Expand Up @@ -99,7 +99,7 @@ def __init__(
async def async_set_native_value(self, value: int) -> None:
"""Update charging amps."""
await self._car.set_charging_amps(value)
await self.async_update_ha_state()
self.async_write_ha_state()

@property
def native_value(self) -> int:
Expand Down Expand Up @@ -141,7 +141,7 @@ def __init__(
async def async_set_native_value(self, value: int) -> None:
"""Update backup reserve percentage."""
await self._energysite.set_reserve_percent(value)
await self.async_update_ha_state()
self.async_write_ha_state()

@property
def native_value(self) -> int:
Expand Down
8 changes: 4 additions & 4 deletions custom_components/tesla_custom/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def __init__(
async def async_select_option(self, option: str, **kwargs):
"""Change the selected option."""
await self._car.set_cabin_overheat_protection(option)
await self.async_update_ha_state()
self.async_write_ha_state()

@property
def current_option(self):
Expand Down Expand Up @@ -220,7 +220,7 @@ async def async_select_option(self, option: str, **kwargs):
else:
await self._energysite.set_grid_charging(False)

await self.async_update_ha_state()
self.async_write_ha_state()

@property
def current_option(self):
Expand Down Expand Up @@ -259,7 +259,7 @@ async def async_select_option(self, option: str, **kwargs):
if option == EXPORT_RULE[1]:
await self._energysite.set_export_rule("battery_ok")

await self.async_update_ha_state()
self.async_write_ha_state()

@property
def current_option(self) -> str:
Expand Down Expand Up @@ -295,7 +295,7 @@ async def async_select_option(self, option: str, **kwargs):
if option == OPERATION_MODE[2]:
await self._energysite.set_operation_mode("backup")

await self.async_update_ha_state()
self.async_write_ha_state()

@property
def current_option(self) -> str:
Expand Down
20 changes: 10 additions & 10 deletions custom_components/tesla_custom/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ def is_on(self):
async def async_turn_on(self, **kwargs):
"""Send the on command."""
await self._car.set_heated_steering_wheel(True)
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_turn_off(self, **kwargs):
"""Send the off command."""
await self._car.set_heated_steering_wheel(False)
await self.async_update_ha_state()
self.async_write_ha_state()


class TeslaCarPolling(TeslaCarEntity, SwitchEntity):
Expand Down Expand Up @@ -95,13 +95,13 @@ async def async_turn_on(self, **kwargs):
"""Send the on command."""
_LOGGER.debug("Enable polling: %s %s", self.name, self._car.vin)
self._coordinator.controller.set_updates(vin=self._car.vin, value=True)
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_turn_off(self, **kwargs):
"""Send the off command."""
_LOGGER.debug("Disable polling: %s %s", self.name, self._car.vin)
self._coordinator.controller.set_updates(vin=self._car.vin, value=False)
await self.async_update_ha_state()
self.async_write_ha_state()


class TeslaCarCharger(TeslaCarEntity, SwitchEntity):
Expand All @@ -126,12 +126,12 @@ def is_on(self):
async def async_turn_on(self, **kwargs):
"""Send the on command."""
await self._car.start_charge()
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_turn_off(self, **kwargs):
"""Send the off command."""
await self._car.stop_charge()
await self.async_update_ha_state()
self.async_write_ha_state()


class TeslaCarSentryMode(TeslaCarEntity, SwitchEntity):
Expand Down Expand Up @@ -169,12 +169,12 @@ def is_on(self):
async def async_turn_on(self, **kwargs):
"""Send the on command."""
await self._car.set_sentry_mode(True)
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_turn_off(self, **kwargs):
"""Send the off command."""
await self._car.set_sentry_mode(False)
await self.async_update_ha_state()
self.async_write_ha_state()


class TeslaCarValetMode(TeslaCarEntity, SwitchEntity):
Expand Down Expand Up @@ -203,7 +203,7 @@ async def async_turn_on(self, **kwargs):
_LOGGER.debug("Pin required for valet mode, set pin in vehicle or app.")
else:
await self._car.valet_mode(True)
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_turn_off(self, **kwargs):
"""Send the off command."""
Expand All @@ -212,4 +212,4 @@ async def async_turn_off(self, **kwargs):
_LOGGER.debug("Pin required for valet mode, set pin in vehicle or app.")
else:
await self._car.valet_mode(False)
await self.async_update_ha_state()
self.async_write_ha_state()
2 changes: 1 addition & 1 deletion custom_components/tesla_custom/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async def async_set_value(self, value: str) -> None:

await self.teslsmate.set_car_id(self._car.vin, value)
await self.teslsmate.watch_cars()
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_update(self) -> None:
"""Update the entity."""
Expand Down

0 comments on commit 78b0641

Please sign in to comment.