Skip to content

Commit b9d1ee8

Browse files
committed
Rename update class
1 parent 3e5e93e commit b9d1ee8

File tree

3 files changed

+33
-27
lines changed

3 files changed

+33
-27
lines changed

homeassistant/components/mqtt/mixins.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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:

homeassistant/components/mqtt/models.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Modesl used by multiple MQTT modules."""
1+
"""Models used by multiple MQTT modules."""
22
from __future__ import annotations
33

44
from collections.abc import Awaitable, Callable
@@ -40,26 +40,25 @@ class ReceiveMessage:
4040
MessageCallbackType = Callable[[ReceiveMessage], None]
4141

4242

43-
class MqttNotificationConfig(TypedDict, total=False):
44-
"""Supply service parameters for MqttNotificationService."""
43+
class MqttTagConfig(TypedDict, total=False):
44+
"""Supply service parameters for MQTTTagScanner."""
4545

46-
command_topic: str
47-
command_template: Template
48-
encoding: str
49-
name: str
50-
qos: int
51-
retain: bool
52-
targets: list
53-
title: str
46+
topic: str
47+
value_template: Template
5448
device: ConfigType
5549

5650

57-
class MqttTagConfig(TypedDict, total=False):
58-
"""Supply service parameters for MQTTTagScanner."""
51+
class MqttDeviceTriggerConfig(TypedDict, total=False):
52+
"""Supply service parameters for MQTT device trigger."""
5953

54+
automation_type: str
55+
payload: str
56+
qos: int
6057
topic: str
58+
type: str
59+
subtype: str
6160
value_template: Template
6261
device: ConfigType
6362

6463

65-
MqttTypedDictConfigType = Union[MqttNotificationConfig, MqttTagConfig]
64+
MqttTypedDictConfigType = Union[MqttTagConfig, MqttDeviceTriggerConfig]

homeassistant/components/mqtt/tag.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from .discovery import MQTTConfig, cancel_discovery
1818
from .mixins import (
1919
MQTT_ENTITY_DEVICE_INFO_SCHEMA,
20-
MqttDiscoveryDeviceUpdateService,
20+
MqttDiscoveryDeviceUpdate,
2121
update_device,
2222
)
2323
from .models import MqttTagConfig
@@ -83,7 +83,7 @@ def async_has_tags(hass, device_id):
8383
return hass.data[TAGS][device_id] != {}
8484

8585

86-
class MQTTTagScanner(MqttDiscoveryDeviceUpdateService):
86+
class MQTTTagScanner(MqttDiscoveryDeviceUpdate):
8787
"""MQTT Tag scanner."""
8888

8989
def __init__(
@@ -105,7 +105,7 @@ def __init__(
105105

106106
self._setup_from_config(config)
107107

108-
MqttDiscoveryDeviceUpdateService.__init__(
108+
MqttDiscoveryDeviceUpdate.__init__(
109109
self, hass, discovery_info, device_id, config_entry, LOG_NAME
110110
)
111111

0 commit comments

Comments
 (0)