tesla-fleet-api 0.9.9__py3-none-any.whl → 1.0.0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. tesla_fleet_api/__init__.py +7 -22
  2. tesla_fleet_api/const.py +1 -225
  3. tesla_fleet_api/exceptions.py +117 -0
  4. tesla_fleet_api/tesla/__init__.py +11 -0
  5. tesla_fleet_api/tesla/bluetooth.py +33 -0
  6. tesla_fleet_api/{charging.py → tesla/charging.py} +1 -1
  7. tesla_fleet_api/{energy.py → tesla/energysite.py} +41 -33
  8. tesla_fleet_api/{teslafleetapi.py → tesla/fleet.py} +8 -53
  9. tesla_fleet_api/{teslafleetoauth.py → tesla/oauth.py} +3 -4
  10. tesla_fleet_api/{partner.py → tesla/partner.py} +1 -1
  11. tesla_fleet_api/tesla/tesla.py +52 -0
  12. tesla_fleet_api/{user.py → tesla/user.py} +1 -1
  13. tesla_fleet_api/teslemetry/__init__.py +5 -0
  14. tesla_fleet_api/{teslemetry.py → teslemetry/teslemetry.py} +16 -25
  15. tesla_fleet_api/teslemetry/vehicle.py +73 -0
  16. tesla_fleet_api/tessie/__init__.py +5 -0
  17. tesla_fleet_api/{tessie.py → tessie/tessie.py} +17 -9
  18. tesla_fleet_api/tessie/vehicle.py +41 -0
  19. {tesla_fleet_api-0.9.9.dist-info → tesla_fleet_api-1.0.0.dist-info}/METADATA +3 -2
  20. tesla_fleet_api-1.0.0.dist-info/RECORD +24 -0
  21. tesla_fleet_api/energyspecific.py +0 -125
  22. tesla_fleet_api/pb2/__init__.py +0 -0
  23. tesla_fleet_api/pb2/__init__.pyi +0 -9
  24. tesla_fleet_api/pb2/car_server_pb2.py +0 -175
  25. tesla_fleet_api/pb2/car_server_pb2.pyi +0 -904
  26. tesla_fleet_api/pb2/common_pb2.py +0 -33
  27. tesla_fleet_api/pb2/common_pb2.pyi +0 -130
  28. tesla_fleet_api/pb2/errors_pb2.py +0 -17
  29. tesla_fleet_api/pb2/errors_pb2.pyi +0 -32
  30. tesla_fleet_api/pb2/keys_pb2.py +0 -15
  31. tesla_fleet_api/pb2/keys_pb2.pyi +0 -21
  32. tesla_fleet_api/pb2/managed_charging_pb2.py +0 -15
  33. tesla_fleet_api/pb2/managed_charging_pb2.pyi +0 -17
  34. tesla_fleet_api/pb2/signatures_pb2.py +0 -35
  35. tesla_fleet_api/pb2/signatures_pb2.pyi +0 -152
  36. tesla_fleet_api/pb2/universal_message_pb2.py +0 -30
  37. tesla_fleet_api/pb2/universal_message_pb2.pyi +0 -148
  38. tesla_fleet_api/pb2/vcsec_pb2.py +0 -79
  39. tesla_fleet_api/pb2/vcsec_pb2.pyi +0 -482
  40. tesla_fleet_api/pb2/vehicle_pb2.py +0 -125
  41. tesla_fleet_api/pb2/vehicle_pb2.pyi +0 -1183
  42. tesla_fleet_api/teslafleetopensource.py +0 -61
  43. tesla_fleet_api/vehicle.py +0 -878
  44. tesla_fleet_api/vehiclesigned.py +0 -1127
  45. tesla_fleet_api/vehiclespecific.py +0 -505
  46. tesla_fleet_api-0.9.9.dist-info/RECORD +0 -42
  47. {tesla_fleet_api-0.9.9.dist-info → tesla_fleet_api-1.0.0.dist-info}/LICENSE +0 -0
  48. {tesla_fleet_api-0.9.9.dist-info → tesla_fleet_api-1.0.0.dist-info}/WHEEL +0 -0
  49. {tesla_fleet_api-0.9.9.dist-info → tesla_fleet_api-1.0.0.dist-info}/top_level.txt +0 -0
@@ -2,26 +2,20 @@
2
2
 
