Home Assistant Unofficial Reference 2024.12.1
homeassistant.components.mqtt.discovery Namespace Reference

Classes

class  MQTTDiscoveryPayload
 
class  MQTTIntegrationDiscoveryConfig
 

Functions

bool _async_process_discovery_migration (MQTTDiscoveryPayload payload)
 
MQTTDiscoveryPayload _generate_device_config (HomeAssistant hass, str object_id, str|None node_id, bool migrate_discovery=False)
 
None _merge_common_device_options (MQTTDiscoveryPayload component_config, dict[str, Any] device_config)
 
MQTTDiscoveryPayload _parse_device_payload (HomeAssistant hass, ReceivePayloadType payload, str object_id, str|None node_id)
 
None _replace_abbreviations (dict[str, Any]|str payload, dict[str, str] abbreviations, set[str] abbreviations_set)
 
None _replace_all_abbreviations (dict[str, Any] discovery_payload, bool component_only=False)
 
None _replace_topic_base (MQTTDiscoveryPayload discovery_payload)
 
bool _valid_origin_info (MQTTDiscoveryPayload discovery_payload)
 
None async_log_discovery_origin_info (str message, MQTTDiscoveryPayload discovery_payload, int level=logging.INFO)
 
None async_start (HomeAssistant hass, str discovery_topic, ConfigEntry config_entry)
 
None async_stop (HomeAssistant hass)
 
None clear_discovery_hash (HomeAssistant hass, tuple[str, str] discovery_hash)
 
str get_origin_log_string (MQTTDiscoveryPayload discovery_payload, *bool include_url)
 
str|None get_origin_support_url (MQTTDiscoveryPayload discovery_payload)
 
None set_discovery_hash (HomeAssistant hass, tuple[str, str] discovery_hash)
 

Variables

 _LOGGER = logging.getLogger(__name__)
 
 ABBREVIATIONS_SET = set(ABBREVIATIONS)
 
string CONF_MIGRATE_DISCOVERY = "migrate_discovery"
 
 DEVICE_ABBREVIATIONS_SET = set(DEVICE_ABBREVIATIONS)
 
 MIGRATE_DISCOVERY_SCHEMA
 
 ORIGIN_ABBREVIATIONS_SET = set(ORIGIN_ABBREVIATIONS)
 
string TOPIC_BASE = "~"
 
 TOPIC_MATCHER
 

Detailed Description

Support for MQTT discovery.

Function Documentation

◆ _async_process_discovery_migration()

bool homeassistant.components.mqtt.discovery._async_process_discovery_migration ( MQTTDiscoveryPayload  payload)
private
Process a discovery migration request in the discovery payload.

Definition at line 100 of file discovery.py.

◆ _generate_device_config()

MQTTDiscoveryPayload homeassistant.components.mqtt.discovery._generate_device_config ( HomeAssistant  hass,
str  object_id,
str | None  node_id,
bool   migrate_discovery = False 
)
private
Generate a cleanup or discovery migration message on device cleanup.

If an empty payload, or a migrate discovery request is received for a device,
we forward an empty payload for all previously discovered components.

Definition at line 241 of file discovery.py.

◆ _merge_common_device_options()

None homeassistant.components.mqtt.discovery._merge_common_device_options ( MQTTDiscoveryPayload  component_config,
dict[str, Any]   device_config 
)
private
Merge common device options with the component config options.

Common options are:
    CONF_AVAILABILITY,
    CONF_AVAILABILITY_MODE,
    CONF_AVAILABILITY_TEMPLATE,
    CONF_AVAILABILITY_TOPIC,
    CONF_COMMAND_TOPIC,
    CONF_PAYLOAD_AVAILABLE,
    CONF_PAYLOAD_NOT_AVAILABLE,
    CONF_STATE_TOPIC,
Common options in the body of the device based config are inherited into
the component. Unless the option is explicitly specified at component level,
in that case the option at component level will override the common option.

Definition at line 331 of file discovery.py.

◆ _parse_device_payload()

MQTTDiscoveryPayload homeassistant.components.mqtt.discovery._parse_device_payload ( HomeAssistant  hass,
ReceivePayloadType  payload,
str  object_id,
str | None  node_id 
)
private
Parse a device discovery payload.

The device discovery payload is translated info the config payloads for every single
component inside the device based configuration.
An empty payload is translated in a cleanup, which forwards an empty payload to all
removed components.

Definition at line 270 of file discovery.py.

◆ _replace_abbreviations()

None homeassistant.components.mqtt.discovery._replace_abbreviations ( dict[str, Any] | str  payload,
dict[str, str]  abbreviations,
set[str]  abbreviations_set 
)
private
Replace abbreviations in an MQTT discovery payload.

