From 9793ee09c297cdc6dc05e6b67bc826ac11d3394f Mon Sep 17 00:00:00 2001 From: "Alan D. Tse" Date: Tue, 28 Jul 2020 21:49:25 -0700 Subject: [PATCH 1/3] refactor: break out non IO operations to refresh This is to support callback functions for the HA coordinator --- teslajsonpy/battery_sensor.py | 16 ++++++++++++++++ teslajsonpy/binary_sensor.py | 32 ++++++++++++++++++++++++++++++++ teslajsonpy/charger.py | 24 ++++++++++++++++++++++++ teslajsonpy/climate.py | 16 ++++++++++++++++ teslajsonpy/gps.py | 16 ++++++++++++++++ teslajsonpy/lock.py | 16 ++++++++++++++++ teslajsonpy/sentry_mode.py | 8 ++++++++ teslajsonpy/trunk.py | 16 ++++++++++++++++ teslajsonpy/vehicle.py | 13 ++++++++++++- 9 files changed, 156 insertions(+), 1 deletion(-) diff --git a/teslajsonpy/battery_sensor.py b/teslajsonpy/battery_sensor.py index 9028fa58..4e2afad2 100644 --- a/teslajsonpy/battery_sensor.py +++ b/teslajsonpy/battery_sensor.py @@ -37,6 +37,14 @@ def __init__(self, data: Dict, controller) -> None: async def async_update(self, wake_if_asleep=False, force=False) -> None: """Update the battery state.""" await super().async_update(wake_if_asleep=wake_if_asleep) + self.refresh() + + def refresh(self) -> None: + """Refresh data. + + This assumes the controller has already been updated + """ + super().refresh() data = self._controller.get_charging_params(self._id) if data: self.__battery_level = data["battery_level"] @@ -100,6 +108,14 @@ def __init__(self, data: Dict, controller) -> None: async def async_update(self, wake_if_asleep=False, force=False) -> None: """Update the battery range state.""" await super().async_update(wake_if_asleep=wake_if_asleep) + self.refresh() + + def refresh(self) -> None: + """Refresh data. + + This assumes the controller has already been updated + """ + super().refresh() 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 b2147f73..1db093c3 100644 --- a/teslajsonpy/binary_sensor.py +++ b/teslajsonpy/binary_sensor.py @@ -94,6 +94,14 @@ def __init__(self, data: Dict, controller): async def async_update(self, wake_if_asleep=False, force=False) -> None: """Update the parking brake sensor.""" await super().async_update(wake_if_asleep=wake_if_asleep) + self.refresh() + + def refresh(self) -> None: + """Refresh data. + + This assumes the controller has already been updated + """ + super().refresh() data = self._controller.get_drive_params(self._id) if data: self.attrs["shift_state"] = ( @@ -142,6 +150,14 @@ def __init__(self, data, controller): async def async_update(self, wake_if_asleep=False, force=False) -> None: """Update the charger connection sensor.""" await super().async_update(wake_if_asleep=wake_if_asleep) + self.refresh() + + def refresh(self) -> None: + """Refresh data. + + This assumes the controller has already been updated + """ + super().refresh() data = self._controller.get_charging_params(self._id) if data: self.attrs["charging_state"] = data["charging_state"] @@ -182,6 +198,14 @@ def __init__(self, data: Dict, controller) -> None: async def async_update(self, wake_if_asleep=False, force=False) -> None: """Update the battery state.""" await super().async_update(wake_if_asleep=wake_if_asleep) + self.refresh() + + def refresh(self) -> None: + """Refresh data. + + This assumes the controller has already been updated + """ + super().refresh() self.__online_state = self._controller.car_online[self._vin] self.attrs["state"] = self._controller.car_state[self._vin].get("state") @@ -211,6 +235,14 @@ def __init__(self, data: Dict, controller) -> None: async def async_update(self, wake_if_asleep=False, force=False) -> None: """Update the battery state.""" await super().async_update(wake_if_asleep=wake_if_asleep) + self.refresh() + + def refresh(self) -> None: + """Refresh data. + + This assumes the controller has already been updated + """ + super().refresh() self.attrs = ( self.device_state_attributes.copy() if self.device_state_attributes else {} ) diff --git a/teslajsonpy/charger.py b/teslajsonpy/charger.py index 819c0b7c..33cfcec1 100644 --- a/teslajsonpy/charger.py +++ b/teslajsonpy/charger.py @@ -42,6 +42,14 @@ def __init__(self, data, controller): async def async_update(self, wake_if_asleep=False, force=False) -> None: """Update the charging state of the Tesla Vehicle.""" await super().async_update(wake_if_asleep=wake_if_asleep) + self.refresh() + + def refresh(self) -> None: + """Refresh data. + + This assumes the controller has already been updated + """ + super().refresh() 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) @@ -97,6 +105,14 @@ def __init__(self, data, controller): async def async_update(self, wake_if_asleep=False, force=False) -> None: """Update the status of the range setting.""" await super().async_update(wake_if_asleep=wake_if_asleep) + self.refresh() + + def refresh(self) -> None: + """Refresh data. + + This assumes the controller has already been updated + """ + super().refresh() 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) @@ -165,6 +181,14 @@ def __init__(self, data: Dict, controller) -> None: async def async_update(self, wake_if_asleep=False, force=False) -> None: """Update the battery state.""" await super().async_update(wake_if_asleep=wake_if_asleep) + self.refresh() + + def refresh(self) -> None: + """Refresh data. + + This assumes the controller has already been updated + """ + super().refresh() 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 da975032..4514936b 100644 --- a/teslajsonpy/climate.py +++ b/teslajsonpy/climate.py @@ -75,6 +75,14 @@ def get_fan_status(self): async def async_update(self, wake_if_asleep=False, force=False) -> None: """Update the HVAC state.""" await super().async_update(wake_if_asleep=wake_if_asleep, force=force) + self.refresh() + + def refresh(self) -> None: + """Refresh data. + + This assumes the controller has already been updated + """ + super().refresh() data = self._controller.get_climate_params(self._id) if data: last_update = self._controller.get_last_update_time(self._id) @@ -222,6 +230,14 @@ def get_outside_temp(self): async def async_update(self, wake_if_asleep=False, force=False) -> None: """Update the temperature.""" await super().async_update(wake_if_asleep=wake_if_asleep) + self.refresh() + + def refresh(self) -> None: + """Refresh data. + + This assumes the controller has already been updated + """ + super().refresh() data = self._controller.get_climate_params(self._id) if data: self.__inside_temp = ( diff --git a/teslajsonpy/gps.py b/teslajsonpy/gps.py index 2b11bb6a..269b1ede 100644 --- a/teslajsonpy/gps.py +++ b/teslajsonpy/gps.py @@ -60,6 +60,14 @@ def get_location(self): async def async_update(self, wake_if_asleep=False, force=False) -> None: """Update the current GPS location.""" await super().async_update(wake_if_asleep=wake_if_asleep) + self.refresh() + + def refresh(self) -> None: + """Refresh data. + + This assumes the controller has already been updated + """ + super().refresh() data = self._controller.get_drive_params(self._id) if data: if data["native_location_supported"]: @@ -115,6 +123,14 @@ def __init__(self, data, controller): async def async_update(self, wake_if_asleep=False, force=False) -> None: """Update the odometer and the unit of measurement based on GUI.""" await super().async_update(wake_if_asleep=wake_if_asleep) + self.refresh() + + def refresh(self) -> None: + """Refresh data. + + This assumes the controller has already been updated + """ + super().refresh() 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 370d9fe6..fedb68ad 100644 --- a/teslajsonpy/lock.py +++ b/teslajsonpy/lock.py @@ -47,6 +47,14 @@ def __init__(self, data, controller): async def async_update(self, wake_if_asleep=False, force=False) -> None: """Update the lock state.""" await super().async_update(wake_if_asleep=wake_if_asleep) + self.refresh() + + def refresh(self) -> None: + """Refresh data. + + This assumes the controller has already been updated + """ + super().refresh() 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) @@ -117,6 +125,14 @@ def __init__(self, data, controller): async def async_update(self, wake_if_asleep=False, force=False) -> None: """Update state of the charger lock.""" await super().async_update(wake_if_asleep=wake_if_asleep) + self.refresh() + + def refresh(self) -> None: + """Refresh data. + + This assumes the controller has already been updated + """ + super().refresh() 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/sentry_mode.py b/teslajsonpy/sentry_mode.py index d37006ad..6bd7e990 100644 --- a/teslajsonpy/sentry_mode.py +++ b/teslajsonpy/sentry_mode.py @@ -45,6 +45,14 @@ def __init__(self, data, controller): async def async_update(self, wake_if_asleep=False, force=False): """Update the sentry mode of the vehicle.""" await super().async_update(wake_if_asleep=wake_if_asleep) + self.refresh() + + def refresh(self) -> None: + """Refresh data. + + This assumes the controller has already been updated + """ + super().refresh() 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) diff --git a/teslajsonpy/trunk.py b/teslajsonpy/trunk.py index cec112a6..723f3a3a 100644 --- a/teslajsonpy/trunk.py +++ b/teslajsonpy/trunk.py @@ -37,6 +37,14 @@ def __init__(self, data, controller): async def async_update(self, wake_if_asleep=False, force=False) -> None: """Update the rear trunk state.""" await super().async_update(wake_if_asleep=wake_if_asleep, force=force) + self.refresh() + + def refresh(self) -> None: + """Refresh data. + + This assumes the controller has already been updated + """ + super().refresh() 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) @@ -97,6 +105,14 @@ def __init__(self, data, controller): async def async_update(self, wake_if_asleep=False, force=False) -> None: """Update the front trunk (frunk) state.""" await super().async_update(wake_if_asleep=wake_if_asleep, force=force) + self.refresh() + + def refresh(self) -> None: + """Refresh data. + + This assumes the controller has already been updated + """ + super().refresh() 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) diff --git a/teslajsonpy/vehicle.py b/teslajsonpy/vehicle.py index caa9dcd4..26141a58 100644 --- a/teslajsonpy/vehicle.py +++ b/teslajsonpy/vehicle.py @@ -122,10 +122,21 @@ def assumed_state(self) -> bool: async def async_update( self, wake_if_asleep: bool = False, force: bool = False ) -> None: - """Update the vehicle data.""" + """Update the vehicle data. + + This function will call a controller update. + """ await self._controller.update( self.id(), wake_if_asleep=wake_if_asleep, force=force ) + self.refresh() + + def refresh(self) -> None: + """Refresh the vehicle data. + + This assumes the controller has already been updated. This should be + called by inherited classes so the overall vehicle information is updated. + """ state = self._controller.get_state_params(self.id()) if state and "car_version" in state: self._car_version = state["car_version"] From f1f5994da0c57c9eaa49a9216f2b1f164bbd43a8 Mon Sep 17 00:00:00 2001 From: "Alan D. Tse" Date: Tue, 28 Jul 2020 22:03:54 -0700 Subject: [PATCH 2/3] refactor: reorganize homeassistant specific files --- teslajsonpy/__init__.py | 20 ++++++------- teslajsonpy/connection.py | 2 +- teslajsonpy/controller.py | 28 +++++++++---------- teslajsonpy/homeassistant/__init__.py | 6 ++++ .../{ => homeassistant}/battery_sensor.py | 2 +- .../{ => homeassistant}/binary_sensor.py | 2 +- teslajsonpy/{ => homeassistant}/charger.py | 2 +- teslajsonpy/{ => homeassistant}/climate.py | 2 +- teslajsonpy/{ => homeassistant}/gps.py | 2 +- teslajsonpy/{ => homeassistant}/lock.py | 2 +- .../{ => homeassistant}/sentry_mode.py | 2 +- teslajsonpy/{ => homeassistant}/trunk.py | 3 +- teslajsonpy/{ => homeassistant}/vehicle.py | 0 .../{unit_tests => }/test_tesla_exception.py | 0 tests/unit_tests/homeassistant/__init__.py | 7 +++++ .../test_battery_sensor.py | 6 ++-- .../test_charger_connection_sensor.py | 6 ++-- .../{ => homeassistant}/test_charger_lock.py | 6 ++-- .../test_charger_switch.py | 6 ++-- .../test_charging_sensor.py | 6 ++-- .../{ => homeassistant}/test_climate.py | 2 +- .../{ => homeassistant}/test_frunk_lock.py | 6 ++-- .../{ => homeassistant}/test_gps_tracker.py | 6 ++-- .../{ => homeassistant}/test_lock.py | 6 ++-- .../test_odometer_sensor.py | 6 ++-- .../{ => homeassistant}/test_online_sensor.py | 6 ++-- .../test_parking_sensor.py | 6 ++-- .../{ => homeassistant}/test_range_sensor.py | 6 ++-- .../{ => homeassistant}/test_range_switch.py | 6 ++-- .../test_sentry_mode_switch.py | 6 ++-- .../{ => homeassistant}/test_temp_sensor.py | 6 ++-- .../{ => homeassistant}/test_trunk_lock.py | 6 ++-- .../test_vehicle_device.py | 6 ++-- 33 files changed, 98 insertions(+), 86 deletions(-) create mode 100644 teslajsonpy/homeassistant/__init__.py rename teslajsonpy/{ => homeassistant}/battery_sensor.py (98%) rename teslajsonpy/{ => homeassistant}/binary_sensor.py (99%) rename teslajsonpy/{ => homeassistant}/charger.py (99%) rename teslajsonpy/{ => homeassistant}/climate.py (99%) rename teslajsonpy/{ => homeassistant}/gps.py (98%) rename teslajsonpy/{ => homeassistant}/lock.py (98%) rename teslajsonpy/{ => homeassistant}/sentry_mode.py (98%) rename teslajsonpy/{ => homeassistant}/trunk.py (98%) rename teslajsonpy/{ => homeassistant}/vehicle.py (100%) rename tests/{unit_tests => }/test_tesla_exception.py (100%) create mode 100644 tests/unit_tests/homeassistant/__init__.py rename tests/unit_tests/{ => homeassistant}/test_battery_sensor.py (98%) rename tests/unit_tests/{ => homeassistant}/test_charger_connection_sensor.py (96%) rename tests/unit_tests/{ => homeassistant}/test_charger_lock.py (98%) rename tests/unit_tests/{ => homeassistant}/test_charger_switch.py (98%) rename tests/unit_tests/{ => homeassistant}/test_charging_sensor.py (98%) rename tests/unit_tests/{ => homeassistant}/test_climate.py (99%) rename tests/unit_tests/{ => homeassistant}/test_frunk_lock.py (98%) rename tests/unit_tests/{ => homeassistant}/test_gps_tracker.py (98%) rename tests/unit_tests/{ => homeassistant}/test_lock.py (98%) rename tests/unit_tests/{ => homeassistant}/test_odometer_sensor.py (98%) rename tests/unit_tests/{ => homeassistant}/test_online_sensor.py (97%) rename tests/unit_tests/{ => homeassistant}/test_parking_sensor.py (96%) rename tests/unit_tests/{ => homeassistant}/test_range_sensor.py (98%) rename tests/unit_tests/{ => homeassistant}/test_range_switch.py (98%) rename tests/unit_tests/{ => homeassistant}/test_sentry_mode_switch.py (99%) rename tests/unit_tests/{ => homeassistant}/test_temp_sensor.py (96%) rename tests/unit_tests/{ => homeassistant}/test_trunk_lock.py (98%) rename tests/unit_tests/{ => homeassistant}/test_vehicle_device.py (98%) diff --git a/teslajsonpy/__init__.py b/teslajsonpy/__init__.py index 6f8f0196..20a51791 100644 --- a/teslajsonpy/__init__.py +++ b/teslajsonpy/__init__.py @@ -5,20 +5,20 @@ For more details about this api, please refer to the documentation at https://github.com/zabuldon/teslajsonpy """ -from teslajsonpy.battery_sensor import Battery, Range -from teslajsonpy.binary_sensor import ( +from teslajsonpy.controller import Controller +from teslajsonpy.exceptions import TeslaException, UnknownPresetMode +from teslajsonpy.homeassistant.battery_sensor import Battery, Range +from teslajsonpy.homeassistant.binary_sensor import ( ChargerConnectionSensor, OnlineSensor, ParkingSensor, ) -from teslajsonpy.charger import ChargerSwitch, ChargingSensor, RangeSwitch -from teslajsonpy.climate import Climate, TempSensor -from teslajsonpy.controller import Controller -from teslajsonpy.exceptions import TeslaException, UnknownPresetMode -from teslajsonpy.gps import GPS, Odometer -from teslajsonpy.lock import Lock -from teslajsonpy.sentry_mode import SentryModeSwitch -from teslajsonpy.trunk import TrunkLock, FrunkLock +from teslajsonpy.homeassistant.charger import ChargerSwitch, ChargingSensor, RangeSwitch +from teslajsonpy.homeassistant.climate import Climate, TempSensor +from teslajsonpy.homeassistant.gps import GPS, Odometer +from teslajsonpy.homeassistant.lock import Lock +from teslajsonpy.homeassistant.sentry_mode import SentryModeSwitch +from teslajsonpy.homeassistant.trunk import FrunkLock, TrunkLock from .__version__ import __version__ diff --git a/teslajsonpy/connection.py b/teslajsonpy/connection.py index a507faf1..ff24cff5 100644 --- a/teslajsonpy/connection.py +++ b/teslajsonpy/connection.py @@ -16,8 +16,8 @@ import aiohttp from yarl import URL -from teslajsonpy.exceptions import IncompleteCredentials, TeslaException from teslajsonpy.const import DRIVING_INTERVAL, WEBSOCKET_TIMEOUT +from teslajsonpy.exceptions import IncompleteCredentials, TeslaException _LOGGER = logging.getLogger(__name__) diff --git a/teslajsonpy/controller.py b/teslajsonpy/controller.py index 01807cb7..ef51eb41 100644 --- a/teslajsonpy/controller.py +++ b/teslajsonpy/controller.py @@ -10,19 +10,10 @@ import time from typing import Callable, Optional, Text, Tuple +from aiohttp import ClientConnectorError import backoff import wrapt -from aiohttp import ClientConnectorError -from teslajsonpy.battery_sensor import Battery, Range -from teslajsonpy.binary_sensor import ( - ChargerConnectionSensor, - OnlineSensor, - ParkingSensor, - UpdateSensor, -) -from teslajsonpy.charger import ChargerSwitch, ChargingSensor, RangeSwitch -from teslajsonpy.climate import Climate, TempSensor from teslajsonpy.connection import Connection from teslajsonpy.const import ( DRIVING_INTERVAL, @@ -31,10 +22,19 @@ SLEEP_INTERVAL, ) from teslajsonpy.exceptions import RetryLimitError, TeslaException -from teslajsonpy.gps import GPS, Odometer -from teslajsonpy.lock import ChargerLock, Lock -from teslajsonpy.sentry_mode import SentryModeSwitch -from teslajsonpy.trunk import TrunkLock, FrunkLock +from teslajsonpy.homeassistant.battery_sensor import Battery, Range +from teslajsonpy.homeassistant.binary_sensor import ( + ChargerConnectionSensor, + OnlineSensor, + ParkingSensor, + UpdateSensor, +) +from teslajsonpy.homeassistant.charger import ChargerSwitch, ChargingSensor, RangeSwitch +from teslajsonpy.homeassistant.climate import Climate, TempSensor +from teslajsonpy.homeassistant.gps import GPS, Odometer +from teslajsonpy.homeassistant.lock import ChargerLock, Lock +from teslajsonpy.homeassistant.sentry_mode import SentryModeSwitch +from teslajsonpy.homeassistant.trunk import FrunkLock, TrunkLock _LOGGER = logging.getLogger(__name__) diff --git a/teslajsonpy/homeassistant/__init__.py b/teslajsonpy/homeassistant/__init__.py new file mode 100644 index 00000000..ce17bb83 --- /dev/null +++ b/teslajsonpy/homeassistant/__init__.py @@ -0,0 +1,6 @@ +""" +Python Package for controlling Tesla API. + +For more details about this api, please refer to the documentation at +https://github.com/zabuldon/teslajsonpy +""" diff --git a/teslajsonpy/battery_sensor.py b/teslajsonpy/homeassistant/battery_sensor.py similarity index 98% rename from teslajsonpy/battery_sensor.py rename to teslajsonpy/homeassistant/battery_sensor.py index 4e2afad2..0b6be00a 100644 --- a/teslajsonpy/battery_sensor.py +++ b/teslajsonpy/homeassistant/battery_sensor.py @@ -7,7 +7,7 @@ """ from typing import Dict, Optional, Text -from teslajsonpy.vehicle import VehicleDevice +from teslajsonpy.homeassistant.vehicle import VehicleDevice class Battery(VehicleDevice): diff --git a/teslajsonpy/binary_sensor.py b/teslajsonpy/homeassistant/binary_sensor.py similarity index 99% rename from teslajsonpy/binary_sensor.py rename to teslajsonpy/homeassistant/binary_sensor.py index 1db093c3..a7fa447f 100644 --- a/teslajsonpy/binary_sensor.py +++ b/teslajsonpy/homeassistant/binary_sensor.py @@ -7,8 +7,8 @@ """ from typing import Dict, Optional, Text -from teslajsonpy.vehicle import VehicleDevice from teslajsonpy.const import RELEASE_NOTES_URL +from teslajsonpy.homeassistant.vehicle import VehicleDevice class BinarySensor(VehicleDevice): diff --git a/teslajsonpy/charger.py b/teslajsonpy/homeassistant/charger.py similarity index 99% rename from teslajsonpy/charger.py rename to teslajsonpy/homeassistant/charger.py index 33cfcec1..adba78f4 100644 --- a/teslajsonpy/charger.py +++ b/teslajsonpy/homeassistant/charger.py @@ -8,7 +8,7 @@ import time from typing import Dict, Optional, Text -from teslajsonpy.vehicle import VehicleDevice +from teslajsonpy.homeassistant.vehicle import VehicleDevice class ChargerSwitch(VehicleDevice): diff --git a/teslajsonpy/climate.py b/teslajsonpy/homeassistant/climate.py similarity index 99% rename from teslajsonpy/climate.py rename to teslajsonpy/homeassistant/climate.py index 4514936b..487546cd 100644 --- a/teslajsonpy/climate.py +++ b/teslajsonpy/homeassistant/climate.py @@ -8,8 +8,8 @@ import time from typing import List, Optional, Text -from teslajsonpy.vehicle import VehicleDevice from teslajsonpy.exceptions import UnknownPresetMode +from teslajsonpy.homeassistant.vehicle import VehicleDevice class Climate(VehicleDevice): diff --git a/teslajsonpy/gps.py b/teslajsonpy/homeassistant/gps.py similarity index 98% rename from teslajsonpy/gps.py rename to teslajsonpy/homeassistant/gps.py index 269b1ede..3a4b0630 100644 --- a/teslajsonpy/gps.py +++ b/teslajsonpy/homeassistant/gps.py @@ -7,7 +7,7 @@ """ from typing import Optional, Text -from teslajsonpy.vehicle import VehicleDevice +from teslajsonpy.homeassistant.vehicle import VehicleDevice class GPS(VehicleDevice): diff --git a/teslajsonpy/lock.py b/teslajsonpy/homeassistant/lock.py similarity index 98% rename from teslajsonpy/lock.py rename to teslajsonpy/homeassistant/lock.py index fedb68ad..a678d798 100644 --- a/teslajsonpy/lock.py +++ b/teslajsonpy/homeassistant/lock.py @@ -7,7 +7,7 @@ """ import time -from teslajsonpy.vehicle import VehicleDevice +from teslajsonpy.homeassistant.vehicle import VehicleDevice class Lock(VehicleDevice): diff --git a/teslajsonpy/sentry_mode.py b/teslajsonpy/homeassistant/sentry_mode.py similarity index 98% rename from teslajsonpy/sentry_mode.py rename to teslajsonpy/homeassistant/sentry_mode.py index 6bd7e990..981b93d2 100644 --- a/teslajsonpy/sentry_mode.py +++ b/teslajsonpy/homeassistant/sentry_mode.py @@ -7,7 +7,7 @@ """ import time -from teslajsonpy.vehicle import VehicleDevice +from teslajsonpy.homeassistant.vehicle import VehicleDevice class SentryModeSwitch(VehicleDevice): diff --git a/teslajsonpy/trunk.py b/teslajsonpy/homeassistant/trunk.py similarity index 98% rename from teslajsonpy/trunk.py rename to teslajsonpy/homeassistant/trunk.py index 723f3a3a..4655b528 100644 --- a/teslajsonpy/trunk.py +++ b/teslajsonpy/homeassistant/trunk.py @@ -6,10 +6,9 @@ https://github.com/zabuldon/teslajsonpy """ import time - from typing import Text -from teslajsonpy.vehicle import VehicleDevice +from teslajsonpy.homeassistant.vehicle import VehicleDevice class TrunkLock(VehicleDevice): diff --git a/teslajsonpy/vehicle.py b/teslajsonpy/homeassistant/vehicle.py similarity index 100% rename from teslajsonpy/vehicle.py rename to teslajsonpy/homeassistant/vehicle.py diff --git a/tests/unit_tests/test_tesla_exception.py b/tests/test_tesla_exception.py similarity index 100% rename from tests/unit_tests/test_tesla_exception.py rename to tests/test_tesla_exception.py diff --git a/tests/unit_tests/homeassistant/__init__.py b/tests/unit_tests/homeassistant/__init__.py new file mode 100644 index 00000000..2a978c16 --- /dev/null +++ b/tests/unit_tests/homeassistant/__init__.py @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: Apache-2.0 +""" +Python Package for controlling Tesla API. + +For more details about this api, please refer to the documentation at +https://github.com/zabuldon/teslajsonpy +""" diff --git a/tests/unit_tests/test_battery_sensor.py b/tests/unit_tests/homeassistant/test_battery_sensor.py similarity index 98% rename from tests/unit_tests/test_battery_sensor.py rename to tests/unit_tests/homeassistant/test_battery_sensor.py index 4b515454..d7b18c38 100644 --- a/tests/unit_tests/test_battery_sensor.py +++ b/tests/unit_tests/homeassistant/test_battery_sensor.py @@ -2,10 +2,10 @@ import pytest -from tests.tesla_mock import TeslaMock - from teslajsonpy.controller import Controller -from teslajsonpy.battery_sensor import Battery +from teslajsonpy.homeassistant.battery_sensor import Battery + +from tests.tesla_mock import TeslaMock def test_has_battery(monkeypatch): diff --git a/tests/unit_tests/test_charger_connection_sensor.py b/tests/unit_tests/homeassistant/test_charger_connection_sensor.py similarity index 96% rename from tests/unit_tests/test_charger_connection_sensor.py rename to tests/unit_tests/homeassistant/test_charger_connection_sensor.py index f0eb746b..682a4730 100644 --- a/tests/unit_tests/test_charger_connection_sensor.py +++ b/tests/unit_tests/homeassistant/test_charger_connection_sensor.py @@ -2,10 +2,10 @@ import pytest -from tests.tesla_mock import TeslaMock - from teslajsonpy.controller import Controller -from teslajsonpy.binary_sensor import ChargerConnectionSensor +from teslajsonpy.homeassistant.binary_sensor import ChargerConnectionSensor + +from tests.tesla_mock import TeslaMock def test_has_battery(monkeypatch): diff --git a/tests/unit_tests/test_charger_lock.py b/tests/unit_tests/homeassistant/test_charger_lock.py similarity index 98% rename from tests/unit_tests/test_charger_lock.py rename to tests/unit_tests/homeassistant/test_charger_lock.py index 4c3545af..8d5dfade 100644 --- a/tests/unit_tests/test_charger_lock.py +++ b/tests/unit_tests/homeassistant/test_charger_lock.py @@ -2,10 +2,10 @@ import pytest -from tests.tesla_mock import TeslaMock - from teslajsonpy.controller import Controller -from teslajsonpy.lock import ChargerLock +from teslajsonpy.homeassistant.lock import ChargerLock + +from tests.tesla_mock import TeslaMock def test_has_battery(monkeypatch): diff --git a/tests/unit_tests/test_charger_switch.py b/tests/unit_tests/homeassistant/test_charger_switch.py similarity index 98% rename from tests/unit_tests/test_charger_switch.py rename to tests/unit_tests/homeassistant/test_charger_switch.py index 63905420..dbcd9cf1 100644 --- a/tests/unit_tests/test_charger_switch.py +++ b/tests/unit_tests/homeassistant/test_charger_switch.py @@ -2,10 +2,10 @@ import pytest -from tests.tesla_mock import TeslaMock - from teslajsonpy.controller import Controller -from teslajsonpy.charger import ChargerSwitch +from teslajsonpy.homeassistant.charger import ChargerSwitch + +from tests.tesla_mock import TeslaMock def test_has_battery(monkeypatch): diff --git a/tests/unit_tests/test_charging_sensor.py b/tests/unit_tests/homeassistant/test_charging_sensor.py similarity index 98% rename from tests/unit_tests/test_charging_sensor.py rename to tests/unit_tests/homeassistant/test_charging_sensor.py index 1eba1da5..f46646eb 100644 --- a/tests/unit_tests/test_charging_sensor.py +++ b/tests/unit_tests/homeassistant/test_charging_sensor.py @@ -2,10 +2,10 @@ import pytest -from tests.tesla_mock import TeslaMock - from teslajsonpy.controller import Controller -from teslajsonpy.charger import ChargingSensor +from teslajsonpy.homeassistant.charger import ChargingSensor + +from tests.tesla_mock import TeslaMock def test_has_battery(monkeypatch): diff --git a/tests/unit_tests/test_climate.py b/tests/unit_tests/homeassistant/test_climate.py similarity index 99% rename from tests/unit_tests/test_climate.py rename to tests/unit_tests/homeassistant/test_climate.py index e842bdb6..697e9403 100644 --- a/tests/unit_tests/test_climate.py +++ b/tests/unit_tests/homeassistant/test_climate.py @@ -2,9 +2,9 @@ import pytest -from teslajsonpy.climate import Climate from teslajsonpy.controller import Controller from teslajsonpy.exceptions import UnknownPresetMode +from teslajsonpy.homeassistant.climate import Climate from tests.tesla_mock import TeslaMock diff --git a/tests/unit_tests/test_frunk_lock.py b/tests/unit_tests/homeassistant/test_frunk_lock.py similarity index 98% rename from tests/unit_tests/test_frunk_lock.py rename to tests/unit_tests/homeassistant/test_frunk_lock.py index a73a6442..948c86c8 100644 --- a/tests/unit_tests/test_frunk_lock.py +++ b/tests/unit_tests/homeassistant/test_frunk_lock.py @@ -2,10 +2,10 @@ import pytest -from tests.tesla_mock import TeslaMock - from teslajsonpy.controller import Controller -from teslajsonpy.trunk import FrunkLock +from teslajsonpy.homeassistant.trunk import FrunkLock + +from tests.tesla_mock import TeslaMock def test_has_battery(monkeypatch): diff --git a/tests/unit_tests/test_gps_tracker.py b/tests/unit_tests/homeassistant/test_gps_tracker.py similarity index 98% rename from tests/unit_tests/test_gps_tracker.py rename to tests/unit_tests/homeassistant/test_gps_tracker.py index 17e28260..a6cf570d 100644 --- a/tests/unit_tests/test_gps_tracker.py +++ b/tests/unit_tests/homeassistant/test_gps_tracker.py @@ -2,10 +2,10 @@ import pytest -from tests.tesla_mock import TeslaMock - from teslajsonpy.controller import Controller -from teslajsonpy.gps import GPS +from teslajsonpy.homeassistant.gps import GPS + +from tests.tesla_mock import TeslaMock def test_has_battery(monkeypatch): diff --git a/tests/unit_tests/test_lock.py b/tests/unit_tests/homeassistant/test_lock.py similarity index 98% rename from tests/unit_tests/test_lock.py rename to tests/unit_tests/homeassistant/test_lock.py index e20f2ce8..47dab9bb 100644 --- a/tests/unit_tests/test_lock.py +++ b/tests/unit_tests/homeassistant/test_lock.py @@ -2,10 +2,10 @@ import pytest -from tests.tesla_mock import TeslaMock - from teslajsonpy.controller import Controller -from teslajsonpy.lock import Lock +from teslajsonpy.homeassistant.lock import Lock + +from tests.tesla_mock import TeslaMock def test_has_battery(monkeypatch): diff --git a/tests/unit_tests/test_odometer_sensor.py b/tests/unit_tests/homeassistant/test_odometer_sensor.py similarity index 98% rename from tests/unit_tests/test_odometer_sensor.py rename to tests/unit_tests/homeassistant/test_odometer_sensor.py index 637071b3..ad9a131e 100644 --- a/tests/unit_tests/test_odometer_sensor.py +++ b/tests/unit_tests/homeassistant/test_odometer_sensor.py @@ -2,10 +2,10 @@ import pytest -from tests.tesla_mock import TeslaMock - from teslajsonpy.controller import Controller -from teslajsonpy.gps import Odometer +from teslajsonpy.homeassistant.gps import Odometer + +from tests.tesla_mock import TeslaMock def test_has_battery(monkeypatch): diff --git a/tests/unit_tests/test_online_sensor.py b/tests/unit_tests/homeassistant/test_online_sensor.py similarity index 97% rename from tests/unit_tests/test_online_sensor.py rename to tests/unit_tests/homeassistant/test_online_sensor.py index 47ab795f..d9cf51c6 100644 --- a/tests/unit_tests/test_online_sensor.py +++ b/tests/unit_tests/homeassistant/test_online_sensor.py @@ -2,10 +2,10 @@ import pytest -from tests.tesla_mock import TeslaMock - from teslajsonpy.controller import Controller -from teslajsonpy.binary_sensor import OnlineSensor +from teslajsonpy.homeassistant.binary_sensor import OnlineSensor + +from tests.tesla_mock import TeslaMock def test_has_battery(monkeypatch): diff --git a/tests/unit_tests/test_parking_sensor.py b/tests/unit_tests/homeassistant/test_parking_sensor.py similarity index 96% rename from tests/unit_tests/test_parking_sensor.py rename to tests/unit_tests/homeassistant/test_parking_sensor.py index b31ff2fe..02fd1b67 100644 --- a/tests/unit_tests/test_parking_sensor.py +++ b/tests/unit_tests/homeassistant/test_parking_sensor.py @@ -2,10 +2,10 @@ import pytest -from tests.tesla_mock import TeslaMock - from teslajsonpy.controller import Controller -from teslajsonpy.binary_sensor import ParkingSensor +from teslajsonpy.homeassistant.binary_sensor import ParkingSensor + +from tests.tesla_mock import TeslaMock def test_has_battery(monkeypatch): diff --git a/tests/unit_tests/test_range_sensor.py b/tests/unit_tests/homeassistant/test_range_sensor.py similarity index 98% rename from tests/unit_tests/test_range_sensor.py rename to tests/unit_tests/homeassistant/test_range_sensor.py index 2f12130f..4d56c861 100644 --- a/tests/unit_tests/test_range_sensor.py +++ b/tests/unit_tests/homeassistant/test_range_sensor.py @@ -2,10 +2,10 @@ import pytest -from tests.tesla_mock import TeslaMock - from teslajsonpy.controller import Controller -from teslajsonpy.battery_sensor import Range +from teslajsonpy.homeassistant.battery_sensor import Range + +from tests.tesla_mock import TeslaMock def test_has_battery(monkeypatch): diff --git a/tests/unit_tests/test_range_switch.py b/tests/unit_tests/homeassistant/test_range_switch.py similarity index 98% rename from tests/unit_tests/test_range_switch.py rename to tests/unit_tests/homeassistant/test_range_switch.py index e8370880..f01e6651 100644 --- a/tests/unit_tests/test_range_switch.py +++ b/tests/unit_tests/homeassistant/test_range_switch.py @@ -2,10 +2,10 @@ import pytest -from tests.tesla_mock import TeslaMock - from teslajsonpy.controller import Controller -from teslajsonpy.charger import RangeSwitch +from teslajsonpy.homeassistant.charger import RangeSwitch + +from tests.tesla_mock import TeslaMock def test_has_battery(monkeypatch): diff --git a/tests/unit_tests/test_sentry_mode_switch.py b/tests/unit_tests/homeassistant/test_sentry_mode_switch.py similarity index 99% rename from tests/unit_tests/test_sentry_mode_switch.py rename to tests/unit_tests/homeassistant/test_sentry_mode_switch.py index 0025c04b..f395923f 100644 --- a/tests/unit_tests/test_sentry_mode_switch.py +++ b/tests/unit_tests/homeassistant/test_sentry_mode_switch.py @@ -2,10 +2,10 @@ import pytest -from tests.tesla_mock import TeslaMock - from teslajsonpy.controller import Controller -from teslajsonpy.sentry_mode import SentryModeSwitch +from teslajsonpy.homeassistant.sentry_mode import SentryModeSwitch + +from tests.tesla_mock import TeslaMock def test_has_battery(monkeypatch): diff --git a/tests/unit_tests/test_temp_sensor.py b/tests/unit_tests/homeassistant/test_temp_sensor.py similarity index 96% rename from tests/unit_tests/test_temp_sensor.py rename to tests/unit_tests/homeassistant/test_temp_sensor.py index 4de9bc25..e7306a98 100644 --- a/tests/unit_tests/test_temp_sensor.py +++ b/tests/unit_tests/homeassistant/test_temp_sensor.py @@ -2,10 +2,10 @@ import pytest -from tests.tesla_mock import TeslaMock - from teslajsonpy.controller import Controller -from teslajsonpy.climate import TempSensor +from teslajsonpy.homeassistant.climate import TempSensor + +from tests.tesla_mock import TeslaMock def test_has_battery(monkeypatch): diff --git a/tests/unit_tests/test_trunk_lock.py b/tests/unit_tests/homeassistant/test_trunk_lock.py similarity index 98% rename from tests/unit_tests/test_trunk_lock.py rename to tests/unit_tests/homeassistant/test_trunk_lock.py index f7026fc2..2437c4f0 100644 --- a/tests/unit_tests/test_trunk_lock.py +++ b/tests/unit_tests/homeassistant/test_trunk_lock.py @@ -2,10 +2,10 @@ import pytest -from tests.tesla_mock import TeslaMock - from teslajsonpy.controller import Controller -from teslajsonpy.trunk import TrunkLock +from teslajsonpy.homeassistant.trunk import TrunkLock + +from tests.tesla_mock import TeslaMock def test_has_battery(monkeypatch): diff --git a/tests/unit_tests/test_vehicle_device.py b/tests/unit_tests/homeassistant/test_vehicle_device.py similarity index 98% rename from tests/unit_tests/test_vehicle_device.py rename to tests/unit_tests/homeassistant/test_vehicle_device.py index 5dbf5800..af8dc322 100644 --- a/tests/unit_tests/test_vehicle_device.py +++ b/tests/unit_tests/homeassistant/test_vehicle_device.py @@ -2,10 +2,10 @@ import pytest -from tests.tesla_mock import TeslaMock - from teslajsonpy.controller import Controller -from teslajsonpy.vehicle import VehicleDevice +from teslajsonpy.homeassistant.vehicle import VehicleDevice + +from tests.tesla_mock import TeslaMock def test_is_armable(monkeypatch): From 1a1b0fe4c033ed72ebc099d0aa7e9f431a3acf6e Mon Sep 17 00:00:00 2001 From: "Alan D. Tse" Date: Tue, 28 Jul 2020 22:06:46 -0700 Subject: [PATCH 3/3] fix: expose UpdateSensor --- teslajsonpy/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/teslajsonpy/__init__.py b/teslajsonpy/__init__.py index 20a51791..085c6cf2 100644 --- a/teslajsonpy/__init__.py +++ b/teslajsonpy/__init__.py @@ -12,6 +12,7 @@ ChargerConnectionSensor, OnlineSensor, ParkingSensor, + UpdateSensor, ) from teslajsonpy.homeassistant.charger import ChargerSwitch, ChargingSensor, RangeSwitch from teslajsonpy.homeassistant.climate import Climate, TempSensor @@ -29,6 +30,7 @@ "ChargingSensor", "OnlineSensor", "ParkingSensor", + "UpdateSensor", "ChargerSwitch", "RangeSwitch", "Climate",