@@ -47,7 +47,10 @@ def __init__(
4747 True
4848 )
4949 self .vehicle_state = vehicle_state
50- self .ha_discovery = HomeAssistantDiscovery (vehicle_state , vin_info , config )
50+ if self .configuration .ha_discovery_enabled :
51+ self .__ha_discovery = HomeAssistantDiscovery (vehicle_state , vin_info , config )
52+ else :
53+ self .__ha_discovery = None
5154
5255 self .__setup_abrp (config , vin_info )
5356 self .__setup_osmand (config , vin_info )
@@ -114,8 +117,7 @@ async def handle_vehicle(self) -> None:
114117 exc_info = e
115118 )
116119 finally :
117- if self .configuration .ha_discovery_enabled :
118- self .ha_discovery .publish_ha_discovery_messages ()
120+ self .publish_ha_discovery_messages (force = False )
119121 else :
120122 # car not active, wait a second
121123 await asyncio .sleep (1.0 )
@@ -176,9 +178,10 @@ async def __refresh_abrp(self, charge_status, vehicle_status):
176178 else :
177179 LOG .info (f'ABRP not refreshed, reason { abrp_response } ' )
178180
179- async def publish_ha_discovery_messages (self , force = False ):
180- LOG .info (f'Sending HA discovery messages for { self .vin_info .vin } (Force: { force } )' )
181- self .ha_discovery .publish_ha_discovery_messages (force )
181+ def publish_ha_discovery_messages (self , * , force = False ):
182+ if self .__ha_discovery is not None :
183+ LOG .info (f'Sending HA discovery messages for { self .vin_info .vin } (Force: { force } )' )
184+ self .__ha_discovery .publish_ha_discovery_messages (force = force )
182185
183186 async def update_vehicle_status (self ) -> VehicleStatusResp :
184187 LOG .info ('Updating vehicle status' )
0 commit comments