3
3
  from json import dumps
4
4
  from typing import Any, Awaitable
5
- from os.path import exists
6
5
  import aiohttp
7
- import aiofiles
8
6
 
9
- # cryptography
10
- from cryptography.hazmat.primitives.asymmetric import ec
11
- from cryptography.hazmat.primitives import serialization
12
- from cryptography.hazmat.backends import default_backend
13
-
14
- from .exceptions import raise_for_status, InvalidRegion, LibraryError, ResponseError
15
- from .const import SERVERS, Method, LOGGER, VERSION
7
+ from .tesla import Tesla
8
+ from ..exceptions import raise_for_status, InvalidRegion, LibraryError, ResponseError
9
+ from ..const import SERVERS, Method, LOGGER, VERSION
16
10
  from .charging import Charging
17
- from .energy import Energy
11
+ from .energysite import EnergySites
18
12
  from .partner import Partner
19
13
  from .user import User
20
- from .vehicle import Vehicle
14
+ from .vehicle.vehicles import Vehicles
21
15
 
22
16
 
23
17
  # Based on https://developer.tesla.com/docs/fleet-api
24
- class TeslaFleetApi:
18
+ class TeslaFleetApi(Tesla):
25
19
  """Class describing the Tesla Fleet API."""
26
20
 
27
21
  access_token: str | None = None
@@ -30,7 +24,6 @@ class TeslaFleetApi:
30
24
  session: aiohttp.ClientSession
31
25
  headers: dict[str, str]
32
26
  refresh_hook: Awaitable | None = None
33
- private_key: ec.EllipticCurvePrivateKey | None = None
34
27
 
35
28
  def __init__(
36
29
  self,
@@ -63,13 +56,13 @@ class TeslaFleetApi:
63
56
  if charging_scope:
64
57
  self.charging = Charging(self)
65
58
  if energy_scope:
66
- self.energy = Energy(self)
59
+ self.energySites = EnergySites(self)
67
60
  if user_scope:
68
61
  self.user = User(self)
69
62
  if partner_scope:
70
63
  self.partner = Partner(self)
71
64
  if vehicle_scope:
72
- self.vehicle = Vehicle(self)
65
+ self.vehicles = Vehicles(self)
73
66
 
74
67
  async def find_server(self) -> str:
75
68
  """Find the server URL for the Tesla Fleet API."""
@@ -162,41 +155,3 @@ class TeslaFleetApi:
162
155
  Method.GET,
163
156
  "api/1/products",
164
157
  )
165
-
166
- async def get_private_key(
167
- self, path: str = "private_key.pem"
168
- ) -> ec.EllipticCurvePrivateKey:
169
- """Get or create the private key."""
170
- if not exists(path):
171
- self.private_key = ec.generate_private_key(
172
- ec.SECP256R1(), default_backend()
173
- )
174
- # save the key
175
- pem = self.private_key.private_bytes(
176
- encoding=serialization.Encoding.PEM,
177
- format=serialization.PrivateFormat.TraditionalOpenSSL,
178
- encryption_algorithm=serialization.NoEncryption(),
179
- )
180
- async with aiofiles.open(path, "wb") as key_file:
181
- await key_file.write(pem)
182
- else:
183
- try:
184
- async with aiofiles.open(path, "rb") as key_file:
185
- key_data = await key_file.read()
186
- value = serialization.load_pem_private_key(
187
- key_data, password=None, backend=default_backend()
188
- )
189
- except FileNotFoundError:
190
- raise FileNotFoundError(f"Private key file not found at {path}")
191
- except PermissionError:
192
- raise PermissionError(f"Permission denied when trying to read {path}")
193
-
194
- if not isinstance(value, ec.EllipticCurvePrivateKey):
195
- raise AssertionError("Loaded key is not an EllipticCurvePrivateKey")
196
- self.private_key = value
197
- return self.private_key
198
-
199
- @property
200
- def has_private_key(self) -> bool:
201
- """Check if the private key has been set."""
202
- return self.private_key is not None
@@ -2,16 +2,15 @@ from typing import Any
2
2
  import aiohttp
3
3
  import time
4
4
 
5
- from tesla_fleet_api.const import Method
6
- from .teslafleetapi import TeslaFleetApi
7
- from .const import Scope, SERVERS
5
+ from . import TeslaFleetApi
6
+ from ..const import Scope, SERVERS, Method
8
7
 
