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:
Jan Bouwhuis 2022-01-03 09:03:47 +01:00 committed by GitHub
parent 2cc4d9846b
commit d0c4f0fec4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 1283 additions and 27 deletions

View file

@ -1,4 +1,5 @@
"""Test MQTT humidifiers."""
import copy
from unittest.mock import patch
import pytest
@ -42,6 +43,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,
@ -1058,3 +1060,66 @@ async def test_entity_debug_info_message(hass, mqtt_mock):
await help_test_entity_debug_info_message(
hass, mqtt_mock, humidifier.DOMAIN, DEFAULT_CONFIG
)
@pytest.mark.parametrize(
"service,topic,parameters,payload,template",
[
(
humidifier.SERVICE_TURN_ON,
"command_topic",
None,
"ON",
None,
),
(
humidifier.SERVICE_TURN_OFF,
"command_topic",
None,
"OFF",
None,
),
(
humidifier.SERVICE_SET_MODE,
"mode_command_topic",
{humidifier.ATTR_MODE: "eco"},
"eco",
"mode_command_template",
),
(
humidifier.SERVICE_SET_HUMIDITY,
"target_humidity_command_topic",
{humidifier.ATTR_HUMIDITY: "45"},
45,
"target_humidity_command_template",
),
],
)
async def test_publishing_with_custom_encoding(
hass,
mqtt_mock,
caplog,
service,
topic,
parameters,
payload,
template,
):
"""Test publishing MQTT payload with different encoding."""
domain = humidifier.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG[domain])
if topic == "mode_command_topic":
config["modes"] = ["auto", "eco"]
await help_test_publishing_with_custom_encoding(
hass,
mqtt_mock,
caplog,
domain,
config,
service,
topic,
parameters,
payload,
template,
)