Allow to omit the payload attribute to MQTT publish action to allow an empty payload to be sent by default (#137595)
Allow to omit the payload attribute to MQTT publish actionto allow an empty payload to be sent by defaultpull/137688/head
parent
7b20299de7
commit
e09ae1c83d
|
@ -236,7 +236,7 @@ CONFIG_SCHEMA = vol.Schema(
|
|||
MQTT_PUBLISH_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Required(ATTR_TOPIC): valid_publish_topic,
|
||||
vol.Required(ATTR_PAYLOAD): cv.string,
|
||||
vol.Required(ATTR_PAYLOAD, default=None): vol.Any(cv.string, None),
|
||||
vol.Optional(ATTR_EVALUATE_PAYLOAD): cv.boolean,
|
||||
vol.Optional(ATTR_QOS, default=DEFAULT_QOS): valid_qos_schema,
|
||||
vol.Optional(ATTR_RETAIN, default=DEFAULT_RETAIN): cv.boolean,
|
||||
|
|
|
@ -8,7 +8,6 @@ publish:
|
|||
selector:
|
||||
text:
|
||||
payload:
|
||||
required: true
|
||||
example: "The temperature is {{ states('sensor.temperature') }}"
|
||||
selector:
|
||||
template:
|
||||
|
|
|
@ -246,11 +246,7 @@
|
|||
},
|
||||
"payload": {
|
||||
"name": "Payload",
|
||||
"description": "The payload to publish."
|
||||
},
|
||||
"payload_template": {
|
||||
"name": "Payload template",
|
||||
"description": "Template to render as a payload value. If a payload is provided, the template is ignored."
|
||||
"description": "The payload to publish. Publishes an empty message if not provided."
|
||||
},
|
||||
"qos": {
|
||||
"name": "QoS",
|
||||
|
|
|
@ -391,6 +391,25 @@ async def test_service_call_with_ascii_qos_retain_flags(
|
|||
blocking=True,
|
||||
)
|
||||
assert mqtt_mock.async_publish.called
|
||||
assert mqtt_mock.async_publish.call_args[0][1] == ""
|
||||
assert mqtt_mock.async_publish.call_args[0][2] == 2
|
||||
assert not mqtt_mock.async_publish.call_args[0][3]
|
||||
|
||||
mqtt_mock.reset_mock()
|
||||
|
||||
# Test service call without payload
|
||||
await hass.services.async_call(
|
||||
mqtt.DOMAIN,
|
||||
mqtt.SERVICE_PUBLISH,
|
||||
{
|
||||
mqtt.ATTR_TOPIC: "test/topic",
|
||||
mqtt.ATTR_QOS: "2",
|
||||
mqtt.ATTR_RETAIN: "no",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
assert mqtt_mock.async_publish.called
|
||||
assert mqtt_mock.async_publish.call_args[0][1] is None
|
||||
assert mqtt_mock.async_publish.call_args[0][2] == 2
|
||||
assert not mqtt_mock.async_publish.call_args[0][3]
|
||||
|
||||
|
|
Loading…
Reference in New Issue