From 7aa48d5578631ffbdd2f739ec86ee3ccec5636b3 Mon Sep 17 00:00:00 2001 From: "Alan D. Tse" Date: Tue, 22 Oct 2019 00:45:15 -0700 Subject: [PATCH] feat: expose car_type and car_version for entities --- teslajsonpy/battery_sensor.py | 2 ++ teslajsonpy/binary_sensor.py | 2 ++ teslajsonpy/charger.py | 2 ++ teslajsonpy/climate.py | 3 ++- teslajsonpy/gps.py | 2 ++ teslajsonpy/lock.py | 2 ++ teslajsonpy/vehicle.py | 29 +++++++++++++++++++++++++++++ 7 files changed, 41 insertions(+), 1 deletion(-) diff --git a/teslajsonpy/battery_sensor.py b/teslajsonpy/battery_sensor.py index 41102827..a7b10b13 100644 --- a/teslajsonpy/battery_sensor.py +++ b/teslajsonpy/battery_sensor.py @@ -44,6 +44,7 @@ def __init__(self, data, controller): def update(self): """Update the battery state.""" self._controller.update(self._id, wake_if_asleep=False) + super().update() data = self._controller.get_charging_params(self._id) if data: self.__battery_level = data['battery_level'] @@ -94,6 +95,7 @@ def __init__(self, data, controller): def update(self): """Update the battery range state.""" self._controller.update(self._id, wake_if_asleep=False) + super().update() 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 56f88b6b..b2b482f0 100644 --- a/teslajsonpy/binary_sensor.py +++ b/teslajsonpy/binary_sensor.py @@ -48,6 +48,7 @@ def __init__(self, data, controller): def update(self): """Update the parking brake sensor.""" self._controller.update(self._id, wake_if_asleep=False) + super().update() data = self._controller.get_drive_params(self._id) if data: if not data['shift_state'] or data['shift_state'] == 'P': @@ -101,6 +102,7 @@ def __init__(self, data, controller): def update(self): """Update the charger connection sensor.""" self._controller.update(self._id, wake_if_asleep=False) + super().update() data = self._controller.get_charging_params(self._id) if data: if data['charging_state'] in ["Disconnected"]: diff --git a/teslajsonpy/charger.py b/teslajsonpy/charger.py index f6bc87bb..c51142a5 100644 --- a/teslajsonpy/charger.py +++ b/teslajsonpy/charger.py @@ -44,6 +44,7 @@ def __init__(self, data, controller): def update(self): """Update the charging state of the Tesla Vehicle.""" self._controller.update(self._id, wake_if_asleep=False) + super().update() data = self._controller.get_charging_params(self._id) if data and (time.time() - self.__manual_update_time > 60): if data['charging_state'] != "Charging": @@ -97,6 +98,7 @@ def __init__(self, data, controller): def update(self): """Update the status of the range setting.""" self._controller.update(self._id, wake_if_asleep=False) + super().update() data = self._controller.get_charging_params(self._id) if data and (time.time() - self.__manual_update_time > 60): self.__maxrange_state = data['charge_to_max_range'] diff --git a/teslajsonpy/climate.py b/teslajsonpy/climate.py index 88b4d0f2..f7dd6aa2 100644 --- a/teslajsonpy/climate.py +++ b/teslajsonpy/climate.py @@ -76,7 +76,7 @@ def get_fan_status(self): def update(self): """Update the HVAC state.""" self._controller.update(self._id, wake_if_asleep=False) - + super().update() data = self._controller.get_climate_params(self._id) if data: if time.time() - self.__manual_update_time > 60: @@ -181,6 +181,7 @@ def get_outside_temp(self): def update(self): """Update the temperature.""" self._controller.update(self._id, wake_if_asleep=False) + super().update() data = self._controller.get_climate_params(self._id) if data: self.__inside_temp = (data['inside_temp'] if data['inside_temp'] diff --git a/teslajsonpy/gps.py b/teslajsonpy/gps.py index bc741849..2624c085 100644 --- a/teslajsonpy/gps.py +++ b/teslajsonpy/gps.py @@ -53,6 +53,7 @@ def get_location(self): def update(self): """Update the current GPS location.""" self._controller.update(self._id, wake_if_asleep=False) + super().update() data = self._controller.get_drive_params(self._id) if data: self.__longitude = data['longitude'] @@ -102,6 +103,7 @@ def __init__(self, data, controller): def update(self): """Update the odometer and the unit of measurement based on GUI.""" self._controller.update(self._id, wake_if_asleep=False) + super().update() 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 40162323..9524cdd1 100644 --- a/teslajsonpy/lock.py +++ b/teslajsonpy/lock.py @@ -50,6 +50,7 @@ def __init__(self, data, controller): def update(self): """Update the lock state.""" self._controller.update(self._id, wake_if_asleep=False) + super().update() data = self._controller.get_state_params(self._id) if data and (time.time() - self.__manual_update_time > 60): self.__lock_state = data['locked'] @@ -120,6 +121,7 @@ def __init__(self, data, controller): def update(self): """Update state of the charger lock.""" self._controller.update(self._id, wake_if_asleep=False) + super().update() data = self._controller.get_charging_params(self._id) if data and (time.time() - self.__manual_update_time > 60): self.__lock_state = not ((data['charge_port_door_open']) and diff --git a/teslajsonpy/vehicle.py b/teslajsonpy/vehicle.py index 3b455b0c..fd5a1715 100644 --- a/teslajsonpy/vehicle.py +++ b/teslajsonpy/vehicle.py @@ -7,7 +7,9 @@ For more details about this api, please refer to the documentation at https://github.com/zabuldon/teslajsonpy """ +import logging +_LOGGER = logging.getLogger(__name__) class VehicleDevice: """Home-assistant class of Tesla vehicles. @@ -36,6 +38,8 @@ def __init__(self, data, controller): self._display_name = data['display_name'] self._vin = data['vin'] self._state = data['state'] + self._car_type = f"Model {str(self._vin[3]).upper()}" + self._car_version = "" self._controller = controller self.should_poll = True self.type = "device" @@ -56,6 +60,25 @@ def id(self): """Return the id of this Vehicle.""" return self._id + def car_name(self): + """Return the software version of this Vehicle.""" + return ( + self._display_name if + self._display_name is not None and + self._display_name != self._vin[-6:] + else f'Tesla Model {str(self._vin[3]).upper()}' + ) + + @property + def car_version(self): + """Return the software version of this Vehicle.""" + return self._car_version + + @property + def car_type(self): + """Return the type of this Vehicle.""" + return self._car_type + def assumed_state(self): # pylint: disable=protected-access """Return whether the data is from an online vehicle.""" @@ -64,6 +87,12 @@ def assumed_state(self): self._controller._last_wake_up_time[self.id()] > self._controller.update_interval)) + def update(self): + """Update the car version.""" + state = self._controller.get_state_params(self.id()) + if state and 'car_version' in state: + self._car_version = state['car_version'] + @staticmethod def is_armable(): """Return whether the data is from an online vehicle."""