9
8
 
10
9
  class TeslaFleetOAuth(TeslaFleetApi):
11
10
  """Tesla Fleet OAuth API."""
12
11
 
13
12
  expires: int
14
- refresh_token: str
13
+ refresh_token: str | None
15
14
  redirect_uri: str | None
16
15
  _client_secret: str | None
17
16
 
@@ -1,5 +1,5 @@
1
1
  from typing import Any
2
- from .const import Method
2
+ from ..const import Method
3
3
 
4
4
 
5
5
  class Partner:
@@ -0,0 +1,52 @@
1
+ """Tesla Fleet API for Python."""
2
+
3
+ from os.path import exists
4
+ import aiofiles
5
+
6
+ # cryptography
7
+ from cryptography.hazmat.primitives.asymmetric import ec
8
+ from cryptography.hazmat.primitives import serialization
9
+ from cryptography.hazmat.backends import default_backend
10
+
11
+ class Tesla:
12
+ """Base class describing interactions with Tesla products."""
13
+
14
+ private_key: ec.EllipticCurvePrivateKey | None = None
15
+
16
+ async def get_private_key(
17
+ self, path: str = "private_key.pem"
18
+ ) -> ec.EllipticCurvePrivateKey:
19
+ """Get or create the private key."""
20
+ if not exists(path):
21
+ self.private_key = ec.generate_private_key(
22
+ ec.SECP256R1(), default_backend()
23
+ )
24
+ # save the key
25
+ pem = self.private_key.private_bytes(
26
+ encoding=serialization.Encoding.PEM,
27
+ format=serialization.PrivateFormat.TraditionalOpenSSL,
28
+ encryption_algorithm=serialization.NoEncryption(),
29
+ )
30
+ async with aiofiles.open(path, "wb") as key_file:
31
+ await key_file.write(pem)
32
+ else:
33
+ try:
34
+ async with aiofiles.open(path, "rb") as key_file:
35
+ key_data = await key_file.read()
36
+ value = serialization.load_pem_private_key(
37
+ key_data, password=None, backend=default_backend()
38
+ )
39
+ except FileNotFoundError:
40
+ raise FileNotFoundError(f"Private key file not found at {path}")
41
+ except PermissionError:
42
+ raise PermissionError(f"Permission denied when trying to read {path}")
43
+
44
+ if not isinstance(value, ec.EllipticCurvePrivateKey):
45
+ raise AssertionError("Loaded key is not an EllipticCurvePrivateKey")
46
+ self.private_key = value
47
+ return self.private_key
48
+
49
+ @property
50
+ def has_private_key(self) -> bool:
51
+ """Check if the private key has been set."""
52
+ return self.private_key is not None
@@ -1,5 +1,5 @@
1
1
  from typing import Any
2
- from .const import Method
2
+ from ..const import Method
3
3
 
4
4
 
5
5
  class User:
@@ -0,0 +1,5 @@
1
+ from .teslemetry import Teslemetry
2
+
3
+ __all__ = [
4
+ "Teslemetry",
5
+ ]
@@ -1,30 +1,32 @@
1
1
  from typing import Any
2
2
 
3
3
  import aiohttp
4
- from aiolimiter import AsyncLimiter
5
4
 
6
- from .const import LOGGER, Method
7
- from .teslafleetapi import TeslaFleetApi
5
+ from ..tesla.charging import Charging
6
+ from ..tesla.energysite import EnergySites
7
+ from ..tesla.user import User
8
+ from .vehicle import TeslemetryVehicles
9
+ from ..const import LOGGER, Method
10
+ from ..tesla import TeslaFleetApi
8
11
 
9
- # Rate limit should be global, even if multiple instances are created
10
- rate_limit = AsyncLimiter(5, 10)
12
+ class Teslemetry(TeslaFleetApi):
11
13
 
14
+ server = "https://api.teslemetry.com"
12
15
 
13
- class Teslemetry(TeslaFleetApi):
14
16
  def __init__(
15
17
  self,
16
18
  session: aiohttp.ClientSession,
17
19
  access_token: str,
18
20
  ):
19
21
  """Initialize the Teslemetry API."""
