mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 01:07:10 +00:00
Simplify imports in mqtt (#125749)
This commit is contained in:
parent
e4347e5520
commit
ba9dae10c3
@ -26,8 +26,8 @@ from homeassistant.loader import async_get_mqtt
|
|||||||
from homeassistant.util.json import json_loads_object
|
from homeassistant.util.json import json_loads_object
|
||||||
from homeassistant.util.signal_type import SignalTypeFormat
|
from homeassistant.util.signal_type import SignalTypeFormat
|
||||||
|
|
||||||
from .. import mqtt
|
|
||||||
from .abbreviations import ABBREVIATIONS, DEVICE_ABBREVIATIONS, ORIGIN_ABBREVIATIONS
|
from .abbreviations import ABBREVIATIONS, DEVICE_ABBREVIATIONS, ORIGIN_ABBREVIATIONS
|
||||||
|
from .client import async_subscribe_internal
|
||||||
from .const import (
|
from .const import (
|
||||||
ATTR_DISCOVERY_HASH,
|
ATTR_DISCOVERY_HASH,
|
||||||
ATTR_DISCOVERY_PAYLOAD,
|
ATTR_DISCOVERY_PAYLOAD,
|
||||||
@ -341,7 +341,7 @@ async def async_start( # noqa: C901
|
|||||||
)
|
)
|
||||||
|
|
||||||
mqtt_data.discovery_unsubscribe = [
|
mqtt_data.discovery_unsubscribe = [
|
||||||
mqtt.async_subscribe_internal(
|
async_subscribe_internal(
|
||||||
hass,
|
hass,
|
||||||
topic,
|
topic,
|
||||||
async_discovery_message_received,
|
async_discovery_message_received,
|
||||||
@ -400,7 +400,7 @@ async def async_start( # noqa: C901
|
|||||||
|
|
||||||
integration_unsubscribe.update(
|
integration_unsubscribe.update(
|
||||||
{
|
{
|
||||||
f"{integration}_{topic}": mqtt.async_subscribe_internal(
|
f"{integration}_{topic}": async_subscribe_internal(
|
||||||
hass,
|
hass,
|
||||||
topic,
|
topic,
|
||||||
functools.partial(async_integration_message_received, integration),
|
functools.partial(async_integration_message_received, integration),
|
||||||
|
@ -24,8 +24,15 @@ from homeassistant.helpers.trigger import TriggerActionType, TriggerData, Trigge
|
|||||||
from homeassistant.helpers.typing import ConfigType, TemplateVarsType
|
from homeassistant.helpers.typing import ConfigType, TemplateVarsType
|
||||||
from homeassistant.util.json import json_loads
|
from homeassistant.util.json import json_loads
|
||||||
|
|
||||||
from .. import mqtt
|
from .client import async_subscribe_internal
|
||||||
from .const import CONF_ENCODING, CONF_QOS, CONF_TOPIC, DEFAULT_ENCODING, DEFAULT_QOS
|
from .const import (
|
||||||
|
CONF_ENCODING,
|
||||||
|
CONF_QOS,
|
||||||
|
CONF_TOPIC,
|
||||||
|
DEFAULT_ENCODING,
|
||||||
|
DEFAULT_QOS,
|
||||||
|
DOMAIN,
|
||||||
|
)
|
||||||
from .models import (
|
from .models import (
|
||||||
MqttCommandTemplate,
|
MqttCommandTemplate,
|
||||||
MqttValueTemplate,
|
MqttValueTemplate,
|
||||||
@ -33,11 +40,12 @@ from .models import (
|
|||||||
PublishPayloadType,
|
PublishPayloadType,
|
||||||
ReceiveMessage,
|
ReceiveMessage,
|
||||||
)
|
)
|
||||||
|
from .util import valid_subscribe_topic, valid_subscribe_topic_template
|
||||||
|
|
||||||
TRIGGER_SCHEMA = cv.TRIGGER_BASE_SCHEMA.extend(
|
TRIGGER_SCHEMA = cv.TRIGGER_BASE_SCHEMA.extend(
|
||||||
{
|
{
|
||||||
vol.Required(CONF_PLATFORM): mqtt.DOMAIN,
|
vol.Required(CONF_PLATFORM): DOMAIN,
|
||||||
vol.Required(CONF_TOPIC): mqtt.util.valid_subscribe_topic_template,
|
vol.Required(CONF_TOPIC): valid_subscribe_topic_template,
|
||||||
vol.Optional(CONF_PAYLOAD): cv.template,
|
vol.Optional(CONF_PAYLOAD): cv.template,
|
||||||
vol.Optional(CONF_VALUE_TEMPLATE): cv.template,
|
vol.Optional(CONF_VALUE_TEMPLATE): cv.template,
|
||||||
vol.Optional(CONF_ENCODING, default=DEFAULT_ENCODING): cv.string,
|
vol.Optional(CONF_ENCODING, default=DEFAULT_ENCODING): cv.string,
|
||||||
@ -76,7 +84,7 @@ async def async_attach_trigger(
|
|||||||
|
|
||||||
topic_template: Template = config[CONF_TOPIC]
|
topic_template: Template = config[CONF_TOPIC]
|
||||||
topic = topic_template.async_render(variables, limited=True, parse_result=False)
|
topic = topic_template.async_render(variables, limited=True, parse_result=False)
|
||||||
mqtt.util.valid_subscribe_topic(topic)
|
valid_subscribe_topic(topic)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def mqtt_automation_listener(mqttmsg: ReceiveMessage) -> None:
|
def mqtt_automation_listener(mqttmsg: ReceiveMessage) -> None:
|
||||||
@ -104,7 +112,7 @@ async def async_attach_trigger(
|
|||||||
"Attaching MQTT trigger for topic: '%s', payload: '%s'", topic, wanted_payload
|
"Attaching MQTT trigger for topic: '%s', payload: '%s'", topic, wanted_payload
|
||||||
)
|
)
|
||||||
|
|
||||||
return mqtt.async_subscribe_internal(
|
return async_subscribe_internal(
|
||||||
hass,
|
hass,
|
||||||
topic,
|
topic,
|
||||||
mqtt_automation_listener,
|
mqtt_automation_listener,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user