@@ -530,7 +530,7 @@ async def cleanup_device_registry(
530530 )
531531
532532
533- class MqttDiscoveryDeviceUpdateService :
533+ class MqttDiscoveryDeviceUpdate :
534534 """Add support for auto discovery for platforms without an entity."""
535535
536536 def __init__ (
@@ -565,6 +565,12 @@ async def async_discovery_update(
565565 ) -> None :
566566 """Handle discovery update."""
567567 nonlocal rediscover , self
568+ _LOGGER .info (
569+ "Got update for %s with hash: %s '%s'" ,
570+ self .log_name ,
571+ self .discovery_hash ,
572+ discovery_payload ,
573+ )
568574 if (
569575 discovery_payload
570576 and discovery_payload != discovery_data [ATTR_DISCOVERY_PAYLOAD ]
@@ -573,20 +579,16 @@ async def async_discovery_update(
573579 if not discovery_payload or rediscover :
574580 # unregister and clean up the current discovery instance
575581 self .terminate_discovery ()
576- async_dispatcher_send (
577- hass , MQTT_DISCOVERY_DONE .format (self .discovery_hash ), None
578- )
579582 await _async_tear_down ()
583+ self .async_send_discovery_done ()
580584 _LOGGER .info (
581585 "%s %s has been removed" ,
582586 self .log_name ,
583587 self .discovery_hash ,
584588 )
585589 else :
586590 # Normal update without change
587- async_dispatcher_send (
588- hass , MQTT_DISCOVERY_DONE .format (self .discovery_hash ), None
589- )
591+ self .async_send_discovery_done ()
590592 _LOGGER .info (
591593 "%s %s no changes" ,
592594 self .log_name ,
@@ -651,15 +653,20 @@ def _entry_unload(*_: Any) -> None:
651653 self ._remove_device_updated = hass .bus .async_listen (
652654 EVENT_DEVICE_REGISTRY_UPDATED , _async_device_removed
653655 )
654- async_dispatcher_send (
655- hass , MQTT_DISCOVERY_DONE .format (self .discovery_hash ), None
656- )
656+ self .async_send_discovery_done ()
657657 _LOGGER .info (
658658 "%s %s has been initialized" ,
659659 self .log_name ,
660660 self .discovery_hash ,
661661 )
662662
663+ @callback
664+ def async_send_discovery_done (self ) -> None :
665+ """Acknowledge a discovery message has been handled."""
666+ async_dispatcher_send (
667+ self .hass , MQTT_DISCOVERY_DONE .format (self .discovery_hash ), None
668+ )
669+
663670 def terminate_discovery (self ) -> None :
664671 """Terminate the discovery."""
665672 if self ._remove_discovery :
0 commit comments