20
- super().__init__(
21
- session=session,
22
- access_token=access_token,
23
- server="https://api.teslemetry.com",
24
- user_scope=False,
25
- partner_scope=False,
26
- )
27
- self.rate_limit = rate_limit
22
+
23
+ self.session = session
24
+ self.access_token = access_token
25
+
26
+ self.charging = Charging(self)
27
+ self.energySites = EnergySites(self)
28
+ self.user = User(self)
29
+ self.vehicle = TeslemetryVehicles(self)
28
30
 
29
31
  async def ping(self) -> dict[str, bool]:
30
32
  """Send a ping."""
@@ -102,14 +104,3 @@ class Teslemetry(TeslaFleetApi):
102
104
  Method.GET,
103
105
  f"api/refresh/{vin}",
104
106
  )
105
-
106
- async def _request(
107
- self,
108
- method: Method,
109
- path: str,
110
- params: dict[str, Any] | None = None,
111
- json: dict[str, Any] | None = None,
112
- ) -> dict[str, Any]:
113
- """Send a request to the Teslemetry API."""
114
- async with rate_limit:
115
- return await super()._request(method, path, params, json)
@@ -0,0 +1,73 @@
1
+ from __future__ import annotations
2
+ from typing import TYPE_CHECKING, Any
3
+
4
+ from ..const import Method
5
+ from ..tesla.vehicle.proto.universal_message_pb2 import Domain
6
+ from ..tesla.vehicle.vehicle import Vehicle
7
+ from ..tesla.vehicle.vehicles import Vehicles
8
+ from ..tesla.vehicle.bluetooth import VehicleBluetooth
9
+ from ..tesla.vehicle.fleet import VehicleFleet
10
+
11
+ if TYPE_CHECKING:
12
+ from .teslemetry import Teslemetry
13
+
14
+ class TeslemetryVehicle(Vehicle):
15
+ """Teslemetry specific base vehicle."""
16
+ pass
17
+
18
+ class TeslemetryVehicleFleet(VehicleFleet):
19
+ """Teslemetry specific API vehicle."""
20
+
21
+ async def server_side_polling(
22
+ self, value: bool | None = None
23
+ ) -> bool | None:
24
+ """Get or set Auto mode."""
25
+ if value is True:
26
+ return (
27
+ await self._request(
28
+ Method.POST,
29
+ f"api/auto/{self.vin}",
30
+ )
31
+ ).get("response")
32
+ if value is False:
33
+ return (
34
+ await self._request(
35
+ Method.DELETE,
36
+ f"api/auto/{self.vin}",
37
+ )
38
+ ).get("response")
39
+ return (
40
+ await self._request(
41
+ Method.GET,
42
+ f"api/auto/{self.vin}",
43
+ )
44
+ ).get("response")
45
+
46
+ async def data_refresh(self) -> dict[str, Any]:
47
+ """Force a refresh of the vehicle data."""
48
+ return await self._request(
49
+ Method.GET,
50
+ f"api/refresh/{self.vin}",
51
+ )
52
+
53
+
54
+ class TeslemetryVehicles(Vehicles):
55
+ """Class containing and creating vehicles."""
56
+
57
+ def create(self, vin: str) -> TeslemetryVehicleFleet:
58
+ """Creates a specific vehicle."""
59
+ return self.createFleet(vin)
60
+
61
+ def createFleet(self, vin: str) -> TeslemetryVehicleFleet:
62
+ """Creates a specific vehicle."""
63
+ vehicle = TeslemetryVehicleFleet(self._parent, vin)
64
+ self[vin] = vehicle
65
+ return vehicle
66
+
67
+ def createSigned(self, vin: str):
68
+ """Creates a specific vehicle."""
69
+ raise NotImplementedError("Signing is handled by Teslemetry server-side")
70
+
71
+ def createBluetooth(self, vin: str):
72
+ """Creates a specific vehicle."""
73
+ raise NotImplementedError("Bluetooth is only handled locally")
@@ -0,0 +1,5 @@
1
+ from .tessie import Tessie
2
+
3
+ __all__ = [
4
+ "Tessie",
5
+ ]
@@ -1,23 +1,31 @@
1
1
  import aiohttp
2
2
  from typing import Any
3
- from .teslafleetapi import TeslaFleetApi
4
- from .const import Method
5
3
 
