mirror of
https://github.com/home-assistant/core.git
synced 2025-08-03 20:55:10 +02:00
Add mqtt encoding support for publishing (#62739)
* encoding support for mqtt publishing - todo tests * signature allows None values for qos and retain * common test for mqtt publishing encoding * better test with command templates * more tests * fix tests alarm control panel+tests light basic * tests light json and template * add tests vacuum and fix tests light_template
This commit is contained in:
@@ -26,6 +26,7 @@ If your light doesn't support white value feature, omit `white_value_template`.
|
||||
|
||||
If your light doesn't support RGB feature, omit `(red|green|blue)_template`.
|
||||
"""
|
||||
import copy
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
@@ -60,6 +61,7 @@ from .test_common import (
|
||||
help_test_entity_device_info_with_identifier,
|
||||
help_test_entity_id_update_discovery_update,
|
||||
help_test_entity_id_update_subscriptions,
|
||||
help_test_publishing_with_custom_encoding,
|
||||
help_test_setting_attribute_via_mqtt_json_message,
|
||||
help_test_setting_attribute_with_template,
|
||||
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
||||
@@ -1085,3 +1087,62 @@ async def test_max_mireds(hass, mqtt_mock):
|
||||
state = hass.states.get("light.test")
|
||||
assert state.attributes.get("min_mireds") == 153
|
||||
assert state.attributes.get("max_mireds") == 370
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"service,topic,parameters,payload,template,tpl_par,tpl_output",
|
||||
[
|
||||
(
|
||||
light.SERVICE_TURN_ON,
|
||||
"command_topic",
|
||||
None,
|
||||
"on,",
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
),
|
||||
(
|
||||
light.SERVICE_TURN_OFF,
|
||||
"command_topic",
|
||||
None,
|
||||
"off,",
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_publishing_with_custom_encoding(
|
||||
hass,
|
||||
mqtt_mock,
|
||||
caplog,
|
||||
service,
|
||||
topic,
|
||||
parameters,
|
||||
payload,
|
||||
template,
|
||||
tpl_par,
|
||||
tpl_output,
|
||||
):
|
||||
"""Test publishing MQTT payload with different encoding."""
|
||||
domain = light.DOMAIN
|
||||
config = copy.deepcopy(DEFAULT_CONFIG[domain])
|
||||
if topic == "effect_command_topic":
|
||||
config["effect_list"] = ["random", "color_loop"]
|
||||
elif topic == "white_command_topic":
|
||||
config["rgb_command_topic"] = "some-cmd-topic"
|
||||
|
||||
await help_test_publishing_with_custom_encoding(
|
||||
hass,
|
||||
mqtt_mock,
|
||||
caplog,
|
||||
domain,
|
||||
config,
|
||||
service,
|
||||
topic,
|
||||
parameters,
|
||||
payload,
|
||||
template,
|
||||
tpl_par=tpl_par,
|
||||
tpl_output=tpl_output,
|
||||
)
|
||||
|
Reference in New Issue
Block a user