1212from integrations import IntegrationException
1313from integrations .abrp .api import AbrpApi
1414from integrations .home_assistant .discovery import HomeAssistantDiscovery
15+ from integrations .openwb import OpenWBIntegration
1516from integrations .osmand .api import OsmAndApi
1617import mqtt_topics
1718from saic_api_listener import MqttGatewayAbrpListener , MqttGatewayOsmAndListener
@@ -61,8 +62,9 @@ def __init__(
6162 self .vehicle_state = vehicle_state
6263 self .__ha_discovery = self .__setup_ha_discovery (vehicle_state , vin_info , config )
6364
64- self .__setup_abrp (config , vin_info )
65- self .__setup_osmand (config , vin_info )
65+ self .openwb_integration = self .__setup_openwb (config , vin_info , publisher )
66+ self .abrp_api = self .__setup_abrp (config , vin_info )
67+ self .osmand_api = self .__setup_osmand (config , vin_info )
6668 self .__vehicle_info_publisher = VehicleInfoPublisher (
6769 self .vin_info , self .publisher , self .vehicle_prefix
6870 )
@@ -74,7 +76,18 @@ def __init__(
7476 vehicle_prefix = self .vehicle_prefix ,
7577 )
7678
77- def __setup_abrp (self , config : Configuration , vin_info : VehicleInfo ) -> None :
79+ def __setup_openwb (
80+ self , config : Configuration , vin_info : VehicleInfo , publisher : Publisher
81+ ) -> OpenWBIntegration | None :
82+ charging_station = config .charging_stations_by_vin .get (vin_info .vin , None )
83+ if not charging_station :
84+ return None
85+ return OpenWBIntegration (
86+ charging_station = charging_station ,
87+ publisher = publisher ,
88+ )
89+
90+ def __setup_abrp (self , config : Configuration , vin_info : VehicleInfo ) -> AbrpApi :
7891 if vin_info .vin in self .configuration .abrp_token_map :
7992 abrp_user_token = self .configuration .abrp_token_map [vin_info .vin ]
8093 else :
@@ -83,14 +96,15 @@ def __setup_abrp(self, config: Configuration, vin_info: VehicleInfo) -> None:
8396 abrp_api_listener = MqttGatewayAbrpListener (self .publisher )
8497 else :
8598 abrp_api_listener = None
86- self . abrp_api = AbrpApi (
99+ return AbrpApi (
87100 self .configuration .abrp_api_key , abrp_user_token , listener = abrp_api_listener
88101 )
89102
90- def __setup_osmand (self , config : Configuration , vin_info : VehicleInfo ) -> None :
103+ def __setup_osmand (
104+ self , config : Configuration , vin_info : VehicleInfo
105+ ) -> OsmAndApi | None :
91106 if not self .configuration .osmand_server_uri :
92- self .osmand_api = None
93- return
107+ return None
94108
95109 if config .publish_raw_osmand_data :
96110 api_listener = MqttGatewayOsmAndListener (self .publisher )
@@ -99,7 +113,7 @@ def __setup_osmand(self, config: Configuration, vin_info: VehicleInfo) -> None:
99113 osmand_device_id = self .configuration .osmand_device_id_map .get (
100114 vin_info .vin , vin_info .vin
101115 )
102- self . osmand_api = OsmAndApi (
116+ return OsmAndApi (
103117 server_uri = self .configuration .osmand_server_uri ,
104118 device_id = osmand_device_id ,
105119 listener = api_listener ,
@@ -171,7 +185,6 @@ async def __polling(self) -> None:
171185 )
172186 else :
173187 LOG .debug ("Skipping EV-related updates as the vehicle is not an EV" )
174- charge_status = None
175188
176189 self .vehicle_state .update_data_conflicting_in_vehicle_and_bms (
177190 vehicle_status_processing_result , charge_status_processing_result
@@ -180,6 +193,9 @@ async def __polling(self) -> None:
180193 self .vehicle_state .mark_successful_refresh ()
181194 LOG .info ("Refreshing vehicle status succeeded..." )
182195
196+ self .__refresh_openwb (
197+ vehicle_status_processing_result , charge_status_processing_result
198+ )
183199 await self .__refresh_abrp (charge_status , vehicle_status )
184200 await self .__refresh_osmand (charge_status , vehicle_status )
185201
@@ -196,10 +212,21 @@ def __should_complete_configuration(self, start_time: datetime.datetime) -> bool
196212 and datetime .datetime .now () > start_time + datetime .timedelta (seconds = 10 )
197213 )
198214
215+ def __refresh_openwb (
216+ self ,
217+ vehicle_status_processing_result : VehicleStatusRespProcessingResult ,
218+ charge_status_processing_result : ChrgMgmtDataRespProcessingResult | None ,
219+ ) -> None :
220+ if self .openwb_integration is None :
221+ return
222+ self .openwb_integration .update_openwb (
223+ vehicle_status_processing_result , charge_status_processing_result
224+ )
225+
199226 async def __refresh_osmand (
200227 self ,
201228 charge_status : ChrgMgmtDataResp | None ,
202- vehicle_status : VehicleStatusResp | None ,
229+ vehicle_status : VehicleStatusResp ,
203230 ) -> None :
204231 if not self .osmand_api :
205232 return
@@ -215,9 +242,7 @@ async def __refresh_osmand(
215242 LOG .info (f"OsmAnd not refreshed, reason { response } " )
216243
217244 async def __refresh_abrp (
218- self ,
219- charge_status : ChrgMgmtDataResp | None ,
220- vehicle_status : VehicleStatusResp | None ,
245+ self , charge_status : ChrgMgmtDataResp | None , vehicle_status : VehicleStatusResp
221246 ) -> None :
222247 abrp_refreshed , abrp_response = await self .abrp_api .update_abrp (
223248 vehicle_status , charge_status
0 commit comments