4
+ from ..tesla.charging import Charging
5
+ from ..tesla.energysite import EnergySites
6
+ from ..tesla.user import User
7
+ from ..tesla import TeslaFleetApi
8
+ from ..const import Method
9
+ from .vehicle import TessieVehicles
6
10
 
7
11
  class Tessie(TeslaFleetApi):
12
+
13
+ server="https://api.tessie.com"
14
+
8
15
  def __init__(
9
16
  self,
10
17
  session: aiohttp.ClientSession,
11
18
  access_token: str,
12
19
  ):
13
20
  """Initialize the Tessie API."""
14
- super().__init__(
15
- session,
16
- access_token,
17
- server="https://api.tessie.com",
18
- partner_scope=False,
19
- user_scope=False,
20
- )
21
+
22
+ self.session = session
23
+ self.access_token = access_token
24
+
25
+ self.charging = Charging(self)
26
+ self.energySites = EnergySites(self)
27
+ self.user = User(self)
28
+ self.vehicle = TessieVehicles(self)
21
29
 
22
30
  async def scopes(self) -> list[str]:
23
31
  """Get user scopes."""
@@ -0,0 +1,41 @@
1
+ from __future__ import annotations
2
+ from typing import TYPE_CHECKING, Any
3
+
4
+ from ..const import Method
5
+ from ..tesla.vehicle.proto.universal_message_pb2 import Domain
6
+ from ..tesla.vehicle.vehicle import Vehicle
7
+ from ..tesla.vehicle.vehicles import Vehicles
8
+ from ..tesla.vehicle.bluetooth import VehicleBluetooth
9
+ from ..tesla.vehicle.fleet import VehicleFleet
10
+
11
+ if TYPE_CHECKING:
12
+ from .tessie import Tessie
13
+
14
+ class TessieVehicle(Vehicle):
15
+ """Tessie specific base vehicle."""
16
+ pass
17
+
18
+ class TessieVehicleFleet(VehicleFleet):
19
+ """Tessie specific API vehicle."""
20
+ pass
21
+
22
+ class TessieVehicles(Vehicles):
23
+ """Class containing and creating vehicles."""
24
+
25
+ def create(self, vin: str) -> TessieVehicleFleet:
26
+ """Creates a specific vehicle."""
27
+ return self.createFleet(vin)
28
+
29
+ def createFleet(self, vin: str) -> TessieVehicleFleet:
30
+ """Creates a specific vehicle."""
31
+ vehicle = TessieVehicleFleet(self._parent, vin)
32
+ self[vin] = vehicle
33
+ return vehicle
34
+
35
+ def createSigned(self, vin: str):
36
+ """Creates a specific vehicle."""
37
+ raise NotImplementedError("Signing is handled by Tessie server-side")
38
+
39
+ def createBluetooth(self, vin: str):
40
+ """Creates a specific vehicle."""
41
+ raise NotImplementedError("Bluetooth is only handled locally")
@@ -1,11 +1,11 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: tesla_fleet_api
3
- Version: 0.9.9
3
+ Version: 1.0.0
4
4
  Summary: Tesla Fleet API library for Python
5
5
  Home-page: https://github.com/Teslemetry/python-tesla-fleet-api
6
6
  Author: Brett Adams
7
7
  Author-email: hello@teslemetry.com
8
- Classifier: Development Status :: 4 - Beta
8
+ Classifier: Development Status :: 5 - Production/Stable
9
9
  Classifier: Programming Language :: Python :: 3
10
10
  Classifier: License :: OSI Approved :: Apache Software License
11
11
  Classifier: Operating System :: OS Independent
@@ -17,6 +17,7 @@ Requires-Dist: aiofiles
17
17
  Requires-Dist: aiolimiter
18
18
  Requires-Dist: cryptography
19
19
  Requires-Dist: protobuf
20
+ Requires-Dist: bleak
20
21
  Dynamic: author
21
22
  Dynamic: author-email
22
23
  Dynamic: classifier