Definition at line 171 of file discovery.py.

◆ _replace_all_abbreviations()

None homeassistant.components.mqtt.discovery._replace_all_abbreviations ( dict[str, Any]  discovery_payload,
bool   component_only = False 
)
private
Replace all abbreviations in an MQTT discovery payload.

Definition at line 184 of file discovery.py.

◆ _replace_topic_base()

None homeassistant.components.mqtt.discovery._replace_topic_base ( MQTTDiscoveryPayload  discovery_payload)
private
Replace topic base in MQTT discovery data.

Definition at line 220 of file discovery.py.

◆ _valid_origin_info()

bool homeassistant.components.mqtt.discovery._valid_origin_info ( MQTTDiscoveryPayload  discovery_payload)
private
Parse and validate origin info from a single component discovery payload.

Definition at line 314 of file discovery.py.

◆ async_log_discovery_origin_info()

None homeassistant.components.mqtt.discovery.async_log_discovery_origin_info ( str  message,
MQTTDiscoveryPayload  discovery_payload,
int   level = logging.INFO 
)
Log information about the discovery and origin.

Definition at line 154 of file discovery.py.

◆ async_start()

None homeassistant.components.mqtt.discovery.async_start ( HomeAssistant  hass,
str  discovery_topic,
ConfigEntry   config_entry 
)
Start MQTT Discovery.

Definition at line 354 of file discovery.py.

◆ async_stop()

None homeassistant.components.mqtt.discovery.async_stop ( HomeAssistant  hass)
Stop MQTT Discovery.

Definition at line 694 of file discovery.py.

◆ clear_discovery_hash()

None homeassistant.components.mqtt.discovery.clear_discovery_hash ( HomeAssistant  hass,
tuple[str, str]  discovery_hash 
)
Clear entry from already discovered list.

Definition at line 117 of file discovery.py.

◆ get_origin_log_string()

str homeassistant.components.mqtt.discovery.get_origin_log_string ( MQTTDiscoveryPayload  discovery_payload,
*bool   include_url 
)
Get the origin information from a discovery payload for logging.

Definition at line 128 of file discovery.py.

◆ get_origin_support_url()

str | None homeassistant.components.mqtt.discovery.get_origin_support_url ( MQTTDiscoveryPayload  discovery_payload)
Get the origin information support URL from a discovery payload.

Definition at line 145 of file discovery.py.

◆ set_discovery_hash()

None homeassistant.components.mqtt.discovery.set_discovery_hash ( HomeAssistant  hass,
tuple[str, str]  discovery_hash 
)
Add entry to already discovered list.

Definition at line 122 of file discovery.py.

Variable Documentation

◆ _LOGGER

homeassistant.components.mqtt.discovery._LOGGER = logging.getLogger(__name__)
private

Definition at line 57 of file discovery.py.

◆ ABBREVIATIONS_SET

homeassistant.components.mqtt.discovery.ABBREVIATIONS_SET = set(ABBREVIATIONS)

Definition at line 53 of file discovery.py.

◆ CONF_MIGRATE_DISCOVERY

string homeassistant.components.mqtt.discovery.CONF_MIGRATE_DISCOVERY = "migrate_discovery"

Definition at line 76 of file discovery.py.

◆ DEVICE_ABBREVIATIONS_SET

homeassistant.components.mqtt.discovery.DEVICE_ABBREVIATIONS_SET = set(DEVICE_ABBREVIATIONS)

Definition at line 54 of file discovery.py.

◆ MIGRATE_DISCOVERY_SCHEMA

homeassistant.components.mqtt.discovery.MIGRATE_DISCOVERY_SCHEMA
Initial value:
1 = vol.Schema(
2  {vol.Optional(CONF_MIGRATE_DISCOVERY): True},
3 )

Definition at line 78 of file discovery.py.

◆ ORIGIN_ABBREVIATIONS_SET

homeassistant.components.mqtt.discovery.ORIGIN_ABBREVIATIONS_SET = set(ORIGIN_ABBREVIATIONS)

Definition at line 55 of file discovery.py.

◆ TOPIC_BASE

string homeassistant.components.mqtt.discovery.TOPIC_BASE = "~"

Definition at line 74 of file discovery.py.

◆ TOPIC_MATCHER

homeassistant.components.mqtt.discovery.TOPIC_MATCHER
Initial value:
1 = re.compile(
2  r"(?P<component>\w+)/(?:(?P<node_id>[a-zA-Z0-9_-]+)/)"
3  r"?(?P<object_id>[a-zA-Z0-9_-]+)/config"
4 )

Definition at line 59 of file discovery.py.