@@ -61,6 +61,10 @@ def __init__(
61
61
def mqtt_topic_prefix (self ) -> str :
62
62
return self ._mqtt_topic_prefix
63
63
64
+ @property
65
+ def shutdown_lock_acquired (self ) -> bool :
66
+ return self ._shutdown_lock is not None
67
+
64
68
def acquire_shutdown_lock (self ) -> None :
65
69
with self ._shutdown_lock_mutex :
66
70
assert self ._shutdown_lock is None
@@ -234,7 +238,8 @@ def _mqtt_on_connect(
234
238
assert return_code == 0 , return_code # connection accepted
235
239
mqtt_broker_host , mqtt_broker_port = mqtt_client .socket ().getpeername ()
236
240
_LOGGER .debug ("connected to MQTT broker %s:%d" , mqtt_broker_host , mqtt_broker_port )
237
- state .acquire_shutdown_lock ()
241
+ if not state .shutdown_lock_acquired :
242
+ state .acquire_shutdown_lock ()
238
243
state .register_prepare_for_shutdown_handler (mqtt_client = mqtt_client )
239
244
state .publish_preparing_for_shutdown (mqtt_client = mqtt_client )
240
245
state .publish_preparing_for_shutdown_homeassistant_config (mqtt_client = mqtt_client )
@@ -246,7 +251,7 @@ def _mqtt_on_connect(
246
251
sub = topic , callback = action .mqtt_message_callback
247
252
)
248
253
_LOGGER .debug (
249
- "registered MQTT callback for topic %s triggering %r" , topic , action .action
254
+ "registered MQTT callback for topic %s triggering %r" , topic , action .action ,
250
255
)
251
256
252
257
0 commit comments