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

Classes

class  EnsureJobAfterCooldown
 

Functions

None async_create_certificate_temp_files (HomeAssistant hass, ConfigType config)
 
None async_forward_entry_setup_and_setup_discovery (HomeAssistant hass, ConfigEntry config_entry, set[Platform|str] platforms, bool late=False)
 
bool async_wait_for_mqtt_client (HomeAssistant hass)
 
bool check_state_too_long (logging.Logger logger, str proposed_state, str entity_id, ReceiveMessage msg)
 
str|None get_file_path (str option, str|None default=None)
 
str|None migrate_certificate_file_to_content (str file_name_or_auto)
 
bool|None mqtt_config_entry_enabled (HomeAssistant hass)
 
set[Platform|str] platforms_from_config (list[ConfigType] config)
 
ConfigType valid_birth_will (ConfigType config)
 
str valid_publish_topic (Any topic)
 
int valid_qos_schema (Any qos)
 
str valid_subscribe_topic (Any topic)
 
template.Template valid_subscribe_topic_template (Any value)
 
str valid_topic (Any topic)
 

Variables

 _LOGGER = logging.getLogger(__name__)
 
 _MQTT_WILL_BIRTH_SCHEMA
 
 _VALID_QOS_SCHEMA = vol.All(vol.Coerce(int), vol.In([0, 1, 2]))
 
float AVAILABILITY_TIMEOUT = 50.0
 
string TEMP_DIR_NAME = f"home-assistant-{DOMAIN}"
 

Detailed Description

Utility functions for the MQTT integration.

Function Documentation

◆ async_create_certificate_temp_files()

None homeassistant.components.mqtt.util.async_create_certificate_temp_files ( HomeAssistant  hass,
ConfigType   config 
)
Create certificate temporary files for the MQTT client.

Definition at line 340 of file util.py.

◆ async_forward_entry_setup_and_setup_discovery()

None homeassistant.components.mqtt.util.async_forward_entry_setup_and_setup_discovery ( HomeAssistant  hass,
ConfigEntry  config_entry,
set[Platform | str]  platforms,
bool   late = False 
)
Forward the config entry setup to the platforms and set up discovery.

Definition at line 153 of file util.py.

◆ async_wait_for_mqtt_client()

bool homeassistant.components.mqtt.util.async_wait_for_mqtt_client ( HomeAssistant  hass)
Wait for the MQTT client to become available.

Waits when mqtt set up is in progress,
It is not needed that the client is connected.
Returns True if the mqtt client is available.
Returns False when the client is not available.

Definition at line 203 of file util.py.

◆ check_state_too_long()

bool homeassistant.components.mqtt.util.check_state_too_long ( logging.Logger  logger,
str  proposed_state,
str  entity_id,
ReceiveMessage   msg 
)
Check if the processed state is too long and log warning.

Definition at line 370 of file util.py.

◆ get_file_path()

str | None homeassistant.components.mqtt.util.get_file_path ( str  option,
str | None   default = None 
)
Get file path of a certificate file.

Definition at line 392 of file util.py.

◆ migrate_certificate_file_to_content()

str | None homeassistant.components.mqtt.util.migrate_certificate_file_to_content ( str  file_name_or_auto)
Convert certificate file or setting to config entry setting.

Definition at line 405 of file util.py.

◆ mqtt_config_entry_enabled()

bool | None homeassistant.components.mqtt.util.mqtt_config_entry_enabled ( HomeAssistant  hass)
Return true when the MQTT config entry is enabled.

Definition at line 192 of file util.py.

◆ platforms_from_config()

set[Platform | str] homeassistant.components.mqtt.util.platforms_from_config ( list[ConfigType]  config)
Return the platforms to be set up.

Definition at line 148 of file util.py.

◆ valid_birth_will()

ConfigType homeassistant.components.mqtt.util.valid_birth_will ( ConfigType  config)
Validate a birth or will configuration and required topic/payload.

Definition at line 333 of file util.py.

◆ valid_publish_topic()

str homeassistant.components.mqtt.util.valid_publish_topic ( Any  topic)
Validate that we can publish using this MQTT topic.

Definition at line 308 of file util.py.

◆ valid_qos_schema()

int homeassistant.components.mqtt.util.valid_qos_schema ( Any  qos)
Validate that QOS value is valid.

Definition at line 316 of file util.py.

◆ valid_subscribe_topic()

str homeassistant.components.mqtt.util.valid_subscribe_topic ( Any  topic)
Validate that we can subscribe using this MQTT topic.

Definition at line 270 of file util.py.

◆ valid_subscribe_topic_template()

template.Template homeassistant.components.mqtt.util.valid_subscribe_topic_template ( Any  value)
Validate either a jinja2 template or a valid MQTT subscription topic.

Definition at line 297 of file util.py.

◆ valid_topic()

str homeassistant.components.mqtt.util.valid_topic ( Any  topic)
Validate that this is a valid topic name/filter.

This function is not cached and is not expected to be called
directly outside of this module. It is not marked as protected
only because its tested directly in test_util.py.

If it gets used outside of valid_subscribe_topic and
valid_publish_topic, it may need an lru_cache decorator or
an lru_cache decorator on the function where its used.

Definition at line 233 of file util.py.

Variable Documentation

◆ _LOGGER

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

Definition at line 45 of file util.py.

◆ _MQTT_WILL_BIRTH_SCHEMA

homeassistant.components.mqtt.util._MQTT_WILL_BIRTH_SCHEMA
private
Initial value:
1 = vol.Schema(
2  {
3  vol.Required(ATTR_TOPIC): valid_publish_topic,
4  vol.Required(ATTR_PAYLOAD): cv.string,
5  vol.Optional(ATTR_QOS, default=DEFAULT_QOS): valid_qos_schema,
6  vol.Optional(ATTR_RETAIN, default=DEFAULT_RETAIN): cv.boolean,
7  },
8  required=True,
9 )

Definition at line 322 of file util.py.

◆ _VALID_QOS_SCHEMA

homeassistant.components.mqtt.util._VALID_QOS_SCHEMA = vol.All(vol.Coerce(int), vol.In([0, 1, 2]))
private

Definition at line 43 of file util.py.

◆ AVAILABILITY_TIMEOUT

float homeassistant.components.mqtt.util.AVAILABILITY_TIMEOUT = 50.0

Definition at line 39 of file util.py.

◆ TEMP_DIR_NAME

string homeassistant.components.mqtt.util.TEMP_DIR_NAME = f"home-assistant-{DOMAIN}"

Definition at line 41 of file util.py.