11from __future__ import annotations
2- from abc import abstractmethod
2+ from abc import ABC , abstractmethod
33
44import struct
55from random import randbytes
6- from typing import Any , TYPE_CHECKING
6+ from typing import Any , TYPE_CHECKING , Literal
77import time
88import hmac
99import hashlib
10+ from typing_extensions import ClassVar
1011from cryptography .hazmat .primitives .asymmetric import ec
1112from cryptography .hazmat .primitives .serialization import PublicFormat , Encoding
1213from cryptography .hazmat .primitives .hashes import Hash , SHA256
@@ -179,7 +180,7 @@ def __init__(self, parent: Commands, domain: Domain):
179180 self .sharedKey : bytes | None = None
180181 self .hmac : bytes | None = None
181182 self .publicKey : bytes | None = None
182- self .lock = Lock ()
183+ self .lock : Lock = Lock ()
183184
184185 @property
185186 def ready (self ) -> bool :
@@ -223,15 +224,14 @@ def aes_gcm_personalized(self) -> AES_GCM_Personalized_Signature_Data:
223224 )
224225
225226
226- class Commands (Vehicle ):
227+ class Commands (ABC , Vehicle ):
227228 """Class describing the Tesla Fleet API vehicle endpoints and commands for a specific vehicle with command signing."""
228229
229230 private_key : ec .EllipticCurvePrivateKey
230231 _public_key : bytes
231232 _from_destination : bytes
232233 _sessions : dict [int , Session ]
233- _require_keys = True
234- _auth_method : str
234+ _auth_method : ClassVar [Literal ["hmac" , "aes" ]]
235235
236236 def __init__ (
237237 self ,
@@ -250,17 +250,16 @@ def __init__(
250250 Domain .DOMAIN_INFOTAINMENT : Session (self , Domain .DOMAIN_INFOTAINMENT ),
251251 }
252252
253- if self ._require_keys :
254- if private_key :
255- self .private_key = private_key
256- elif parent .private_key :
257- self .private_key = parent .private_key
258- else :
259- raise ValueError ("No private key." )
253+ if private_key :
254+ self .private_key = private_key
255+ elif parent .private_key :
256+ self .private_key = parent .private_key
257+ else :
258+ raise ValueError ("No private key." )
260259
261- self ._public_key = public_key or self .private_key .public_key ().public_bytes (
262- encoding = Encoding .X962 , format = PublicFormat .UncompressedPoint
263- )
260+ self ._public_key = public_key or self .private_key .public_key ().public_bytes (
261+ encoding = Encoding .X962 , format = PublicFormat .UncompressedPoint
262+ )
264263
265264 def shared_key (self , vehicleKey : bytes ) -> bytes :
266265 exchange = self .private_key .exchange (
0 commit comments