From 500968a04b5773e4c2e63a49192dd4fc5c935a7a Mon Sep 17 00:00:00 2001 From: "Alan D. Tse" Date: Sat, 15 Feb 2020 22:35:41 -0800 Subject: [PATCH] feat: add wake_if_asleep param to update --- teslajsonpy/battery_sensor.py | 8 ++++---- teslajsonpy/binary_sensor.py | 12 ++++++------ teslajsonpy/charger.py | 12 ++++++------ teslajsonpy/climate.py | 8 ++++---- teslajsonpy/gps.py | 8 ++++---- teslajsonpy/lock.py | 8 ++++---- teslajsonpy/vehicle.py | 4 ++-- 7 files changed, 30 insertions(+), 30 deletions(-) diff --git a/teslajsonpy/battery_sensor.py b/teslajsonpy/battery_sensor.py index 347e81e1..b86a2c75 100644 --- a/teslajsonpy/battery_sensor.py +++ b/teslajsonpy/battery_sensor.py @@ -34,9 +34,9 @@ def __init__(self, data: Dict, controller) -> None: self.uniq_name: Text = self._uniq_name() self.bin_type: hex = 0x5 - async def async_update(self) -> None: + async def async_update(self, wake_if_asleep=False) -> None: """Update the battery state.""" - await super().async_update() + await super().async_update(wake_if_asleep=wake_if_asleep) data = self._controller.get_charging_params(self._id) if data: self.__battery_level = data["battery_level"] @@ -97,9 +97,9 @@ def __init__(self, data: Dict, controller) -> None: self.uniq_name = self._uniq_name() self.bin_type = 0xA - async def async_update(self): + async def async_update(self, wake_if_asleep=False) -> None: """Update the battery range state.""" - await super().async_update() + await super().async_update(wake_if_asleep=wake_if_asleep) data = self._controller.get_charging_params(self._id) if data: self.__battery_range = data["battery_range"] diff --git a/teslajsonpy/binary_sensor.py b/teslajsonpy/binary_sensor.py index b72a3723..acd06ab2 100644 --- a/teslajsonpy/binary_sensor.py +++ b/teslajsonpy/binary_sensor.py @@ -44,9 +44,9 @@ def __init__(self, data: Dict, controller): self.uniq_name = self._uniq_name() self.bin_type = 0x1 - async def async_update(self): + async def async_update(self, wake_if_asleep=False) -> None: """Update the parking brake sensor.""" - await super().async_update() + await super().async_update(wake_if_asleep=wake_if_asleep) data = self._controller.get_drive_params(self._id) if data: self.attrs["shift_state"] = ( @@ -100,9 +100,9 @@ def __init__(self, data, controller): self.uniq_name = self._uniq_name() self.bin_type = 0x2 - async def async_update(self): + async def async_update(self, wake_if_asleep=False) -> None: """Update the charger connection sensor.""" - await super().async_update() + await super().async_update(wake_if_asleep=wake_if_asleep) data = self._controller.get_charging_params(self._id) if data: self.attrs["charging_state"] = data["charging_state"] @@ -144,9 +144,9 @@ def __init__(self, data: Dict, controller) -> None: self.name: Text = self._name() self.uniq_name: Text = self._uniq_name() - async def async_update(self) -> None: + async def async_update(self, wake_if_asleep=False) -> None: """Update the battery state.""" - await super().async_update() + await super().async_update(wake_if_asleep=wake_if_asleep) self.__online_state = self._controller.car_online[self._vin] self.attrs["state"] = self._controller.car_state[self._vin].get("state") diff --git a/teslajsonpy/charger.py b/teslajsonpy/charger.py index a684f774..c890cc1c 100644 --- a/teslajsonpy/charger.py +++ b/teslajsonpy/charger.py @@ -39,9 +39,9 @@ def __init__(self, data, controller): self.uniq_name = self._uniq_name() self.bin_type = 0x8 - async def async_update(self): + async def async_update(self, wake_if_asleep=False) -> None: """Update the charging state of the Tesla Vehicle.""" - await super().async_update() + await super().async_update(wake_if_asleep=wake_if_asleep) last_update = self._controller.get_last_update_time(self._id) if last_update >= self.__manual_update_time: data = self._controller.get_charging_params(self._id) @@ -94,9 +94,9 @@ def __init__(self, data, controller): self.uniq_name = self._uniq_name() self.bin_type = 0x9 - async def async_update(self): + async def async_update(self, wake_if_asleep=False) -> None: """Update the status of the range setting.""" - await super().async_update() + await super().async_update(wake_if_asleep=wake_if_asleep) last_update = self._controller.get_last_update_time(self._id) if last_update >= self.__manual_update_time: data = self._controller.get_charging_params(self._id) @@ -161,9 +161,9 @@ def __init__(self, data: Dict, controller) -> None: self.__charger_actual_current = None self.__charger_voltage = None - async def async_update(self) -> None: + async def async_update(self, wake_if_asleep=False) -> None: """Update the battery state.""" - await super().async_update() + await super().async_update(wake_if_asleep=wake_if_asleep) data = self._controller.get_gui_params(self._id) if data: self.measurement = data["gui_distance_units"] diff --git a/teslajsonpy/climate.py b/teslajsonpy/climate.py index 3cc718f3..d5975ad1 100644 --- a/teslajsonpy/climate.py +++ b/teslajsonpy/climate.py @@ -70,9 +70,9 @@ def get_fan_status(self): """Return fan status.""" return self.__fan_status - async def async_update(self): + async def async_update(self, wake_if_asleep=False) -> None: """Update the HVAC state.""" - await super().async_update() + await super().async_update(wake_if_asleep=wake_if_asleep) data = self._controller.get_climate_params(self._id) if data: last_update = self._controller.get_last_update_time(self._id) @@ -180,9 +180,9 @@ def get_outside_temp(self): """Get outside temperature.""" return self.__outside_temp - async def async_update(self): + async def async_update(self, wake_if_asleep=False) -> None: """Update the temperature.""" - await super().async_update() + await super().async_update(wake_if_asleep=wake_if_asleep) data = self._controller.get_climate_params(self._id) if data: self.__inside_temp = ( diff --git a/teslajsonpy/gps.py b/teslajsonpy/gps.py index a1718304..3a76ce9c 100644 --- a/teslajsonpy/gps.py +++ b/teslajsonpy/gps.py @@ -57,9 +57,9 @@ def get_location(self): } return self.__location - async def async_update(self): + async def async_update(self, wake_if_asleep=False) -> None: """Update the current GPS location.""" - await super().async_update() + await super().async_update(wake_if_asleep=wake_if_asleep) data = self._controller.get_drive_params(self._id) if data: self.__longitude = data["longitude"] @@ -103,9 +103,9 @@ def __init__(self, data, controller): self.bin_type = 0xB self.__rated = True - async def async_update(self): + async def async_update(self, wake_if_asleep=False) -> None: """Update the odometer and the unit of measurement based on GUI.""" - await super().async_update() + await super().async_update(wake_if_asleep=wake_if_asleep) data = self._controller.get_state_params(self._id) if data: self.__odometer = data["odometer"] diff --git a/teslajsonpy/lock.py b/teslajsonpy/lock.py index 268594a2..e32a4387 100644 --- a/teslajsonpy/lock.py +++ b/teslajsonpy/lock.py @@ -44,9 +44,9 @@ def __init__(self, data, controller): self.uniq_name = self._uniq_name() self.bin_type = 0x7 - async def async_update(self): + async def async_update(self, wake_if_asleep=False) -> None: """Update the lock state.""" - await super().async_update() + await super().async_update(wake_if_asleep=wake_if_asleep) last_update = self._controller.get_last_update_time(self._id) if last_update >= self.__manual_update_time: data = self._controller.get_state_params(self._id) @@ -116,9 +116,9 @@ def __init__(self, data, controller): self.uniq_name = self._uniq_name() self.bin_type = 0x7 - async def async_update(self): + async def async_update(self, wake_if_asleep=False) -> None: """Update state of the charger lock.""" - await super().async_update() + await super().async_update(wake_if_asleep=wake_if_asleep) last_update = self._controller.get_last_update_time(self._id) if last_update >= self.__manual_update_time: data = self._controller.get_charging_params(self._id) diff --git a/teslajsonpy/vehicle.py b/teslajsonpy/vehicle.py index eb3a0f51..88f6ac1e 100644 --- a/teslajsonpy/vehicle.py +++ b/teslajsonpy/vehicle.py @@ -93,9 +93,9 @@ def assumed_state(self): > self._controller.update_interval ) - async def async_update(self): + async def async_update(self, wake_if_asleep=False): """Update the car version.""" - await self._controller.update(self.id(), wake_if_asleep=False) + await self._controller.update(self.id(), wake_if_asleep=wake_if_asleep) state = self._controller.get_state_params(self.id()) if state and "car_version" in state: self._car_version = state["car_version"]