@@ -0,0 +1,24 @@
1
+ tesla_fleet_api/__init__.py,sha256=FewtEncMLxOZa3dVA3SsT3tY--RMNF9-GXIpOTkbXvk,396
2
+ tesla_fleet_api/const.py,sha256=uyfy2ZOfFZd4sunTRiIuB3FtGxIzmO1VAcSRs1pztSY,3158
3
+ tesla_fleet_api/exceptions.py,sha256=nTo9MIJrAxL-UxzbrMrr00QhSvrLaSc6ee00Ko9pB1Q,34213
4
+ tesla_fleet_api/ratecalculator.py,sha256=4lz8yruUeouHXh_3ezsXX-CTpIegp1T1J4VuRV_qdHA,1791
5
+ tesla_fleet_api/tesla/__init__.py,sha256=sWIkVh4lesdp5eGQPC9Hjk_eoyN1_g9zz7vpMsJzTgo,219
6
+ tesla_fleet_api/tesla/bluetooth.py,sha256=H4LQwNJ4RwtKMWMwfHTOyG2om11MtvC9px0Go2GCRNE,915
7
+ tesla_fleet_api/tesla/charging.py,sha256=9zNSFi9vo8v03KQRKyosO5me49_tDrg3_25BRZibfQ0,1690
8
+ tesla_fleet_api/tesla/energysite.py,sha256=jauUrh14LL-EaMruxhye1YsNHjtTMmgCl1HCf_8mBeI,6070
9
+ tesla_fleet_api/tesla/fleet.py,sha256=NCkHLd-ddpa0wkSu_CEOG7ru9ea5HTLXud4lvkh3DWM,5516
10
+ tesla_fleet_api/tesla/oauth.py,sha256=pFGtIcERjsNKrO5VUEHm8WsNo1xF4DVbx3Yt2MhlGPQ,4070
11
+ tesla_fleet_api/tesla/partner.py,sha256=TU3Xg18x2w3PHv6Dy3Mo40pb417pp5lqnF0c1vDCt6g,1224
12
+ tesla_fleet_api/tesla/tesla.py,sha256=Jlz90-fM0nJbhnQN0k3ukNv59-9KqZZbyQ91IiLIbfo,2010
13
+ tesla_fleet_api/tesla/user.py,sha256=1LVwarEU-wmkqkPw0LGvNiPRy6uGRZkYL-vr17sz51M,1180
14
+ tesla_fleet_api/teslemetry/__init__.py,sha256=OnHrZEkPGVFrziwMA-vArvh5vgBn6vT_nMbIhjN49V0,68
15
+ tesla_fleet_api/teslemetry/teslemetry.py,sha256=BtV__OSenTg_dwM0aovbL--mv3HhIIWtoWHQp58sViQ,2990
16
+ tesla_fleet_api/teslemetry/vehicle.py,sha256=aCe4Vhs4WHd6OQ-gzdxsPubKF_C5aLBoHrDvzyVgucI,2277
17
+ tesla_fleet_api/tessie/__init__.py,sha256=UNsWgx5w0DJSIFcMd7jBBdSxklF3Vhubq9tSL8vfegg,56
18
+ tesla_fleet_api/tessie/tessie.py,sha256=Z6t-ulDL7zfBIAJ6L7EBUMux2iawWjR1cR4jvYIhVFg,2523
19
+ tesla_fleet_api/tessie/vehicle.py,sha256=C2Q0en3Uo3xtI2sU9jSHXUtYhgBrNJYYhl8gP2zVmfQ,1315
20
+ tesla_fleet_api-1.0.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
21
+ tesla_fleet_api-1.0.0.dist-info/METADATA,sha256=vmW8VMIM1jR6N_64JNBgkivup9NBaM9blKTkFULRDxY,4056
22
+ tesla_fleet_api-1.0.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
23
+ tesla_fleet_api-1.0.0.dist-info/top_level.txt,sha256=jeNbog_1saXBFrGpom9WyPWmilxsyP3szL_G7JLWQfM,16
24
+ tesla_fleet_api-1.0.0.dist-info/RECORD,,
@@ -1,125 +0,0 @@
1
- from __future__ import annotations
2
- from typing import Any, TYPE_CHECKING
3
- from .const import EnergyExportMode, EnergyOperationMode, TeslaEnergyPeriod
4
-
5
- if TYPE_CHECKING:
6
- from .energy import Energy
7
-
8
-
9
- class EnergySpecific:
10
- """Class describing the Tesla Fleet API partner endpoints"""
11
-
12
- _parent: Energy
13
- energy_site_id: int
14
-
15
- def __init__(
16
- self,
17
- parent: Energy,
18
- energy_site_id: int,
19
- ):
20
- self._parent = parent
21
- self.energy_site_id = energy_site_id
22
-
23
- async def backup(self, backup_reserve_percent: int) -> dict[str, Any]:
24
- """Adjust the site's backup reserve."""
25
- return await self._parent.backup(
26
- self.energy_site_id,
27
- backup_reserve_percent,
28
- )
29
-
30
- async def backup_history(
31
- self,
32
- period: TeslaEnergyPeriod | str,
33
- start_date: str | None = None,
34
- end_date: str | None = None,
35
- time_zone: str | None = None,
36
- ) -> dict[str, Any]:
37
- """Returns the backup (off-grid) event history of the site in duration of seconds."""
38
- return await self._parent.backup_history(
39
- self.energy_site_id,
40
- period,
41
- start_date,
42
- end_date,
43
- time_zone,
44
- )
45
-
46
- async def charge_history(
47
- self,
48
- start_date: str,
49
- end_date: str,
50
- time_zone: str | None = None,
51
- ) -> dict[str, Any]:
52
- """Returns the charging history of a wall connector."""
53
- return await self._parent.charge_history(
54
- self.energy_site_id,
55
- start_date,
56
- end_date,
57
- time_zone,
58
- )
59
-
60
- async def energy_history(
61
- self,
62
- period: TeslaEnergyPeriod | str,
63
- start_date: str | None = None,
64
- end_date: str | None = None,
65
- time_zone: str | None = None,
66
- ) -> dict[str, Any]:
67
- """Returns the energy measurements of the site, aggregated to the requested period."""
68
- return await self._parent.energy_history(
69
- self.energy_site_id,
70
- period,
71
- start_date,
72
- end_date,
73
- time_zone,
74
- )
75
-
76
- async def grid_import_export(
77
- self,
78
- disallow_charge_from_grid_with_solar_installed: bool | None = None,
79
- customer_preferred_export_rule: EnergyExportMode | str | None = None,
80
- ) -> dict[str, Any]:
81
- """Allow/disallow charging from the grid and exporting energy to the grid."""
82
- return await self._parent.grid_import_export(
83
- self.energy_site_id,
84
- disallow_charge_from_grid_with_solar_installed,
85
- customer_preferred_export_rule,
86
- )
87
-
88
- async def live_status(self) -> dict[str, Any]:
89
- """Returns the live status of the site (power, state of energy, grid status, storm mode)."""
90
- return await self._parent.live_status(self.energy_site_id)
91
-
92
- async def off_grid_vehicle_charging_reserve(
93
- self, off_grid_vehicle_charging_reserve_percent: int
94
- ) -> dict[str, Any]:
95
- """Adjust the site's off-grid vehicle charging backup reserve."""
96
- return await self._parent.off_grid_vehicle_charging_reserve(
97
- self.energy_site_id, off_grid_vehicle_charging_reserve_percent
98
- )
99
-
100
- async def operation(
101
- self, default_real_mode: EnergyOperationMode | str
102
- ) -> dict[str, Any]:
103
- """Set the site's mode."""
104
- return await self._parent.operation(
105
- self.energy_site_id,
106
- default_real_mode,
107
- )
108
-
109
- async def site_info(self) -> dict[str, Any]:
110
- """Returns information about the site. Things like assets (has solar, etc), settings (backup reserve, etc), and features (storm_mode_capable, etc)."""
111
- return await self._parent.site_info(self.energy_site_id)
112
-
113
- async def storm_mode(self, enabled: bool) -> dict[str, Any]:
114
- """Update storm watch participation."""
115
- return await self._parent.storm_mode(
116
- self.energy_site_id,
117
- enabled,
118
- )
119
-
120
- async def time_of_use_settings(self, settings: dict[str, Any]) -> dict[str, Any]:
121
- """Update the site's time of use settings."""
122
- return await self._parent.time_of_use_settings(
123
- self.energy_site_id,
124
- settings,
125
- )
File without changes
@@ -1,9 +0,0 @@
1
- from . import car_server_pb2
2
- from . import common_pb2
3
- from . import errors_pb2
4
- from . import keys_pb2
5
- from . import managed_charging_pb2
6
- from . import signatures_pb2
7
- from . import universal_message_pb2
8
- from . import vcsec_pb2
9
- from . import vehicle_pb2