@@ -28,29 +28,29 @@ def __init__(self, msg: str) -> None:
2828class AbrpApiListener (ABC ):
2929 @abstractmethod
3030 async def on_request (
31- self ,
32- path : str ,
33- body : str | None = None ,
34- headers : dict [str , str ] | None = None ,
31+ self ,
32+ path : str ,
33+ body : str | None = None ,
34+ headers : dict [str , str ] | None = None ,
3535 ) -> None :
3636 pass
3737
3838 @abstractmethod
3939 async def on_response (
40- self ,
41- path : str ,
42- body : str | None = None ,
43- headers : dict [str , str ] | None = None ,
40+ self ,
41+ path : str ,
42+ body : str | None = None ,
43+ headers : dict [str , str ] | None = None ,
4444 ) -> None :
4545 pass
4646
4747
4848class AbrpApi :
4949 def __init__ (
50- self ,
51- abrp_api_key : str | None ,
52- abrp_user_token : str | None ,
53- listener : AbrpApiListener | None = None ,
50+ self ,
51+ abrp_api_key : str | None ,
52+ abrp_user_token : str | None ,
53+ listener : AbrpApiListener | None = None ,
5454 ) -> None :
5555 self .abrp_api_key = abrp_api_key
5656 self .abrp_user_token = abrp_user_token
@@ -64,18 +64,18 @@ def __init__(
6464 )
6565
6666 async def update_abrp (
67- self ,
68- vehicle_status : VehicleStatusResp | None ,
69- charge_info : ChrgMgmtDataResp | None ,
67+ self ,
68+ vehicle_status : VehicleStatusResp | None ,
69+ charge_info : ChrgMgmtDataResp | None ,
7070 ) -> tuple [bool , str ]:
7171 charge_mgmt_data = None if charge_info is None else charge_info .chrgMgmtData
7272 charge_status = None if charge_info is None else charge_info .rvsChargeStatus
7373
7474 if (
75- self .abrp_api_key is not None
76- and self .abrp_user_token is not None
77- and vehicle_status is not None
78- and charge_mgmt_data is not None
75+ self .abrp_api_key is not None
76+ and self .abrp_user_token is not None
77+ and vehicle_status is not None
78+ and charge_mgmt_data is not None
7979 ):
8080 # Request
8181 tlm_send_url = f"{ self .__base_uri } tlm/send"
@@ -91,19 +91,18 @@ async def update_abrp(
9191 )
9292
9393 # Skip invalid current values reported by the API
94+ decoded_current = charge_mgmt_data .decoded_current
9495 is_valid_current = (
95- charge_mgmt_data .bmsPackCrntV != 1
96- and (raw_current := charge_mgmt_data .bmsPackCrnt ) is not None
97- and value_in_range (raw_current , 0 , 65535 )
96+ charge_mgmt_data .bmsPackCrntV != 1
97+ and (raw_current := charge_mgmt_data .bmsPackCrnt ) is not None
98+ and value_in_range (raw_current , 0 , 65535 )
99+ and decoded_current is not None
98100 )
99101 if is_valid_current :
100102 is_charging = (
101- charge_status is not None
102- and charge_status .chargingGunState
103- and is_valid_current
104- and (decoded_current := charge_mgmt_data .decoded_current )
105- is not None
106- and decoded_current < 0.0
103+ charge_status is not None
104+ and charge_status .chargingGunState
105+ and decoded_current < 0.0
107106 )
108107 data .update (
109108 {
@@ -154,15 +153,15 @@ async def update_abrp(
154153
155154 @staticmethod
156155 def __extract_basic_vehicle_status (
157- basic_vehicle_status : BasicVehicleStatus ,
156+ basic_vehicle_status : BasicVehicleStatus ,
158157 ) -> dict [str , Any ]:
159158 data : dict [str , Any ] = {
160159 "is_parked" : basic_vehicle_status .is_parked ,
161160 }
162161
163162 exterior_temperature = basic_vehicle_status .exteriorTemperature
164163 if exterior_temperature is not None and value_in_range (
165- exterior_temperature , - 127 , 127
164+ exterior_temperature , - 127 , 127
166165 ):
167166 data ["ext_temp" ] = exterior_temperature
168167 mileage = basic_vehicle_status .mileage
@@ -206,7 +205,7 @@ def __extract_gps_position(gps_position: GpsPosition) -> dict[str, Any]:
206205 data ["elevation" ] = altitude
207206
208207 if (raw_lat := position .latitude ) is not None and (
209- raw_lon := position .longitude
208+ raw_lon := position .longitude
210209 ) is not None :
211210 lat_degrees = raw_lat / 1000000.0
212211 lon_degrees = raw_lon / 1000000.0
@@ -222,16 +221,16 @@ def __extract_gps_position(gps_position: GpsPosition) -> dict[str, Any]:
222221 return data
223222
224223 def __extract_electric_range (
225- self ,
226- basic_vehicle_status : BasicVehicleStatus | None ,
227- charge_status : RvsChargeStatus | None ,
224+ self ,
225+ basic_vehicle_status : BasicVehicleStatus | None ,
226+ charge_status : RvsChargeStatus | None ,
228227 ) -> dict [str , Any ]:
229228 data = {}
230229
231230 range_elec_vehicle = 0.0
232231 if (
233- basic_vehicle_status
234- and (fuel_range := basic_vehicle_status .fuelRangeElec ) is not None
232+ basic_vehicle_status
233+ and (fuel_range := basic_vehicle_status .fuelRangeElec ) is not None
235234 ):
236235 range_elec_vehicle = self .__parse_electric_range (raw_value = fuel_range )
237236
0 commit comments