Prepare MQTT common tests part3 (#90022)
This commit is contained in:
parent
23f136e9d6
commit
d865440012
25 changed files with 1023 additions and 969 deletions
|
@ -1,6 +1,7 @@
|
||||||
"""The tests the MQTT alarm control panel component."""
|
"""The tests the MQTT alarm control panel component."""
|
||||||
import copy
|
import copy
|
||||||
import json
|
import json
|
||||||
|
from typing import Any
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -9,6 +10,7 @@ from homeassistant.components import alarm_control_panel, mqtt
|
||||||
from homeassistant.components.mqtt.alarm_control_panel import (
|
from homeassistant.components.mqtt.alarm_control_panel import (
|
||||||
MQTT_ALARM_ATTRIBUTES_BLOCKED,
|
MQTT_ALARM_ATTRIBUTES_BLOCKED,
|
||||||
)
|
)
|
||||||
|
from homeassistant.components.mqtt.models import PublishPayloadType
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_CODE,
|
ATTR_CODE,
|
||||||
ATTR_ENTITY_ID,
|
ATTR_ENTITY_ID,
|
||||||
|
@ -58,7 +60,6 @@ from .test_common import (
|
||||||
help_test_setting_attribute_via_mqtt_json_message,
|
help_test_setting_attribute_via_mqtt_json_message,
|
||||||
help_test_setting_attribute_with_template,
|
help_test_setting_attribute_with_template,
|
||||||
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
||||||
help_test_setup_manual_entity_from_yaml,
|
|
||||||
help_test_unique_id,
|
help_test_unique_id,
|
||||||
help_test_unload_config_entry_with_platform,
|
help_test_unload_config_entry_with_platform,
|
||||||
help_test_update_with_json_attrs_bad_json,
|
help_test_update_with_json_attrs_bad_json,
|
||||||
|
@ -172,10 +173,7 @@ async def test_fail_setup_without_state_or_command_topic(
|
||||||
hass: HomeAssistant, config, valid
|
hass: HomeAssistant, config, valid
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test for failing setup with no state or command topic."""
|
"""Test for failing setup with no state or command topic."""
|
||||||
assert (
|
assert help_test_validate_platform_config(hass, config) == valid
|
||||||
help_test_validate_platform_config(hass, alarm_control_panel.DOMAIN, config)
|
|
||||||
== valid
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||||
|
@ -722,30 +720,35 @@ async def test_discovery_update_attr(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"hass_config",
|
||||||
|
[
|
||||||
|
{
|
||||||
|
mqtt.DOMAIN: {
|
||||||
|
alarm_control_panel.DOMAIN: [
|
||||||
|
{
|
||||||
|
"name": "Test 1",
|
||||||
|
"state_topic": "test-topic",
|
||||||
|
"command_topic": "command-topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Test 2",
|
||||||
|
"state_topic": "test-topic",
|
||||||
|
"command_topic": "command-topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
)
|
||||||
async def test_unique_id(
|
async def test_unique_id(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test unique id option only creates one alarm per unique_id."""
|
"""Test unique id option only creates one alarm per unique_id."""
|
||||||
config = {
|
|
||||||
mqtt.DOMAIN: {
|
|
||||||
alarm_control_panel.DOMAIN: [
|
|
||||||
{
|
|
||||||
"name": "Test 1",
|
|
||||||
"state_topic": "test-topic",
|
|
||||||
"command_topic": "command-topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Test 2",
|
|
||||||
"state_topic": "test-topic",
|
|
||||||
"command_topic": "command-topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await help_test_unique_id(
|
await help_test_unique_id(
|
||||||
hass, mqtt_mock_entry_with_yaml_config, alarm_control_panel.DOMAIN, config
|
hass, mqtt_mock_entry_no_yaml_config, alarm_control_panel.DOMAIN
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -888,16 +891,14 @@ async def test_discovery_broken(
|
||||||
)
|
)
|
||||||
async def test_encoding_subscribable_topics(
|
async def test_encoding_subscribable_topics(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
topic: str,
|
||||||
topic,
|
value: str,
|
||||||
value,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test handling of incoming encoded payload."""
|
"""Test handling of incoming encoded payload."""
|
||||||
await help_test_encoding_subscribable_topics(
|
await help_test_encoding_subscribable_topics(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
caplog,
|
|
||||||
alarm_control_panel.DOMAIN,
|
alarm_control_panel.DOMAIN,
|
||||||
DEFAULT_CONFIG[mqtt.DOMAIN][alarm_control_panel.DOMAIN],
|
DEFAULT_CONFIG[mqtt.DOMAIN][alarm_control_panel.DOMAIN],
|
||||||
topic,
|
topic,
|
||||||
|
@ -954,14 +955,11 @@ async def test_entity_device_info_remove(
|
||||||
|
|
||||||
|
|
||||||
async def test_entity_id_update_subscriptions(
|
async def test_entity_id_update_subscriptions(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||||
await help_test_entity_id_update_subscriptions(
|
await help_test_entity_id_update_subscriptions(
|
||||||
hass,
|
hass, mqtt_mock_entry_no_yaml_config, alarm_control_panel.DOMAIN, DEFAULT_CONFIG
|
||||||
mqtt_mock_entry_with_yaml_config,
|
|
||||||
alarm_control_panel.DOMAIN,
|
|
||||||
DEFAULT_CONFIG,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1016,15 +1014,15 @@ async def test_entity_debug_info_message(
|
||||||
)
|
)
|
||||||
async def test_publishing_with_custom_encoding(
|
async def test_publishing_with_custom_encoding(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
service,
|
service: str,
|
||||||
topic,
|
topic: str,
|
||||||
parameters,
|
parameters: dict[str, Any],
|
||||||
payload,
|
payload: str,
|
||||||
template,
|
template: str | None,
|
||||||
tpl_par,
|
tpl_par: str,
|
||||||
tpl_output,
|
tpl_output: PublishPayloadType,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test publishing MQTT payload with different encoding."""
|
"""Test publishing MQTT payload with different encoding."""
|
||||||
domain = alarm_control_panel.DOMAIN
|
domain = alarm_control_panel.DOMAIN
|
||||||
|
@ -1032,7 +1030,7 @@ async def test_publishing_with_custom_encoding(
|
||||||
|
|
||||||
await help_test_publishing_with_custom_encoding(
|
await help_test_publishing_with_custom_encoding(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
caplog,
|
caplog,
|
||||||
domain,
|
domain,
|
||||||
config,
|
config,
|
||||||
|
@ -1056,10 +1054,13 @@ async def test_reloadable(
|
||||||
await help_test_reloadable(hass, mqtt_client_mock, domain, config)
|
await help_test_reloadable(hass, mqtt_client_mock, domain, config)
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None:
|
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||||
|
async def test_setup_manual_entity_from_yaml(
|
||||||
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
|
) -> None:
|
||||||
"""Test setup manual configured MQTT entity."""
|
"""Test setup manual configured MQTT entity."""
|
||||||
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
platform = alarm_control_panel.DOMAIN
|
platform = alarm_control_panel.DOMAIN
|
||||||
await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
|
|
||||||
assert hass.states.get(f"{platform}.test")
|
assert hass.states.get(f"{platform}.test")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ import copy
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import json
|
import json
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from typing import Any
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from freezegun.api import FrozenDateTimeFactory
|
from freezegun.api import FrozenDateTimeFactory
|
||||||
|
@ -43,7 +44,6 @@ from .test_common import (
|
||||||
help_test_reloadable,
|
help_test_reloadable,
|
||||||
help_test_setting_attribute_via_mqtt_json_message,
|
help_test_setting_attribute_via_mqtt_json_message,
|
||||||
help_test_setting_attribute_with_template,
|
help_test_setting_attribute_with_template,
|
||||||
help_test_setup_manual_entity_from_yaml,
|
|
||||||
help_test_unique_id,
|
help_test_unique_id,
|
||||||
help_test_unload_config_entry_with_platform,
|
help_test_unload_config_entry_with_platform,
|
||||||
help_test_update_with_json_attrs_bad_json,
|
help_test_update_with_json_attrs_bad_json,
|
||||||
|
@ -781,28 +781,33 @@ async def test_discovery_update_attr(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"hass_config",
|
||||||
|
[
|
||||||
|
{
|
||||||
|
mqtt.DOMAIN: {
|
||||||
|
binary_sensor.DOMAIN: [
|
||||||
|
{
|
||||||
|
"name": "Test 1",
|
||||||
|
"state_topic": "test-topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Test 2",
|
||||||
|
"state_topic": "test-topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
)
|
||||||
async def test_unique_id(
|
async def test_unique_id(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test unique id option only creates one sensor per unique_id."""
|
"""Test unique id option only creates one sensor per unique_id."""
|
||||||
config = {
|
|
||||||
mqtt.DOMAIN: {
|
|
||||||
binary_sensor.DOMAIN: [
|
|
||||||
{
|
|
||||||
"name": "Test 1",
|
|
||||||
"state_topic": "test-topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Test 2",
|
|
||||||
"state_topic": "test-topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await help_test_unique_id(
|
await help_test_unique_id(
|
||||||
hass, mqtt_mock_entry_with_yaml_config, binary_sensor.DOMAIN, config
|
hass, mqtt_mock_entry_no_yaml_config, binary_sensor.DOMAIN
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -909,18 +914,16 @@ async def test_discovery_update_binary_sensor_template(
|
||||||
)
|
)
|
||||||
async def test_encoding_subscribable_topics(
|
async def test_encoding_subscribable_topics(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
topic: str,
|
||||||
topic,
|
value: str,
|
||||||
value,
|
attribute: str | None,
|
||||||
attribute,
|
attribute_value: Any,
|
||||||
attribute_value,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test handling of incoming encoded payload."""
|
"""Test handling of incoming encoded payload."""
|
||||||
await help_test_encoding_subscribable_topics(
|
await help_test_encoding_subscribable_topics(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
caplog,
|
|
||||||
binary_sensor.DOMAIN,
|
binary_sensor.DOMAIN,
|
||||||
DEFAULT_CONFIG[mqtt.DOMAIN][binary_sensor.DOMAIN],
|
DEFAULT_CONFIG[mqtt.DOMAIN][binary_sensor.DOMAIN],
|
||||||
topic,
|
topic,
|
||||||
|
@ -1021,14 +1024,11 @@ async def test_entity_device_info_remove(
|
||||||
|
|
||||||
|
|
||||||
async def test_entity_id_update_subscriptions(
|
async def test_entity_id_update_subscriptions(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||||
await help_test_entity_id_update_subscriptions(
|
await help_test_entity_id_update_subscriptions(
|
||||||
hass,
|
hass, mqtt_mock_entry_no_yaml_config, binary_sensor.DOMAIN, DEFAULT_CONFIG
|
||||||
mqtt_mock_entry_with_yaml_config,
|
|
||||||
binary_sensor.DOMAIN,
|
|
||||||
DEFAULT_CONFIG,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1162,10 +1162,13 @@ async def test_skip_restoring_state_with_over_due_expire_trigger(
|
||||||
assert state.state == STATE_UNAVAILABLE
|
assert state.state == STATE_UNAVAILABLE
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None:
|
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||||
|
async def test_setup_manual_entity_from_yaml(
|
||||||
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
|
) -> None:
|
||||||
"""Test setup manual configured MQTT entity."""
|
"""Test setup manual configured MQTT entity."""
|
||||||
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
platform = binary_sensor.DOMAIN
|
platform = binary_sensor.DOMAIN
|
||||||
await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
|
|
||||||
assert hass.states.get(f"{platform}.test")
|
assert hass.states.get(f"{platform}.test")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
"""The tests for the MQTT button platform."""
|
"""The tests for the MQTT button platform."""
|
||||||
import copy
|
import copy
|
||||||
|
from typing import Any
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -35,7 +36,6 @@ from .test_common import (
|
||||||
help_test_setting_attribute_via_mqtt_json_message,
|
help_test_setting_attribute_via_mqtt_json_message,
|
||||||
help_test_setting_attribute_with_template,
|
help_test_setting_attribute_with_template,
|
||||||
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
||||||
help_test_setup_manual_entity_from_yaml,
|
|
||||||
help_test_unique_id,
|
help_test_unique_id,
|
||||||
help_test_unload_config_entry_with_platform,
|
help_test_unload_config_entry_with_platform,
|
||||||
help_test_update_with_json_attrs_bad_json,
|
help_test_update_with_json_attrs_bad_json,
|
||||||
|
@ -277,29 +277,32 @@ async def test_discovery_update_attr(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"hass_config",
|
||||||
|
[
|
||||||
|
{
|
||||||
|
mqtt.DOMAIN: {
|
||||||
|
button.DOMAIN: [
|
||||||
|
{
|
||||||
|
"name": "Test 1",
|
||||||
|
"command_topic": "command-topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Test 2",
|
||||||
|
"command_topic": "command-topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
)
|
||||||
async def test_unique_id(
|
async def test_unique_id(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test unique id option only creates one button per unique_id."""
|
"""Test unique id option only creates one button per unique_id."""
|
||||||
config = {
|
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN)
|
||||||
mqtt.DOMAIN: {
|
|
||||||
button.DOMAIN: [
|
|
||||||
{
|
|
||||||
"name": "Test 1",
|
|
||||||
"command_topic": "command-topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Test 2",
|
|
||||||
"command_topic": "command-topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await help_test_unique_id(
|
|
||||||
hass, mqtt_mock_entry_with_yaml_config, button.DOMAIN, config
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_discovery_removal_button(
|
async def test_discovery_removal_button(
|
||||||
|
@ -497,13 +500,13 @@ async def test_valid_device_class(
|
||||||
)
|
)
|
||||||
async def test_publishing_with_custom_encoding(
|
async def test_publishing_with_custom_encoding(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
service,
|
service: str,
|
||||||
topic,
|
topic: str,
|
||||||
parameters,
|
parameters: dict[str, Any],
|
||||||
payload,
|
payload: str,
|
||||||
template,
|
template: str | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test publishing MQTT payload with different encoding."""
|
"""Test publishing MQTT payload with different encoding."""
|
||||||
domain = button.DOMAIN
|
domain = button.DOMAIN
|
||||||
|
@ -511,7 +514,7 @@ async def test_publishing_with_custom_encoding(
|
||||||
|
|
||||||
await help_test_publishing_with_custom_encoding(
|
await help_test_publishing_with_custom_encoding(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
caplog,
|
caplog,
|
||||||
domain,
|
domain,
|
||||||
config,
|
config,
|
||||||
|
@ -533,10 +536,13 @@ async def test_reloadable(
|
||||||
await help_test_reloadable(hass, mqtt_client_mock, domain, config)
|
await help_test_reloadable(hass, mqtt_client_mock, domain, config)
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None:
|
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||||
|
async def test_setup_manual_entity_from_yaml(
|
||||||
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
|
) -> None:
|
||||||
"""Test setup manual configured MQTT entity."""
|
"""Test setup manual configured MQTT entity."""
|
||||||
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
platform = button.DOMAIN
|
platform = button.DOMAIN
|
||||||
await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
|
|
||||||
assert hass.states.get(f"{platform}.test")
|
assert hass.states.get(f"{platform}.test")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,6 @@ from .test_common import (
|
||||||
help_test_setting_attribute_via_mqtt_json_message,
|
help_test_setting_attribute_via_mqtt_json_message,
|
||||||
help_test_setting_attribute_with_template,
|
help_test_setting_attribute_with_template,
|
||||||
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
||||||
help_test_setup_manual_entity_from_yaml,
|
|
||||||
help_test_unique_id,
|
help_test_unique_id,
|
||||||
help_test_unload_config_entry_with_platform,
|
help_test_unload_config_entry_with_platform,
|
||||||
help_test_update_with_json_attrs_bad_json,
|
help_test_update_with_json_attrs_bad_json,
|
||||||
|
@ -271,29 +270,32 @@ async def test_discovery_update_attr(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"hass_config",
|
||||||
|
[
|
||||||
|
{
|
||||||
|
mqtt.DOMAIN: {
|
||||||
|
camera.DOMAIN: [
|
||||||
|
{
|
||||||
|
"name": "Test 1",
|
||||||
|
"topic": "test-topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Test 2",
|
||||||
|
"topic": "test-topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
)
|
||||||
async def test_unique_id(
|
async def test_unique_id(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test unique id option only creates one camera per unique_id."""
|
"""Test unique id option only creates one camera per unique_id."""
|
||||||
config = {
|
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN)
|
||||||
mqtt.DOMAIN: {
|
|
||||||
camera.DOMAIN: [
|
|
||||||
{
|
|
||||||
"name": "Test 1",
|
|
||||||
"topic": "test-topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Test 2",
|
|
||||||
"topic": "test-topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await help_test_unique_id(
|
|
||||||
hass, mqtt_mock_entry_with_yaml_config, camera.DOMAIN, config
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_discovery_removal_camera(
|
async def test_discovery_removal_camera(
|
||||||
|
@ -394,12 +396,12 @@ async def test_entity_device_info_remove(
|
||||||
|
|
||||||
|
|
||||||
async def test_entity_id_update_subscriptions(
|
async def test_entity_id_update_subscriptions(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||||
await help_test_entity_id_update_subscriptions(
|
await help_test_entity_id_update_subscriptions(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
camera.DOMAIN,
|
camera.DOMAIN,
|
||||||
DEFAULT_CONFIG,
|
DEFAULT_CONFIG,
|
||||||
["test_topic"],
|
["test_topic"],
|
||||||
|
@ -440,10 +442,13 @@ async def test_reloadable(
|
||||||
await help_test_reloadable(hass, mqtt_client_mock, domain, config)
|
await help_test_reloadable(hass, mqtt_client_mock, domain, config)
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None:
|
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||||
|
async def test_setup_manual_entity_from_yaml(
|
||||||
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
|
) -> None:
|
||||||
"""Test setup manual configured MQTT entity."""
|
"""Test setup manual configured MQTT entity."""
|
||||||
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
platform = camera.DOMAIN
|
platform = camera.DOMAIN
|
||||||
await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
|
|
||||||
assert hass.states.get(f"{platform}.test")
|
assert hass.states.get(f"{platform}.test")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
"""The tests for the mqtt climate component."""
|
"""The tests for the mqtt climate component."""
|
||||||
import copy
|
import copy
|
||||||
import json
|
import json
|
||||||
|
from typing import Any
|
||||||
from unittest.mock import call, patch
|
from unittest.mock import call, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -54,7 +55,6 @@ from .test_common import (
|
||||||
help_test_setting_attribute_via_mqtt_json_message,
|
help_test_setting_attribute_via_mqtt_json_message,
|
||||||
help_test_setting_attribute_with_template,
|
help_test_setting_attribute_with_template,
|
||||||
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
||||||
help_test_setup_manual_entity_from_yaml,
|
|
||||||
help_test_unique_id,
|
help_test_unique_id,
|
||||||
help_test_unload_config_entry_with_platform,
|
help_test_unload_config_entry_with_platform,
|
||||||
help_test_update_with_json_attrs_bad_json,
|
help_test_update_with_json_attrs_bad_json,
|
||||||
|
@ -1562,31 +1562,34 @@ async def test_discovery_update_attr(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"hass_config",
|
||||||
|
[
|
||||||
|
{
|
||||||
|
mqtt.DOMAIN: {
|
||||||
|
climate.DOMAIN: [
|
||||||
|
{
|
||||||
|
"name": "Test 1",
|
||||||
|
"mode_state_topic": "test_topic1/state",
|
||||||
|
"mode_command_topic": "test_topic1/command",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Test 2",
|
||||||
|
"mode_state_topic": "test_topic2/state",
|
||||||
|
"mode_command_topic": "test_topic2/command",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
)
|
||||||
async def test_unique_id(
|
async def test_unique_id(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test unique id option only creates one climate per unique_id."""
|
"""Test unique id option only creates one climate per unique_id."""
|
||||||
config = {
|
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN)
|
||||||
mqtt.DOMAIN: {
|
|
||||||
climate.DOMAIN: [
|
|
||||||
{
|
|
||||||
"name": "Test 1",
|
|
||||||
"mode_state_topic": "test_topic1/state",
|
|
||||||
"mode_command_topic": "test_topic1/command",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Test 2",
|
|
||||||
"mode_state_topic": "test_topic2/state",
|
|
||||||
"mode_command_topic": "test_topic2/command",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await help_test_unique_id(
|
|
||||||
hass, mqtt_mock_entry_with_yaml_config, climate.DOMAIN, config
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
@ -1609,19 +1612,17 @@ async def test_unique_id(
|
||||||
)
|
)
|
||||||
async def test_encoding_subscribable_topics(
|
async def test_encoding_subscribable_topics(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
topic: str,
|
||||||
topic,
|
value: str,
|
||||||
value,
|
attribute: str | None,
|
||||||
attribute,
|
attribute_value: Any,
|
||||||
attribute_value,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test handling of incoming encoded payload."""
|
"""Test handling of incoming encoded payload."""
|
||||||
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][climate.DOMAIN])
|
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][climate.DOMAIN])
|
||||||
await help_test_encoding_subscribable_topics(
|
await help_test_encoding_subscribable_topics(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
caplog,
|
|
||||||
climate.DOMAIN,
|
climate.DOMAIN,
|
||||||
config,
|
config,
|
||||||
topic,
|
topic,
|
||||||
|
@ -1727,7 +1728,7 @@ async def test_entity_device_info_remove(
|
||||||
|
|
||||||
|
|
||||||
async def test_entity_id_update_subscriptions(
|
async def test_entity_id_update_subscriptions(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||||
config = {
|
config = {
|
||||||
|
@ -1741,7 +1742,7 @@ async def test_entity_id_update_subscriptions(
|
||||||
}
|
}
|
||||||
await help_test_entity_id_update_subscriptions(
|
await help_test_entity_id_update_subscriptions(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
climate.DOMAIN,
|
climate.DOMAIN,
|
||||||
config,
|
config,
|
||||||
["test-topic", "avty-topic"],
|
["test-topic", "avty-topic"],
|
||||||
|
@ -1919,13 +1920,13 @@ async def test_precision_whole(
|
||||||
)
|
)
|
||||||
async def test_publishing_with_custom_encoding(
|
async def test_publishing_with_custom_encoding(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
service,
|
service: str,
|
||||||
topic,
|
topic: str,
|
||||||
parameters,
|
parameters: dict[str, Any],
|
||||||
payload,
|
payload: str,
|
||||||
template,
|
template: str | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test publishing MQTT payload with different encoding."""
|
"""Test publishing MQTT payload with different encoding."""
|
||||||
domain = climate.DOMAIN
|
domain = climate.DOMAIN
|
||||||
|
@ -1936,7 +1937,7 @@ async def test_publishing_with_custom_encoding(
|
||||||
|
|
||||||
await help_test_publishing_with_custom_encoding(
|
await help_test_publishing_with_custom_encoding(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
caplog,
|
caplog,
|
||||||
domain,
|
domain,
|
||||||
config,
|
config,
|
||||||
|
@ -2016,10 +2017,13 @@ async def test_reloadable(
|
||||||
await help_test_reloadable(hass, mqtt_client_mock, domain, config)
|
await help_test_reloadable(hass, mqtt_client_mock, domain, config)
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None:
|
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||||
|
async def test_setup_manual_entity_from_yaml(
|
||||||
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
|
) -> None:
|
||||||
"""Test setup manual configured MQTT entity."""
|
"""Test setup manual configured MQTT entity."""
|
||||||
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
platform = climate.DOMAIN
|
platform = climate.DOMAIN
|
||||||
await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
|
|
||||||
assert hass.states.get(f"{platform}.test")
|
assert hass.states.get(f"{platform}.test")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ from homeassistant.components.mqtt import debug_info
|
||||||
from homeassistant.components.mqtt.config_integration import PLATFORM_CONFIG_SCHEMA_BASE
|
from homeassistant.components.mqtt.config_integration import PLATFORM_CONFIG_SCHEMA_BASE
|
||||||
from homeassistant.components.mqtt.const import MQTT_DISCONNECTED
|
from homeassistant.components.mqtt.const import MQTT_DISCONNECTED
|
||||||
from homeassistant.components.mqtt.mixins import MQTT_ATTRIBUTES_BLOCKED
|
from homeassistant.components.mqtt.mixins import MQTT_ATTRIBUTES_BLOCKED
|
||||||
|
from homeassistant.components.mqtt.models import PublishPayloadType
|
||||||
from homeassistant.config import async_log_exception
|
from homeassistant.config import async_log_exception
|
||||||
from homeassistant.config_entries import ConfigEntryState
|
from homeassistant.config_entries import ConfigEntryState
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
|
@ -73,7 +74,7 @@ MQTT_YAML_SCHEMA = vol.Schema({mqtt.DOMAIN: PLATFORM_CONFIG_SCHEMA_BASE})
|
||||||
|
|
||||||
|
|
||||||
def help_test_validate_platform_config(
|
def help_test_validate_platform_config(
|
||||||
hass: HomeAssistant, domain: str, config: ConfigType
|
hass: HomeAssistant, config: ConfigType
|
||||||
) -> ConfigType | None:
|
) -> ConfigType | None:
|
||||||
"""Test the schema validation."""
|
"""Test the schema validation."""
|
||||||
try:
|
try:
|
||||||
|
@ -82,7 +83,7 @@ def help_test_validate_platform_config(
|
||||||
return True
|
return True
|
||||||
except vol.Error as exc:
|
except vol.Error as exc:
|
||||||
# log schema exceptions
|
# log schema exceptions
|
||||||
async_log_exception(exc, domain, config, hass)
|
async_log_exception(exc, mqtt.DOMAIN, config, hass)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@ -394,10 +395,10 @@ async def help_test_default_availability_list_single(
|
||||||
{"topic": "availability-topic1"},
|
{"topic": "availability-topic1"},
|
||||||
]
|
]
|
||||||
config[mqtt.DOMAIN][domain]["availability_topic"] = "availability-topic"
|
config[mqtt.DOMAIN][domain]["availability_topic"] = "availability-topic"
|
||||||
help_test_validate_platform_config(hass, domain, config)
|
help_test_validate_platform_config(hass, config)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
f"Invalid config for [{domain}]: two or more values in the same group of exclusion 'availability'"
|
"Invalid config for [mqtt]: two or more values in the same group of exclusion 'availability'"
|
||||||
in caplog.text
|
in caplog.text
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -698,14 +699,12 @@ async def help_test_discovery_update_attr(
|
||||||
|
|
||||||
async def help_test_unique_id(
|
async def help_test_unique_id(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
domain: str,
|
domain: str,
|
||||||
config: ConfigType,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test unique id option only creates one entity per unique_id."""
|
"""Test unique id option only creates one entity per unique_id."""
|
||||||
assert await async_setup_component(hass, mqtt.DOMAIN, config)
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
await mqtt_mock_entry_with_yaml_config()
|
|
||||||
assert len(hass.states.async_entity_ids(domain)) == 1
|
assert len(hass.states.async_entity_ids(domain)) == 1
|
||||||
|
|
||||||
|
|
||||||
|
@ -854,15 +853,14 @@ async def help_test_discovery_broken(
|
||||||
|
|
||||||
async def help_test_encoding_subscribable_topics(
|
async def help_test_encoding_subscribable_topics(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
|
||||||
domain: str,
|
domain: str,
|
||||||
config: ConfigType,
|
config: ConfigType,
|
||||||
topic: str,
|
topic: str,
|
||||||
value: Any,
|
value: Any,
|
||||||
attribute: str | None = None,
|
attribute: str | None = None,
|
||||||
attribute_value: Any = None,
|
attribute_value: Any = None,
|
||||||
init_payload: str | None = None,
|
init_payload: tuple[str, str] | None = None,
|
||||||
skip_raw_test: bool = False,
|
skip_raw_test: bool = False,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test handling of incoming encoded payload."""
|
"""Test handling of incoming encoded payload."""
|
||||||
|
@ -929,13 +927,17 @@ async def help_test_encoding_subscribable_topics(
|
||||||
init_payload_value_utf8 = init_payload[1].encode("utf-8")
|
init_payload_value_utf8 = init_payload[1].encode("utf-8")
|
||||||
init_payload_value_utf16 = init_payload[1].encode("utf-16")
|
init_payload_value_utf16 = init_payload[1].encode("utf-16")
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
|
async_fire_mqtt_message(
|
||||||
assert await async_setup_component(
|
hass, f"homeassistant/{domain}/item1/config", json.dumps(config1)
|
||||||
hass, mqtt.DOMAIN, {mqtt.DOMAIN: {domain: [config1, config2, config3]}}
|
)
|
||||||
|
async_fire_mqtt_message(
|
||||||
|
hass, f"homeassistant/{domain}/item2/config", json.dumps(config2)
|
||||||
|
)
|
||||||
|
async_fire_mqtt_message(
|
||||||
|
hass, f"homeassistant/{domain}/item3/config", json.dumps(config3)
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
await mqtt_mock_entry_with_yaml_config()
|
|
||||||
|
|
||||||
expected_result = attribute_value or value
|
expected_result = attribute_value or value
|
||||||
|
|
||||||
|
@ -1124,7 +1126,7 @@ async def help_test_entity_device_info_update(
|
||||||
|
|
||||||
async def help_test_entity_id_update_subscriptions(
|
async def help_test_entity_id_update_subscriptions(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
domain: str,
|
domain: str,
|
||||||
config: ConfigType,
|
config: ConfigType,
|
||||||
topics: list[str] | None = None,
|
topics: list[str] | None = None,
|
||||||
|
@ -1142,13 +1144,10 @@ async def help_test_entity_id_update_subscriptions(
|
||||||
assert len(topics) > 0
|
assert len(topics) > 0
|
||||||
entity_registry = er.async_get(hass)
|
entity_registry = er.async_get(hass)
|
||||||
|
|
||||||
assert await async_setup_component(
|
mqtt_mock = await help_setup_component(
|
||||||
hass,
|
hass, mqtt_mock_entry_no_yaml_config, domain, config, True
|
||||||
mqtt.DOMAIN,
|
|
||||||
config,
|
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
assert mqtt_mock is not None
|
||||||
mqtt_mock = await mqtt_mock_entry_with_yaml_config()
|
|
||||||
|
|
||||||
state = hass.states.get(f"{domain}.test")
|
state = hass.states.get(f"{domain}.test")
|
||||||
assert state is not None
|
assert state is not None
|
||||||
|
@ -1632,7 +1631,7 @@ async def help_test_entity_category(
|
||||||
|
|
||||||
async def help_test_publishing_with_custom_encoding(
|
async def help_test_publishing_with_custom_encoding(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
domain: str,
|
domain: str,
|
||||||
config: ConfigType,
|
config: ConfigType,
|
||||||
|
@ -1642,7 +1641,7 @@ async def help_test_publishing_with_custom_encoding(
|
||||||
payload: str,
|
payload: str,
|
||||||
template: str | None,
|
template: str | None,
|
||||||
tpl_par: str = "value",
|
tpl_par: str = "value",
|
||||||
tpl_output: str | None = None,
|
tpl_output: PublishPayloadType = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test a service with publishing MQTT payload with different encoding."""
|
"""Test a service with publishing MQTT payload with different encoding."""
|
||||||
# prepare config for tests
|
# prepare config for tests
|
||||||
|
@ -1676,14 +1675,16 @@ async def help_test_publishing_with_custom_encoding(
|
||||||
if parameters:
|
if parameters:
|
||||||
service_data[test_id].update(parameters)
|
service_data[test_id].update(parameters)
|
||||||
|
|
||||||
# setup test entities
|
# setup test entities using discovery
|
||||||
assert await async_setup_component(
|
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||||
hass,
|
item: int = 0
|
||||||
mqtt.DOMAIN,
|
for component_config in setup_config:
|
||||||
{mqtt.DOMAIN: {domain: setup_config}},
|
conf = json.dumps(component_config)
|
||||||
)
|
item += 1
|
||||||
|
async_fire_mqtt_message(
|
||||||
|
hass, f"homeassistant/{domain}/component_{item}/config", conf
|
||||||
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
mqtt_mock = await mqtt_mock_entry_with_yaml_config()
|
|
||||||
|
|
||||||
# 1) test with default encoding
|
# 1) test with default encoding
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
|
@ -1692,6 +1693,7 @@ async def help_test_publishing_with_custom_encoding(
|
||||||
service_data["test1"],
|
service_data["test1"],
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
mqtt_mock.async_publish.assert_any_call("cmd/test1", str(payload), 0, False)
|
mqtt_mock.async_publish.assert_any_call("cmd/test1", str(payload), 0, False)
|
||||||
mqtt_mock.async_publish.reset_mock()
|
mqtt_mock.async_publish.reset_mock()
|
||||||
|
@ -1816,8 +1818,7 @@ async def help_test_reloadable(
|
||||||
# We should call await mqtt.async_setup_entry(hass, entry) when async_setup
|
# We should call await mqtt.async_setup_entry(hass, entry) when async_setup
|
||||||
# is removed (this is planned with #87987). Until then we set up the mqtt component
|
# is removed (this is planned with #87987). Until then we set up the mqtt component
|
||||||
# to test reload after the async_setup setup has set the initial config
|
# to test reload after the async_setup setup has set the initial config
|
||||||
await async_setup_component(hass, mqtt.DOMAIN, old_config)
|
await help_setup_component(hass, None, domain, old_config, use_discovery=False)
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert hass.states.get(f"{domain}.test_old_1")
|
assert hass.states.get(f"{domain}.test_old_1")
|
||||||
assert hass.states.get(f"{domain}.test_old_2")
|
assert hass.states.get(f"{domain}.test_old_2")
|
||||||
|
@ -1852,23 +1853,6 @@ async def help_test_reloadable(
|
||||||
assert hass.states.get(f"{domain}.test_new_3")
|
assert hass.states.get(f"{domain}.test_new_3")
|
||||||
|
|
||||||
|
|
||||||
async def help_test_setup_manual_entity_from_yaml(
|
|
||||||
hass: HomeAssistant, config: ConfigType
|
|
||||||
) -> None:
|
|
||||||
"""Help to test setup from yaml through configuration entry."""
|
|
||||||
# until `async_setup` does the initial config setup, we need to use
|
|
||||||
# async_setup_component to test with other yaml config
|
|
||||||
assert await async_setup_component(hass, mqtt.DOMAIN, config)
|
|
||||||
# Mock config entry
|
|
||||||
entry = MockConfigEntry(domain=mqtt.DOMAIN, data={mqtt.CONF_BROKER: "test-broker"})
|
|
||||||
entry.add_to_hass(hass)
|
|
||||||
|
|
||||||
with patch("paho.mqtt.client.Client") as mock_client:
|
|
||||||
mock_client().connect = lambda *args: 0
|
|
||||||
assert await hass.config_entries.async_setup(entry.entry_id)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
|
|
||||||
async def help_test_unload_config_entry(hass: HomeAssistant) -> None:
|
async def help_test_unload_config_entry(hass: HomeAssistant) -> None:
|
||||||
"""Test unloading the MQTT config entry."""
|
"""Test unloading the MQTT config entry."""
|
||||||
mqtt_config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0]
|
mqtt_config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0]
|
||||||
|
@ -1892,9 +1876,9 @@ async def help_test_unload_config_entry_with_platform(
|
||||||
config_setup: dict[str, dict[str, Any]] = copy.deepcopy(config)
|
config_setup: dict[str, dict[str, Any]] = copy.deepcopy(config)
|
||||||
config_setup[mqtt.DOMAIN][domain]["name"] = "config_setup"
|
config_setup[mqtt.DOMAIN][domain]["name"] = "config_setup"
|
||||||
config_name = config_setup
|
config_name = config_setup
|
||||||
# To be replaced with entry setup when `async_setup` is removed.
|
await help_setup_component(
|
||||||
assert await async_setup_component(hass, mqtt.DOMAIN, config_setup)
|
hass, mqtt_mock_entry_no_yaml_config, domain, config_setup
|
||||||
await hass.async_block_till_done()
|
)
|
||||||
|
|
||||||
# prepare setup through discovery
|
# prepare setup through discovery
|
||||||
discovery_setup = copy.deepcopy(config[mqtt.DOMAIN][domain])
|
discovery_setup = copy.deepcopy(config[mqtt.DOMAIN][domain])
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
"""The tests for the MQTT cover platform."""
|
"""The tests for the MQTT cover platform."""
|
||||||
|
from typing import Any
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -69,7 +70,6 @@ from .test_common import (
|
||||||
help_test_setting_attribute_via_mqtt_json_message,
|
help_test_setting_attribute_via_mqtt_json_message,
|
||||||
help_test_setting_attribute_with_template,
|
help_test_setting_attribute_with_template,
|
||||||
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
||||||
help_test_setup_manual_entity_from_yaml,
|
|
||||||
help_test_unique_id,
|
help_test_unique_id,
|
||||||
help_test_unload_config_entry_with_platform,
|
help_test_unload_config_entry_with_platform,
|
||||||
help_test_update_with_json_attrs_bad_json,
|
help_test_update_with_json_attrs_bad_json,
|
||||||
|
@ -2666,29 +2666,32 @@ async def test_discovery_update_attr(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"hass_config",
|
||||||
|
[
|
||||||
|
{
|
||||||
|
mqtt.DOMAIN: {
|
||||||
|
cover.DOMAIN: [
|
||||||
|
{
|
||||||
|
"name": "Test 1",
|
||||||
|
"state_topic": "test-topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Test 2",
|
||||||
|
"state_topic": "test-topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
)
|
||||||
async def test_unique_id(
|
async def test_unique_id(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test unique_id option only creates one cover per id."""
|
"""Test unique_id option only creates one cover per id."""
|
||||||
config = {
|
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, cover.DOMAIN)
|
||||||
mqtt.DOMAIN: {
|
|
||||||
cover.DOMAIN: [
|
|
||||||
{
|
|
||||||
"name": "Test 1",
|
|
||||||
"state_topic": "test-topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Test 2",
|
|
||||||
"state_topic": "test-topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await help_test_unique_id(
|
|
||||||
hass, mqtt_mock_entry_with_yaml_config, cover.DOMAIN, config
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_discovery_removal_cover(
|
async def test_discovery_removal_cover(
|
||||||
|
@ -2787,11 +2790,11 @@ async def test_entity_device_info_remove(
|
||||||
|
|
||||||
|
|
||||||
async def test_entity_id_update_subscriptions(
|
async def test_entity_id_update_subscriptions(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||||
await help_test_entity_id_update_subscriptions(
|
await help_test_entity_id_update_subscriptions(
|
||||||
hass, mqtt_mock_entry_with_yaml_config, cover.DOMAIN, DEFAULT_CONFIG
|
hass, mqtt_mock_entry_no_yaml_config, cover.DOMAIN, DEFAULT_CONFIG
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -3469,13 +3472,13 @@ async def test_tilt_status_template_without_tilt_status_topic_topic(
|
||||||
)
|
)
|
||||||
async def test_publishing_with_custom_encoding(
|
async def test_publishing_with_custom_encoding(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
service,
|
service: str,
|
||||||
topic,
|
topic: str,
|
||||||
parameters,
|
parameters: dict[str, Any],
|
||||||
payload,
|
payload: str,
|
||||||
template,
|
template: str | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test publishing MQTT payload with different encoding."""
|
"""Test publishing MQTT payload with different encoding."""
|
||||||
domain = cover.DOMAIN
|
domain = cover.DOMAIN
|
||||||
|
@ -3484,7 +3487,7 @@ async def test_publishing_with_custom_encoding(
|
||||||
|
|
||||||
await help_test_publishing_with_custom_encoding(
|
await help_test_publishing_with_custom_encoding(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
caplog,
|
caplog,
|
||||||
domain,
|
domain,
|
||||||
config,
|
config,
|
||||||
|
@ -3517,18 +3520,16 @@ async def test_reloadable(
|
||||||
)
|
)
|
||||||
async def test_encoding_subscribable_topics(
|
async def test_encoding_subscribable_topics(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
topic: str,
|
||||||
topic,
|
value: str,
|
||||||
value,
|
attribute: str | None,
|
||||||
attribute,
|
attribute_value: Any,
|
||||||
attribute_value,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test handling of incoming encoded payload."""
|
"""Test handling of incoming encoded payload."""
|
||||||
await help_test_encoding_subscribable_topics(
|
await help_test_encoding_subscribable_topics(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
caplog,
|
|
||||||
cover.DOMAIN,
|
cover.DOMAIN,
|
||||||
DEFAULT_CONFIG[mqtt.DOMAIN][cover.DOMAIN],
|
DEFAULT_CONFIG[mqtt.DOMAIN][cover.DOMAIN],
|
||||||
topic,
|
topic,
|
||||||
|
@ -3539,10 +3540,13 @@ async def test_encoding_subscribable_topics(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None:
|
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||||
|
async def test_setup_manual_entity_from_yaml(
|
||||||
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
|
) -> None:
|
||||||
"""Test setup manual configured MQTT entity."""
|
"""Test setup manual configured MQTT entity."""
|
||||||
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
platform = cover.DOMAIN
|
platform = cover.DOMAIN
|
||||||
await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
|
|
||||||
assert hass.states.get(f"{platform}.test")
|
assert hass.states.get(f"{platform}.test")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,17 +4,13 @@ from unittest.mock import patch
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components import device_tracker, mqtt
|
from homeassistant.components import device_tracker, mqtt
|
||||||
from homeassistant.components.device_tracker import legacy
|
|
||||||
from homeassistant.components.mqtt.const import DOMAIN as MQTT_DOMAIN
|
from homeassistant.components.mqtt.const import DOMAIN as MQTT_DOMAIN
|
||||||
from homeassistant.const import STATE_HOME, STATE_NOT_HOME, STATE_UNKNOWN, Platform
|
from homeassistant.const import STATE_HOME, STATE_NOT_HOME, STATE_UNKNOWN, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from .test_common import (
|
from .test_common import help_test_setting_blocked_attribute_via_mqtt_json_message
|
||||||
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
|
||||||
help_test_setup_manual_entity_from_yaml,
|
|
||||||
)
|
|
||||||
|
|
||||||
from tests.common import async_fire_mqtt_message
|
from tests.common import async_fire_mqtt_message
|
||||||
from tests.typing import MqttMockHAClientGenerator, WebSocketGenerator
|
from tests.typing import MqttMockHAClientGenerator, WebSocketGenerator
|
||||||
|
@ -589,18 +585,21 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"hass_config",
|
||||||
|
[
|
||||||
|
{
|
||||||
|
mqtt.DOMAIN: {
|
||||||
|
device_tracker.DOMAIN: {"name": "jan", "state_topic": "/location/jan"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
)
|
||||||
async def test_setup_with_modern_schema(
|
async def test_setup_with_modern_schema(
|
||||||
hass: HomeAssistant, mock_device_tracker_conf: list[legacy.Device]
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test setup using the modern schema."""
|
"""Test setup using the modern schema."""
|
||||||
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
dev_id = "jan"
|
dev_id = "jan"
|
||||||
entity_id = f"{device_tracker.DOMAIN}.{dev_id}"
|
entity_id = f"{device_tracker.DOMAIN}.{dev_id}"
|
||||||
topic = "/location/jan"
|
|
||||||
|
|
||||||
config = {
|
|
||||||
mqtt.DOMAIN: {device_tracker.DOMAIN: {"name": dev_id, "state_topic": topic}}
|
|
||||||
}
|
|
||||||
|
|
||||||
await help_test_setup_manual_entity_from_yaml(hass, config)
|
|
||||||
|
|
||||||
assert hass.states.get(entity_id) is not None
|
assert hass.states.get(entity_id) is not None
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
"""Test MQTT fans."""
|
"""Test MQTT fans."""
|
||||||
import copy
|
import copy
|
||||||
|
from typing import Any
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -56,7 +57,6 @@ from .test_common import (
|
||||||
help_test_setting_attribute_via_mqtt_json_message,
|
help_test_setting_attribute_via_mqtt_json_message,
|
||||||
help_test_setting_attribute_with_template,
|
help_test_setting_attribute_with_template,
|
||||||
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
||||||
help_test_setup_manual_entity_from_yaml,
|
|
||||||
help_test_unique_id,
|
help_test_unique_id,
|
||||||
help_test_unload_config_entry_with_platform,
|
help_test_unload_config_entry_with_platform,
|
||||||
help_test_update_with_json_attrs_bad_json,
|
help_test_update_with_json_attrs_bad_json,
|
||||||
|
@ -1371,12 +1371,11 @@ async def test_sending_mqtt_commands_and_explicit_optimistic(
|
||||||
)
|
)
|
||||||
async def test_encoding_subscribable_topics(
|
async def test_encoding_subscribable_topics(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
topic: str,
|
||||||
topic,
|
value: str,
|
||||||
value,
|
attribute: str | None,
|
||||||
attribute,
|
attribute_value: Any,
|
||||||
attribute_value,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test handling of incoming encoded payload."""
|
"""Test handling of incoming encoded payload."""
|
||||||
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][fan.DOMAIN])
|
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][fan.DOMAIN])
|
||||||
|
@ -1386,8 +1385,7 @@ async def test_encoding_subscribable_topics(
|
||||||
config[CONF_OSCILLATION_COMMAND_TOPIC] = "fan/some_oscillation_command_topic"
|
config[CONF_OSCILLATION_COMMAND_TOPIC] = "fan/some_oscillation_command_topic"
|
||||||
await help_test_encoding_subscribable_topics(
|
await help_test_encoding_subscribable_topics(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
caplog,
|
|
||||||
fan.DOMAIN,
|
fan.DOMAIN,
|
||||||
config,
|
config,
|
||||||
topic,
|
topic,
|
||||||
|
@ -1779,31 +1777,34 @@ async def test_discovery_update_attr(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"hass_config",
|
||||||
|
[
|
||||||
|
{
|
||||||
|
mqtt.DOMAIN: {
|
||||||
|
fan.DOMAIN: [
|
||||||
|
{
|
||||||
|
"name": "Test 1",
|
||||||
|
"state_topic": "test-topic",
|
||||||
|
"command_topic": "test_topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Test 2",
|
||||||
|
"state_topic": "test-topic",
|
||||||
|
"command_topic": "test_topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
)
|
||||||
async def test_unique_id(
|
async def test_unique_id(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test unique_id option only creates one fan per id."""
|
"""Test unique_id option only creates one fan per id."""
|
||||||
config = {
|
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN)
|
||||||
mqtt.DOMAIN: {
|
|
||||||
fan.DOMAIN: [
|
|
||||||
{
|
|
||||||
"name": "Test 1",
|
|
||||||
"state_topic": "test-topic",
|
|
||||||
"command_topic": "test_topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Test 2",
|
|
||||||
"state_topic": "test-topic",
|
|
||||||
"command_topic": "test_topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await help_test_unique_id(
|
|
||||||
hass, mqtt_mock_entry_with_yaml_config, fan.DOMAIN, config
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_discovery_removal_fan(
|
async def test_discovery_removal_fan(
|
||||||
|
@ -1903,11 +1904,11 @@ async def test_entity_device_info_remove(
|
||||||
|
|
||||||
|
|
||||||
async def test_entity_id_update_subscriptions(
|
async def test_entity_id_update_subscriptions(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||||
await help_test_entity_id_update_subscriptions(
|
await help_test_entity_id_update_subscriptions(
|
||||||
hass, mqtt_mock_entry_with_yaml_config, fan.DOMAIN, DEFAULT_CONFIG
|
hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1975,13 +1976,13 @@ async def test_entity_debug_info_message(
|
||||||
)
|
)
|
||||||
async def test_publishing_with_custom_encoding(
|
async def test_publishing_with_custom_encoding(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
service,
|
service: str,
|
||||||
topic,
|
topic: str,
|
||||||
parameters,
|
parameters: dict[str, Any],
|
||||||
payload,
|
payload: str,
|
||||||
template,
|
template: str | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test publishing MQTT payload with different encoding."""
|
"""Test publishing MQTT payload with different encoding."""
|
||||||
domain = fan.DOMAIN
|
domain = fan.DOMAIN
|
||||||
|
@ -1991,7 +1992,7 @@ async def test_publishing_with_custom_encoding(
|
||||||
|
|
||||||
await help_test_publishing_with_custom_encoding(
|
await help_test_publishing_with_custom_encoding(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
caplog,
|
caplog,
|
||||||
domain,
|
domain,
|
||||||
config,
|
config,
|
||||||
|
@ -2013,10 +2014,13 @@ async def test_reloadable(
|
||||||
await help_test_reloadable(hass, mqtt_client_mock, domain, config)
|
await help_test_reloadable(hass, mqtt_client_mock, domain, config)
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None:
|
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||||
|
async def test_setup_manual_entity_from_yaml(
|
||||||
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
|
) -> None:
|
||||||
"""Test setup manual configured MQTT entity."""
|
"""Test setup manual configured MQTT entity."""
|
||||||
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
platform = fan.DOMAIN
|
platform = fan.DOMAIN
|
||||||
await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
|
|
||||||
assert hass.states.get(f"{platform}.test")
|
assert hass.states.get(f"{platform}.test")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
"""Test MQTT humidifiers."""
|
"""Test MQTT humidifiers."""
|
||||||
import copy
|
import copy
|
||||||
|
from typing import Any
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -58,7 +59,6 @@ from .test_common import (
|
||||||
help_test_setting_attribute_via_mqtt_json_message,
|
help_test_setting_attribute_via_mqtt_json_message,
|
||||||
help_test_setting_attribute_with_template,
|
help_test_setting_attribute_with_template,
|
||||||
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
||||||
help_test_setup_manual_entity_from_yaml,
|
|
||||||
help_test_unique_id,
|
help_test_unique_id,
|
||||||
help_test_unload_config_entry_with_platform,
|
help_test_unload_config_entry_with_platform,
|
||||||
help_test_update_with_json_attrs_bad_json,
|
help_test_update_with_json_attrs_bad_json,
|
||||||
|
@ -752,12 +752,11 @@ async def test_sending_mqtt_commands_and_explicit_optimistic(
|
||||||
)
|
)
|
||||||
async def test_encoding_subscribable_topics(
|
async def test_encoding_subscribable_topics(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
topic: str,
|
||||||
topic,
|
value: str,
|
||||||
value,
|
attribute: str | None,
|
||||||
attribute,
|
attribute_value: Any,
|
||||||
attribute_value,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test handling of incoming encoded payload."""
|
"""Test handling of incoming encoded payload."""
|
||||||
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][humidifier.DOMAIN])
|
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][humidifier.DOMAIN])
|
||||||
|
@ -765,8 +764,7 @@ async def test_encoding_subscribable_topics(
|
||||||
config[CONF_MODE_COMMAND_TOPIC] = "humidifier/some_mode_command_topic"
|
config[CONF_MODE_COMMAND_TOPIC] = "humidifier/some_mode_command_topic"
|
||||||
await help_test_encoding_subscribable_topics(
|
await help_test_encoding_subscribable_topics(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
caplog,
|
|
||||||
humidifier.DOMAIN,
|
humidifier.DOMAIN,
|
||||||
config,
|
config,
|
||||||
topic,
|
topic,
|
||||||
|
@ -1136,33 +1134,36 @@ async def test_discovery_update_attr(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"hass_config",
|
||||||
|
[
|
||||||
|
{
|
||||||
|
mqtt.DOMAIN: {
|
||||||
|
humidifier.DOMAIN: [
|
||||||
|
{
|
||||||
|
"name": "Test 1",
|
||||||
|
"state_topic": "test-topic",
|
||||||
|
"command_topic": "test_topic",
|
||||||
|
"target_humidity_command_topic": "humidity-command-topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Test 2",
|
||||||
|
"state_topic": "test-topic",
|
||||||
|
"command_topic": "test_topic",
|
||||||
|
"target_humidity_command_topic": "humidity-command-topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
)
|
||||||
async def test_unique_id(
|
async def test_unique_id(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test unique_id option only creates one fan per id."""
|
"""Test unique_id option only creates one fan per id."""
|
||||||
config = {
|
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN)
|
||||||
mqtt.DOMAIN: {
|
|
||||||
humidifier.DOMAIN: [
|
|
||||||
{
|
|
||||||
"name": "Test 1",
|
|
||||||
"state_topic": "test-topic",
|
|
||||||
"command_topic": "test_topic",
|
|
||||||
"target_humidity_command_topic": "humidity-command-topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Test 2",
|
|
||||||
"state_topic": "test-topic",
|
|
||||||
"command_topic": "test_topic",
|
|
||||||
"target_humidity_command_topic": "humidity-command-topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await help_test_unique_id(
|
|
||||||
hass, mqtt_mock_entry_with_yaml_config, humidifier.DOMAIN, config
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_discovery_removal_humidifier(
|
async def test_discovery_removal_humidifier(
|
||||||
|
@ -1274,11 +1275,11 @@ async def test_entity_device_info_remove(
|
||||||
|
|
||||||
|
|
||||||
async def test_entity_id_update_subscriptions(
|
async def test_entity_id_update_subscriptions(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||||
await help_test_entity_id_update_subscriptions(
|
await help_test_entity_id_update_subscriptions(
|
||||||
hass, mqtt_mock_entry_with_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG
|
hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1339,13 +1340,13 @@ async def test_entity_debug_info_message(
|
||||||
)
|
)
|
||||||
async def test_publishing_with_custom_encoding(
|
async def test_publishing_with_custom_encoding(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
service,
|
service: str,
|
||||||
topic,
|
topic: str,
|
||||||
parameters,
|
parameters: dict[str, Any],
|
||||||
payload,
|
payload: str,
|
||||||
template,
|
template: str | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test publishing MQTT payload with different encoding."""
|
"""Test publishing MQTT payload with different encoding."""
|
||||||
domain = humidifier.DOMAIN
|
domain = humidifier.DOMAIN
|
||||||
|
@ -1355,7 +1356,7 @@ async def test_publishing_with_custom_encoding(
|
||||||
|
|
||||||
await help_test_publishing_with_custom_encoding(
|
await help_test_publishing_with_custom_encoding(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
caplog,
|
caplog,
|
||||||
domain,
|
domain,
|
||||||
config,
|
config,
|
||||||
|
@ -1377,10 +1378,13 @@ async def test_reloadable(
|
||||||
await help_test_reloadable(hass, mqtt_client_mock, domain, config)
|
await help_test_reloadable(hass, mqtt_client_mock, domain, config)
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None:
|
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||||
|
async def test_setup_manual_entity_from_yaml(
|
||||||
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
|
) -> None:
|
||||||
"""Test setup manual configured MQTT entity."""
|
"""Test setup manual configured MQTT entity."""
|
||||||
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
platform = humidifier.DOMAIN
|
platform = humidifier.DOMAIN
|
||||||
await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
|
|
||||||
assert hass.states.get(f"{platform}.test")
|
assert hass.states.get(f"{platform}.test")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ from homeassistant.util.dt import utcnow
|
||||||
|
|
||||||
from .test_common import (
|
from .test_common import (
|
||||||
help_test_entry_reload_with_new_config,
|
help_test_entry_reload_with_new_config,
|
||||||
help_test_setup_manual_entity_from_yaml,
|
help_test_validate_platform_config,
|
||||||
)
|
)
|
||||||
|
|
||||||
from tests.common import (
|
from tests.common import (
|
||||||
|
@ -1867,8 +1867,7 @@ async def test_setup_manual_mqtt_with_platform_key(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
with pytest.raises(AssertionError):
|
help_test_validate_platform_config(hass, config)
|
||||||
await help_test_setup_manual_entity_from_yaml(hass, config)
|
|
||||||
assert (
|
assert (
|
||||||
"Invalid config for [mqtt]: [platform] is an invalid option for [mqtt]"
|
"Invalid config for [mqtt]: [platform] is an invalid option for [mqtt]"
|
||||||
in caplog.text
|
in caplog.text
|
||||||
|
@ -1881,8 +1880,7 @@ async def test_setup_manual_mqtt_with_invalid_config(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test set up a manual MQTT item with an invalid config."""
|
"""Test set up a manual MQTT item with an invalid config."""
|
||||||
config = {mqtt.DOMAIN: {"light": {"name": "test"}}}
|
config = {mqtt.DOMAIN: {"light": {"name": "test"}}}
|
||||||
with pytest.raises(AssertionError):
|
help_test_validate_platform_config(hass, config)
|
||||||
await help_test_setup_manual_entity_from_yaml(hass, config)
|
|
||||||
assert (
|
assert (
|
||||||
"Invalid config for [mqtt]: required key not provided @ data['mqtt']['light'][0]['command_topic']."
|
"Invalid config for [mqtt]: required key not provided @ data['mqtt']['light'][0]['command_topic']."
|
||||||
" Got None. (See ?, line ?)" in caplog.text
|
" Got None. (See ?, line ?)" in caplog.text
|
||||||
|
@ -1895,7 +1893,7 @@ async def test_setup_manual_mqtt_empty_platform(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test set up a manual MQTT platform without items."""
|
"""Test set up a manual MQTT platform without items."""
|
||||||
config: ConfigType = {mqtt.DOMAIN: {"light": []}}
|
config: ConfigType = {mqtt.DOMAIN: {"light": []}}
|
||||||
await help_test_setup_manual_entity_from_yaml(hass, config)
|
help_test_validate_platform_config(hass, config)
|
||||||
assert "voluptuous.error.MultipleInvalid" not in caplog.text
|
assert "voluptuous.error.MultipleInvalid" not in caplog.text
|
||||||
|
|
||||||
|
|
||||||
|
@ -3407,12 +3405,12 @@ async def test_disabling_and_enabling_entry(
|
||||||
)
|
)
|
||||||
async def test_setup_manual_items_with_unique_ids(
|
async def test_setup_manual_items_with_unique_ids(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
hass_config: ConfigType,
|
|
||||||
unique: bool,
|
unique: bool,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test setup manual items is generating unique id's."""
|
"""Test setup manual items is generating unique id's."""
|
||||||
await help_test_setup_manual_entity_from_yaml(hass, hass_config)
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
|
|
||||||
assert hass.states.get("light.test1") is not None
|
assert hass.states.get("light.test1") is not None
|
||||||
assert (hass.states.get("light.test2") is not None) == unique
|
assert (hass.states.get("light.test2") is not None) == unique
|
||||||
|
@ -3480,19 +3478,20 @@ async def test_remove_unknown_conf_entry_options(
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_link_config_entry(
|
async def test_link_config_entry(
|
||||||
hass: HomeAssistant, hass_config: ConfigType, caplog: pytest.LogCaptureFixture
|
hass: HomeAssistant,
|
||||||
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
|
caplog: pytest.LogCaptureFixture,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test manual and dynamically setup entities are linked to the config entry."""
|
"""Test manual and dynamically setup entities are linked to the config entry."""
|
||||||
|
# set up manual item
|
||||||
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
|
|
||||||
|
# set up item through discovery
|
||||||
config_discovery = {
|
config_discovery = {
|
||||||
"name": "test_discovery",
|
"name": "test_discovery",
|
||||||
"unique_id": "test_discovery_unique456",
|
"unique_id": "test_discovery_unique456",
|
||||||
"command_topic": "test-topic_discovery",
|
"command_topic": "test-topic_discovery",
|
||||||
}
|
}
|
||||||
|
|
||||||
# set up manual item
|
|
||||||
await help_test_setup_manual_entity_from_yaml(hass, hass_config)
|
|
||||||
|
|
||||||
# set up item through discovery
|
|
||||||
async_fire_mqtt_message(
|
async_fire_mqtt_message(
|
||||||
hass, "homeassistant/light/bla/config", json.dumps(config_discovery)
|
hass, "homeassistant/light/bla/config", json.dumps(config_discovery)
|
||||||
)
|
)
|
||||||
|
@ -3541,18 +3540,3 @@ async def test_link_config_entry(
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert _check_entities() == 2
|
assert _check_entities() == 2
|
||||||
|
|
||||||
|
|
||||||
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SENSOR])
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"config_manual",
|
|
||||||
[
|
|
||||||
{"mqtt": {"sensor": []}},
|
|
||||||
{"mqtt": {"broker": "test"}},
|
|
||||||
],
|
|
||||||
)
|
|
||||||
async def test_setup_manual_entity_from_yaml(
|
|
||||||
hass: HomeAssistant, config_manual: ConfigType
|
|
||||||
) -> None:
|
|
||||||
"""Test setup with empty platform keys."""
|
|
||||||
await help_test_setup_manual_entity_from_yaml(hass, config_manual)
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
"""The tests for the Legacy Mqtt vacuum platform."""
|
"""The tests for the Legacy Mqtt vacuum platform."""
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
import json
|
import json
|
||||||
|
from typing import Any
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -56,7 +57,6 @@ from .test_common import (
|
||||||
help_test_setting_attribute_via_mqtt_json_message,
|
help_test_setting_attribute_via_mqtt_json_message,
|
||||||
help_test_setting_attribute_with_template,
|
help_test_setting_attribute_with_template,
|
||||||
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
||||||
help_test_setup_manual_entity_from_yaml,
|
|
||||||
help_test_unique_id,
|
help_test_unique_id,
|
||||||
help_test_update_with_json_attrs_bad_json,
|
help_test_update_with_json_attrs_bad_json,
|
||||||
help_test_update_with_json_attrs_not_dict,
|
help_test_update_with_json_attrs_not_dict,
|
||||||
|
@ -745,29 +745,32 @@ async def test_discovery_update_attr(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"hass_config",
|
||||||
|
[
|
||||||
|
{
|
||||||
|
mqtt.DOMAIN: {
|
||||||
|
vacuum.DOMAIN: [
|
||||||
|
{
|
||||||
|
"name": "Test 1",
|
||||||
|
"command_topic": "test_topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Test 2",
|
||||||
|
"command_topic": "test_topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
)
|
||||||
async def test_unique_id(
|
async def test_unique_id(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test unique id option only creates one vacuum per unique_id."""
|
"""Test unique id option only creates one vacuum per unique_id."""
|
||||||
config = {
|
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN)
|
||||||
mqtt.DOMAIN: {
|
|
||||||
vacuum.DOMAIN: [
|
|
||||||
{
|
|
||||||
"name": "Test 1",
|
|
||||||
"command_topic": "test_topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Test 2",
|
|
||||||
"command_topic": "test_topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await help_test_unique_id(
|
|
||||||
hass, mqtt_mock_entry_with_yaml_config, vacuum.DOMAIN, config
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_discovery_removal_vacuum(
|
async def test_discovery_removal_vacuum(
|
||||||
|
@ -866,7 +869,7 @@ async def test_entity_device_info_remove(
|
||||||
|
|
||||||
|
|
||||||
async def test_entity_id_update_subscriptions(
|
async def test_entity_id_update_subscriptions(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||||
config = {
|
config = {
|
||||||
|
@ -882,7 +885,7 @@ async def test_entity_id_update_subscriptions(
|
||||||
}
|
}
|
||||||
await help_test_entity_id_update_subscriptions(
|
await help_test_entity_id_update_subscriptions(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
vacuum.DOMAIN,
|
vacuum.DOMAIN,
|
||||||
config,
|
config,
|
||||||
["test-topic", "avty-topic"],
|
["test-topic", "avty-topic"],
|
||||||
|
@ -964,13 +967,13 @@ async def test_entity_debug_info_message(
|
||||||
)
|
)
|
||||||
async def test_publishing_with_custom_encoding(
|
async def test_publishing_with_custom_encoding(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
service,
|
service: str,
|
||||||
topic,
|
topic: str,
|
||||||
parameters,
|
parameters: dict[str, Any],
|
||||||
payload,
|
payload: str,
|
||||||
template,
|
template: str | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test publishing MQTT payload with different encoding."""
|
"""Test publishing MQTT payload with different encoding."""
|
||||||
domain = vacuum.DOMAIN
|
domain = vacuum.DOMAIN
|
||||||
|
@ -985,7 +988,7 @@ async def test_publishing_with_custom_encoding(
|
||||||
|
|
||||||
await help_test_publishing_with_custom_encoding(
|
await help_test_publishing_with_custom_encoding(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
caplog,
|
caplog,
|
||||||
domain,
|
domain,
|
||||||
config,
|
config,
|
||||||
|
@ -1030,12 +1033,11 @@ async def test_reloadable(
|
||||||
)
|
)
|
||||||
async def test_encoding_subscribable_topics(
|
async def test_encoding_subscribable_topics(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
topic: str,
|
||||||
topic,
|
value: str,
|
||||||
value,
|
attribute: str | None,
|
||||||
attribute,
|
attribute_value: Any,
|
||||||
attribute_value,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test handling of incoming encoded payload."""
|
"""Test handling of incoming encoded payload."""
|
||||||
domain = vacuum.DOMAIN
|
domain = vacuum.DOMAIN
|
||||||
|
@ -1056,8 +1058,7 @@ async def test_encoding_subscribable_topics(
|
||||||
|
|
||||||
await help_test_encoding_subscribable_topics(
|
await help_test_encoding_subscribable_topics(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
caplog,
|
|
||||||
vacuum.DOMAIN,
|
vacuum.DOMAIN,
|
||||||
config,
|
config,
|
||||||
topic,
|
topic,
|
||||||
|
@ -1068,8 +1069,11 @@ async def test_encoding_subscribable_topics(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None:
|
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||||
|
async def test_setup_manual_entity_from_yaml(
|
||||||
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
|
) -> None:
|
||||||
"""Test setup manual configured MQTT entity."""
|
"""Test setup manual configured MQTT entity."""
|
||||||
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
platform = vacuum.DOMAIN
|
platform = vacuum.DOMAIN
|
||||||
await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
|
|
||||||
assert hass.states.get(f"{platform}.mqtttest")
|
assert hass.states.get(f"{platform}.mqtttest")
|
||||||
|
|
|
@ -169,6 +169,7 @@ mqtt:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
import copy
|
import copy
|
||||||
|
from typing import Any
|
||||||
from unittest.mock import call, patch
|
from unittest.mock import call, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -186,6 +187,7 @@ from homeassistant.components.mqtt.light.schema_basic import (
|
||||||
CONF_XY_COMMAND_TOPIC,
|
CONF_XY_COMMAND_TOPIC,
|
||||||
MQTT_LIGHT_ATTRIBUTES_BLOCKED,
|
MQTT_LIGHT_ATTRIBUTES_BLOCKED,
|
||||||
)
|
)
|
||||||
|
from homeassistant.components.mqtt.models import PublishPayloadType
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ASSUMED_STATE,
|
ATTR_ASSUMED_STATE,
|
||||||
STATE_OFF,
|
STATE_OFF,
|
||||||
|
@ -219,7 +221,6 @@ from .test_common import (
|
||||||
help_test_setting_attribute_via_mqtt_json_message,
|
help_test_setting_attribute_via_mqtt_json_message,
|
||||||
help_test_setting_attribute_with_template,
|
help_test_setting_attribute_with_template,
|
||||||
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
||||||
help_test_setup_manual_entity_from_yaml,
|
|
||||||
help_test_unique_id,
|
help_test_unique_id,
|
||||||
help_test_unload_config_entry_with_platform,
|
help_test_unload_config_entry_with_platform,
|
||||||
help_test_update_with_json_attrs_bad_json,
|
help_test_update_with_json_attrs_bad_json,
|
||||||
|
@ -2247,31 +2248,34 @@ async def test_discovery_update_attr(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"hass_config",
|
||||||
|
[
|
||||||
|
{
|
||||||
|
mqtt.DOMAIN: {
|
||||||
|
light.DOMAIN: [
|
||||||
|
{
|
||||||
|
"name": "Test 1",
|
||||||
|
"state_topic": "test-topic",
|
||||||
|
"command_topic": "test_topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Test 2",
|
||||||
|
"state_topic": "test-topic",
|
||||||
|
"command_topic": "test_topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
)
|
||||||
async def test_unique_id(
|
async def test_unique_id(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test unique id option only creates one light per unique_id."""
|
"""Test unique id option only creates one light per unique_id."""
|
||||||
config = {
|
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN)
|
||||||
mqtt.DOMAIN: {
|
|
||||||
light.DOMAIN: [
|
|
||||||
{
|
|
||||||
"name": "Test 1",
|
|
||||||
"state_topic": "test-topic",
|
|
||||||
"command_topic": "test_topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Test 2",
|
|
||||||
"state_topic": "test-topic",
|
|
||||||
"command_topic": "test_topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await help_test_unique_id(
|
|
||||||
hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, config
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_discovery_removal_light(
|
async def test_discovery_removal_light(
|
||||||
|
@ -2859,11 +2863,11 @@ async def test_entity_device_info_remove(
|
||||||
|
|
||||||
|
|
||||||
async def test_entity_id_update_subscriptions(
|
async def test_entity_id_update_subscriptions(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||||
await help_test_entity_id_update_subscriptions(
|
await help_test_entity_id_update_subscriptions(
|
||||||
hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG
|
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -2999,15 +3003,15 @@ async def test_max_mireds(
|
||||||
)
|
)
|
||||||
async def test_publishing_with_custom_encoding(
|
async def test_publishing_with_custom_encoding(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
service,
|
service: str,
|
||||||
topic,
|
topic: str,
|
||||||
parameters,
|
parameters: dict[str, Any],
|
||||||
payload,
|
payload: str,
|
||||||
template,
|
template: str | None,
|
||||||
tpl_par,
|
tpl_par: str,
|
||||||
tpl_output,
|
tpl_output: PublishPayloadType,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test publishing MQTT payload with different encoding."""
|
"""Test publishing MQTT payload with different encoding."""
|
||||||
domain = light.DOMAIN
|
domain = light.DOMAIN
|
||||||
|
@ -3019,7 +3023,7 @@ async def test_publishing_with_custom_encoding(
|
||||||
|
|
||||||
await help_test_publishing_with_custom_encoding(
|
await help_test_publishing_with_custom_encoding(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
caplog,
|
caplog,
|
||||||
domain,
|
domain,
|
||||||
config,
|
config,
|
||||||
|
@ -3075,13 +3079,12 @@ async def test_reloadable(
|
||||||
)
|
)
|
||||||
async def test_encoding_subscribable_topics(
|
async def test_encoding_subscribable_topics(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
topic: str,
|
||||||
topic,
|
value: str,
|
||||||
value,
|
attribute: str | None,
|
||||||
attribute,
|
attribute_value: Any,
|
||||||
attribute_value,
|
init_payload: tuple[str, str] | None,
|
||||||
init_payload,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test handling of incoming encoded payload."""
|
"""Test handling of incoming encoded payload."""
|
||||||
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][light.DOMAIN])
|
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][light.DOMAIN])
|
||||||
|
@ -3098,8 +3101,7 @@ async def test_encoding_subscribable_topics(
|
||||||
|
|
||||||
await help_test_encoding_subscribable_topics(
|
await help_test_encoding_subscribable_topics(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
caplog,
|
|
||||||
light.DOMAIN,
|
light.DOMAIN,
|
||||||
config,
|
config,
|
||||||
topic,
|
topic,
|
||||||
|
@ -3118,13 +3120,13 @@ async def test_encoding_subscribable_topics(
|
||||||
)
|
)
|
||||||
async def test_encoding_subscribable_topics_brightness(
|
async def test_encoding_subscribable_topics_brightness(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
topic,
|
topic: str,
|
||||||
value,
|
value: str,
|
||||||
attribute,
|
attribute: str,
|
||||||
attribute_value,
|
attribute_value: int,
|
||||||
init_payload,
|
init_payload: tuple[str, str] | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test handling of incoming encoded payload for a brightness only light."""
|
"""Test handling of incoming encoded payload for a brightness only light."""
|
||||||
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][light.DOMAIN])
|
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][light.DOMAIN])
|
||||||
|
@ -3132,8 +3134,7 @@ async def test_encoding_subscribable_topics_brightness(
|
||||||
|
|
||||||
await help_test_encoding_subscribable_topics(
|
await help_test_encoding_subscribable_topics(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
caplog,
|
|
||||||
light.DOMAIN,
|
light.DOMAIN,
|
||||||
config,
|
config,
|
||||||
topic,
|
topic,
|
||||||
|
@ -3298,10 +3299,13 @@ async def test_sending_mqtt_xy_command_with_template(
|
||||||
assert state.attributes["xy_color"] == (0.151, 0.343)
|
assert state.attributes["xy_color"] == (0.151, 0.343)
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None:
|
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||||
|
async def test_setup_manual_entity_from_yaml(
|
||||||
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
|
) -> None:
|
||||||
"""Test setup manual configured MQTT entity."""
|
"""Test setup manual configured MQTT entity."""
|
||||||
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
platform = light.DOMAIN
|
platform = light.DOMAIN
|
||||||
await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
|
|
||||||
assert hass.states.get(f"{platform}.test")
|
assert hass.states.get(f"{platform}.test")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -79,6 +79,7 @@ light:
|
||||||
brightness_scale: 99
|
brightness_scale: 99
|
||||||
"""
|
"""
|
||||||
import copy
|
import copy
|
||||||
|
from typing import Any
|
||||||
from unittest.mock import call, patch
|
from unittest.mock import call, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -87,6 +88,7 @@ from homeassistant.components import light, mqtt
|
||||||
from homeassistant.components.mqtt.light.schema_basic import (
|
from homeassistant.components.mqtt.light.schema_basic import (
|
||||||
MQTT_LIGHT_ATTRIBUTES_BLOCKED,
|
MQTT_LIGHT_ATTRIBUTES_BLOCKED,
|
||||||
)
|
)
|
||||||
|
from homeassistant.components.mqtt.models import PublishPayloadType
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ASSUMED_STATE,
|
ATTR_ASSUMED_STATE,
|
||||||
ATTR_SUPPORTED_FEATURES,
|
ATTR_SUPPORTED_FEATURES,
|
||||||
|
@ -122,7 +124,6 @@ from .test_common import (
|
||||||
help_test_setting_attribute_via_mqtt_json_message,
|
help_test_setting_attribute_via_mqtt_json_message,
|
||||||
help_test_setting_attribute_with_template,
|
help_test_setting_attribute_with_template,
|
||||||
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
||||||
help_test_setup_manual_entity_from_yaml,
|
|
||||||
help_test_unique_id,
|
help_test_unique_id,
|
||||||
help_test_update_with_json_attrs_bad_json,
|
help_test_update_with_json_attrs_bad_json,
|
||||||
help_test_update_with_json_attrs_not_dict,
|
help_test_update_with_json_attrs_not_dict,
|
||||||
|
@ -1996,33 +1997,36 @@ async def test_discovery_update_attr(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"hass_config",
|
||||||
|
[
|
||||||
|
{
|
||||||
|
mqtt.DOMAIN: {
|
||||||
|
light.DOMAIN: [
|
||||||
|
{
|
||||||
|
"name": "Test 1",
|
||||||
|
"schema": "json",
|
||||||
|
"state_topic": "test-topic",
|
||||||
|
"command_topic": "test_topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Test 2",
|
||||||
|
"schema": "json",
|
||||||
|
"state_topic": "test-topic",
|
||||||
|
"command_topic": "test_topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
)
|
||||||
async def test_unique_id(
|
async def test_unique_id(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test unique id option only creates one light per unique_id."""
|
"""Test unique id option only creates one light per unique_id."""
|
||||||
config = {
|
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN)
|
||||||
mqtt.DOMAIN: {
|
|
||||||
light.DOMAIN: [
|
|
||||||
{
|
|
||||||
"name": "Test 1",
|
|
||||||
"schema": "json",
|
|
||||||
"state_topic": "test-topic",
|
|
||||||
"command_topic": "test_topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Test 2",
|
|
||||||
"schema": "json",
|
|
||||||
"state_topic": "test-topic",
|
|
||||||
"command_topic": "test_topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await help_test_unique_id(
|
|
||||||
hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, config
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_discovery_removal(
|
async def test_discovery_removal(
|
||||||
|
@ -2167,11 +2171,11 @@ async def test_entity_device_info_remove(
|
||||||
|
|
||||||
|
|
||||||
async def test_entity_id_update_subscriptions(
|
async def test_entity_id_update_subscriptions(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||||
await help_test_entity_id_update_subscriptions(
|
await help_test_entity_id_update_subscriptions(
|
||||||
hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG
|
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -2247,15 +2251,15 @@ async def test_max_mireds(
|
||||||
)
|
)
|
||||||
async def test_publishing_with_custom_encoding(
|
async def test_publishing_with_custom_encoding(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
service,
|
service: str,
|
||||||
topic,
|
topic: str,
|
||||||
parameters,
|
parameters: dict[str, Any],
|
||||||
payload,
|
payload: str,
|
||||||
template,
|
template: str | None,
|
||||||
tpl_par,
|
tpl_par: str,
|
||||||
tpl_output,
|
tpl_output: PublishPayloadType,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test publishing MQTT payload with different encoding."""
|
"""Test publishing MQTT payload with different encoding."""
|
||||||
domain = light.DOMAIN
|
domain = light.DOMAIN
|
||||||
|
@ -2265,7 +2269,7 @@ async def test_publishing_with_custom_encoding(
|
||||||
|
|
||||||
await help_test_publishing_with_custom_encoding(
|
await help_test_publishing_with_custom_encoding(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
caplog,
|
caplog,
|
||||||
domain,
|
domain,
|
||||||
config,
|
config,
|
||||||
|
@ -2303,13 +2307,12 @@ async def test_reloadable(
|
||||||
)
|
)
|
||||||
async def test_encoding_subscribable_topics(
|
async def test_encoding_subscribable_topics(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
topic: str,
|
||||||
topic,
|
value: str,
|
||||||
value,
|
attribute: str | None,
|
||||||
attribute,
|
attribute_value: Any,
|
||||||
attribute_value,
|
init_payload: tuple[str, str] | None,
|
||||||
init_payload,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test handling of incoming encoded payload."""
|
"""Test handling of incoming encoded payload."""
|
||||||
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][light.DOMAIN])
|
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][light.DOMAIN])
|
||||||
|
@ -2324,8 +2327,7 @@ async def test_encoding_subscribable_topics(
|
||||||
]
|
]
|
||||||
await help_test_encoding_subscribable_topics(
|
await help_test_encoding_subscribable_topics(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
caplog,
|
|
||||||
light.DOMAIN,
|
light.DOMAIN,
|
||||||
config,
|
config,
|
||||||
topic,
|
topic,
|
||||||
|
@ -2337,8 +2339,11 @@ async def test_encoding_subscribable_topics(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None:
|
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||||
|
async def test_setup_manual_entity_from_yaml(
|
||||||
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
|
) -> None:
|
||||||
"""Test setup manual configured MQTT entity."""
|
"""Test setup manual configured MQTT entity."""
|
||||||
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
platform = light.DOMAIN
|
platform = light.DOMAIN
|
||||||
await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
|
|
||||||
assert hass.states.get(f"{platform}.test")
|
assert hass.states.get(f"{platform}.test")
|
||||||
|
|
|
@ -25,6 +25,7 @@ If your light doesn't support color temp feature, omit `color_temp_template`.
|
||||||
If your light doesn't support RGB feature, omit `(red|green|blue)_template`.
|
If your light doesn't support RGB feature, omit `(red|green|blue)_template`.
|
||||||
"""
|
"""
|
||||||
import copy
|
import copy
|
||||||
|
from typing import Any
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -33,6 +34,7 @@ from homeassistant.components import light, mqtt
|
||||||
from homeassistant.components.mqtt.light.schema_basic import (
|
from homeassistant.components.mqtt.light.schema_basic import (
|
||||||
MQTT_LIGHT_ATTRIBUTES_BLOCKED,
|
MQTT_LIGHT_ATTRIBUTES_BLOCKED,
|
||||||
)
|
)
|
||||||
|
from homeassistant.components.mqtt.models import PublishPayloadType
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ASSUMED_STATE,
|
ATTR_ASSUMED_STATE,
|
||||||
ATTR_SUPPORTED_FEATURES,
|
ATTR_SUPPORTED_FEATURES,
|
||||||
|
@ -67,7 +69,6 @@ from .test_common import (
|
||||||
help_test_setting_attribute_via_mqtt_json_message,
|
help_test_setting_attribute_via_mqtt_json_message,
|
||||||
help_test_setting_attribute_with_template,
|
help_test_setting_attribute_with_template,
|
||||||
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
||||||
help_test_setup_manual_entity_from_yaml,
|
|
||||||
help_test_unique_id,
|
help_test_unique_id,
|
||||||
help_test_unload_config_entry_with_platform,
|
help_test_unload_config_entry_with_platform,
|
||||||
help_test_update_with_json_attrs_bad_json,
|
help_test_update_with_json_attrs_bad_json,
|
||||||
|
@ -964,37 +965,40 @@ async def test_discovery_update_attr(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"hass_config",
|
||||||
|
[
|
||||||
|
{
|
||||||
|
mqtt.DOMAIN: {
|
||||||
|
light.DOMAIN: [
|
||||||
|
{
|
||||||
|
"name": "Test 1",
|
||||||
|
"schema": "template",
|
||||||
|
"state_topic": "test-topic",
|
||||||
|
"command_topic": "test_topic",
|
||||||
|
"command_on_template": "on,{{ transition }}",
|
||||||
|
"command_off_template": "off,{{ transition|d }}",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Test 2",
|
||||||
|
"schema": "template",
|
||||||
|
"state_topic": "test-topic2",
|
||||||
|
"command_topic": "test_topic2",
|
||||||
|
"command_on_template": "on,{{ transition }}",
|
||||||
|
"command_off_template": "off,{{ transition|d }}",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
)
|
||||||
async def test_unique_id(
|
async def test_unique_id(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test unique id option only creates one light per unique_id."""
|
"""Test unique id option only creates one light per unique_id."""
|
||||||
config = {
|
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN)
|
||||||
mqtt.DOMAIN: {
|
|
||||||
light.DOMAIN: [
|
|
||||||
{
|
|
||||||
"name": "Test 1",
|
|
||||||
"schema": "template",
|
|
||||||
"state_topic": "test-topic",
|
|
||||||
"command_topic": "test_topic",
|
|
||||||
"command_on_template": "on,{{ transition }}",
|
|
||||||
"command_off_template": "off,{{ transition|d }}",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Test 2",
|
|
||||||
"schema": "template",
|
|
||||||
"state_topic": "test-topic2",
|
|
||||||
"command_topic": "test_topic2",
|
|
||||||
"command_on_template": "on,{{ transition }}",
|
|
||||||
"command_off_template": "off,{{ transition|d }}",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await help_test_unique_id(
|
|
||||||
hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, config
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_discovery_removal(
|
async def test_discovery_removal(
|
||||||
|
@ -1127,11 +1131,11 @@ async def test_entity_device_info_remove(
|
||||||
|
|
||||||
|
|
||||||
async def test_entity_id_update_subscriptions(
|
async def test_entity_id_update_subscriptions(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||||
await help_test_entity_id_update_subscriptions(
|
await help_test_entity_id_update_subscriptions(
|
||||||
hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG
|
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1219,15 +1223,15 @@ async def test_max_mireds(
|
||||||
)
|
)
|
||||||
async def test_publishing_with_custom_encoding(
|
async def test_publishing_with_custom_encoding(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
service,
|
service: str,
|
||||||
topic,
|
topic: str,
|
||||||
parameters,
|
parameters: dict[str, Any],
|
||||||
payload,
|
payload: str,
|
||||||
template,
|
template: str | None,
|
||||||
tpl_par,
|
tpl_par: str,
|
||||||
tpl_output,
|
tpl_output: PublishPayloadType,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test publishing MQTT payload with different encoding."""
|
"""Test publishing MQTT payload with different encoding."""
|
||||||
domain = light.DOMAIN
|
domain = light.DOMAIN
|
||||||
|
@ -1237,7 +1241,7 @@ async def test_publishing_with_custom_encoding(
|
||||||
|
|
||||||
await help_test_publishing_with_custom_encoding(
|
await help_test_publishing_with_custom_encoding(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
caplog,
|
caplog,
|
||||||
domain,
|
domain,
|
||||||
config,
|
config,
|
||||||
|
@ -1269,12 +1273,11 @@ async def test_reloadable(
|
||||||
)
|
)
|
||||||
async def test_encoding_subscribable_topics(
|
async def test_encoding_subscribable_topics(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
topic: str,
|
||||||
topic,
|
value: str,
|
||||||
value,
|
attribute: str | None,
|
||||||
attribute,
|
attribute_value: Any,
|
||||||
attribute_value,
|
|
||||||
init_payload,
|
init_payload,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test handling of incoming encoded payload."""
|
"""Test handling of incoming encoded payload."""
|
||||||
|
@ -1282,8 +1285,7 @@ async def test_encoding_subscribable_topics(
|
||||||
config["state_template"] = "{{ value }}"
|
config["state_template"] = "{{ value }}"
|
||||||
await help_test_encoding_subscribable_topics(
|
await help_test_encoding_subscribable_topics(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
caplog,
|
|
||||||
light.DOMAIN,
|
light.DOMAIN,
|
||||||
config,
|
config,
|
||||||
topic,
|
topic,
|
||||||
|
@ -1294,10 +1296,13 @@ async def test_encoding_subscribable_topics(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None:
|
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||||
|
async def test_setup_manual_entity_from_yaml(
|
||||||
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
|
) -> None:
|
||||||
"""Test setup manual configured MQTT entity."""
|
"""Test setup manual configured MQTT entity."""
|
||||||
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
platform = light.DOMAIN
|
platform = light.DOMAIN
|
||||||
await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
|
|
||||||
assert hass.states.get(f"{platform}.test")
|
assert hass.states.get(f"{platform}.test")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
"""The tests for the MQTT lock platform."""
|
"""The tests for the MQTT lock platform."""
|
||||||
from pathlib import Path
|
from typing import Any
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -50,7 +50,6 @@ from .test_common import (
|
||||||
help_test_setting_attribute_via_mqtt_json_message,
|
help_test_setting_attribute_via_mqtt_json_message,
|
||||||
help_test_setting_attribute_with_template,
|
help_test_setting_attribute_with_template,
|
||||||
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
||||||
help_test_setup_manual_entity_from_yaml,
|
|
||||||
help_test_unique_id,
|
help_test_unique_id,
|
||||||
help_test_unload_config_entry_with_platform,
|
help_test_unload_config_entry_with_platform,
|
||||||
help_test_update_with_json_attrs_bad_json,
|
help_test_update_with_json_attrs_bad_json,
|
||||||
|
@ -762,31 +761,34 @@ async def test_discovery_update_attr(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"hass_config",
|
||||||
|
[
|
||||||
|
{
|
||||||
|
mqtt.DOMAIN: {
|
||||||
|
lock.DOMAIN: [
|
||||||
|
{
|
||||||
|
"name": "Test 1",
|
||||||
|
"state_topic": "test-topic",
|
||||||
|
"command_topic": "test_topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Test 2",
|
||||||
|
"state_topic": "test-topic",
|
||||||
|
"command_topic": "test_topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
)
|
||||||
async def test_unique_id(
|
async def test_unique_id(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test unique id option only creates one lock per unique_id."""
|
"""Test unique id option only creates one lock per unique_id."""
|
||||||
config = {
|
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN)
|
||||||
mqtt.DOMAIN: {
|
|
||||||
lock.DOMAIN: [
|
|
||||||
{
|
|
||||||
"name": "Test 1",
|
|
||||||
"state_topic": "test-topic",
|
|
||||||
"command_topic": "test_topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Test 2",
|
|
||||||
"state_topic": "test-topic",
|
|
||||||
"command_topic": "test_topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await help_test_unique_id(
|
|
||||||
hass, mqtt_mock_entry_with_yaml_config, lock.DOMAIN, config
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_discovery_removal_lock(
|
async def test_discovery_removal_lock(
|
||||||
|
@ -899,11 +901,11 @@ async def test_entity_device_info_remove(
|
||||||
|
|
||||||
|
|
||||||
async def test_entity_id_update_subscriptions(
|
async def test_entity_id_update_subscriptions(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||||
await help_test_entity_id_update_subscriptions(
|
await help_test_entity_id_update_subscriptions(
|
||||||
hass, mqtt_mock_entry_with_yaml_config, lock.DOMAIN, DEFAULT_CONFIG
|
hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -944,13 +946,13 @@ async def test_entity_debug_info_message(
|
||||||
)
|
)
|
||||||
async def test_publishing_with_custom_encoding(
|
async def test_publishing_with_custom_encoding(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
service,
|
service: str,
|
||||||
topic,
|
topic: str,
|
||||||
parameters,
|
parameters: dict[str, Any],
|
||||||
payload,
|
payload: str,
|
||||||
template,
|
template: str | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test publishing MQTT payload with different encoding."""
|
"""Test publishing MQTT payload with different encoding."""
|
||||||
domain = lock.DOMAIN
|
domain = lock.DOMAIN
|
||||||
|
@ -958,7 +960,7 @@ async def test_publishing_with_custom_encoding(
|
||||||
|
|
||||||
await help_test_publishing_with_custom_encoding(
|
await help_test_publishing_with_custom_encoding(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
caplog,
|
caplog,
|
||||||
domain,
|
domain,
|
||||||
config,
|
config,
|
||||||
|
@ -988,18 +990,16 @@ async def test_reloadable(
|
||||||
)
|
)
|
||||||
async def test_encoding_subscribable_topics(
|
async def test_encoding_subscribable_topics(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
topic: str,
|
||||||
topic,
|
value: str,
|
||||||
value,
|
attribute: str | None,
|
||||||
attribute,
|
attribute_value: Any,
|
||||||
attribute_value,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test handling of incoming encoded payload."""
|
"""Test handling of incoming encoded payload."""
|
||||||
await help_test_encoding_subscribable_topics(
|
await help_test_encoding_subscribable_topics(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
caplog,
|
|
||||||
lock.DOMAIN,
|
lock.DOMAIN,
|
||||||
DEFAULT_CONFIG[mqtt.DOMAIN][lock.DOMAIN],
|
DEFAULT_CONFIG[mqtt.DOMAIN][lock.DOMAIN],
|
||||||
topic,
|
topic,
|
||||||
|
@ -1009,12 +1009,13 @@ async def test_encoding_subscribable_topics(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||||
async def test_setup_manual_entity_from_yaml(
|
async def test_setup_manual_entity_from_yaml(
|
||||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, tmp_path: Path
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test setup manual configured MQTT entity."""
|
"""Test setup manual configured MQTT entity."""
|
||||||
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
platform = lock.DOMAIN
|
platform = lock.DOMAIN
|
||||||
await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
|
|
||||||
assert hass.states.get(f"{platform}.test")
|
assert hass.states.get(f"{platform}.test")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
"""The tests for mqtt number component."""
|
"""The tests for mqtt number component."""
|
||||||
import json
|
import json
|
||||||
|
from typing import Any
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -54,7 +55,6 @@ from .test_common import (
|
||||||
help_test_setting_attribute_via_mqtt_json_message,
|
help_test_setting_attribute_via_mqtt_json_message,
|
||||||
help_test_setting_attribute_with_template,
|
help_test_setting_attribute_with_template,
|
||||||
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
||||||
help_test_setup_manual_entity_from_yaml,
|
|
||||||
help_test_unique_id,
|
help_test_unique_id,
|
||||||
help_test_unload_config_entry_with_platform,
|
help_test_unload_config_entry_with_platform,
|
||||||
help_test_update_with_json_attrs_bad_json,
|
help_test_update_with_json_attrs_bad_json,
|
||||||
|
@ -559,31 +559,34 @@ async def test_discovery_update_attr(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"hass_config",
|
||||||
|
[
|
||||||
|
{
|
||||||
|
mqtt.DOMAIN: {
|
||||||
|
number.DOMAIN: [
|
||||||
|
{
|
||||||
|
"name": "Test 1",
|
||||||
|
"state_topic": "test-topic",
|
||||||
|
"command_topic": "test-topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Test 2",
|
||||||
|
"state_topic": "test-topic",
|
||||||
|
"command_topic": "test-topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
)
|
||||||
async def test_unique_id(
|
async def test_unique_id(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test unique id option only creates one number per unique_id."""
|
"""Test unique id option only creates one number per unique_id."""
|
||||||
config = {
|
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN)
|
||||||
mqtt.DOMAIN: {
|
|
||||||
number.DOMAIN: [
|
|
||||||
{
|
|
||||||
"name": "Test 1",
|
|
||||||
"state_topic": "test-topic",
|
|
||||||
"command_topic": "test-topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Test 2",
|
|
||||||
"state_topic": "test-topic",
|
|
||||||
"command_topic": "test-topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await help_test_unique_id(
|
|
||||||
hass, mqtt_mock_entry_with_yaml_config, number.DOMAIN, config
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_discovery_removal_number(
|
async def test_discovery_removal_number(
|
||||||
|
@ -696,11 +699,11 @@ async def test_entity_device_info_remove(
|
||||||
|
|
||||||
|
|
||||||
async def test_entity_id_update_subscriptions(
|
async def test_entity_id_update_subscriptions(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||||
await help_test_entity_id_update_subscriptions(
|
await help_test_entity_id_update_subscriptions(
|
||||||
hass, mqtt_mock_entry_with_yaml_config, number.DOMAIN, DEFAULT_CONFIG
|
hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -938,13 +941,13 @@ async def test_mqtt_payload_out_of_range_error(
|
||||||
)
|
)
|
||||||
async def test_publishing_with_custom_encoding(
|
async def test_publishing_with_custom_encoding(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
service,
|
service: str,
|
||||||
topic,
|
topic: str,
|
||||||
parameters,
|
parameters: dict[str, Any],
|
||||||
payload,
|
payload: str,
|
||||||
template,
|
template: str | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test publishing MQTT payload with different encoding."""
|
"""Test publishing MQTT payload with different encoding."""
|
||||||
domain = NUMBER_DOMAIN
|
domain = NUMBER_DOMAIN
|
||||||
|
@ -952,7 +955,7 @@ async def test_publishing_with_custom_encoding(
|
||||||
|
|
||||||
await help_test_publishing_with_custom_encoding(
|
await help_test_publishing_with_custom_encoding(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
caplog,
|
caplog,
|
||||||
domain,
|
domain,
|
||||||
config,
|
config,
|
||||||
|
@ -983,18 +986,16 @@ async def test_reloadable(
|
||||||
)
|
)
|
||||||
async def test_encoding_subscribable_topics(
|
async def test_encoding_subscribable_topics(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
topic: str,
|
||||||
topic,
|
value: str,
|
||||||
value,
|
attribute: str | None,
|
||||||
attribute,
|
attribute_value: Any,
|
||||||
attribute_value,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test handling of incoming encoded payload."""
|
"""Test handling of incoming encoded payload."""
|
||||||
await help_test_encoding_subscribable_topics(
|
await help_test_encoding_subscribable_topics(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
caplog,
|
|
||||||
number.DOMAIN,
|
number.DOMAIN,
|
||||||
DEFAULT_CONFIG[mqtt.DOMAIN][number.DOMAIN],
|
DEFAULT_CONFIG[mqtt.DOMAIN][number.DOMAIN],
|
||||||
topic,
|
topic,
|
||||||
|
@ -1004,10 +1005,13 @@ async def test_encoding_subscribable_topics(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None:
|
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||||
|
async def test_setup_manual_entity_from_yaml(
|
||||||
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
|
) -> None:
|
||||||
"""Test setup manual configured MQTT entity."""
|
"""Test setup manual configured MQTT entity."""
|
||||||
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
platform = number.DOMAIN
|
platform = number.DOMAIN
|
||||||
await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
|
|
||||||
assert hass.states.get(f"{platform}.test")
|
assert hass.states.get(f"{platform}.test")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,6 @@ from .test_common import (
|
||||||
help_test_discovery_update,
|
help_test_discovery_update,
|
||||||
help_test_discovery_update_unchanged,
|
help_test_discovery_update_unchanged,
|
||||||
help_test_reloadable,
|
help_test_reloadable,
|
||||||
help_test_setup_manual_entity_from_yaml,
|
|
||||||
help_test_unique_id,
|
help_test_unique_id,
|
||||||
help_test_unload_config_entry_with_platform,
|
help_test_unload_config_entry_with_platform,
|
||||||
)
|
)
|
||||||
|
@ -148,29 +147,32 @@ async def test_custom_availability_payload(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"hass_config",
|
||||||
|
[
|
||||||
|
{
|
||||||
|
mqtt.DOMAIN: {
|
||||||
|
scene.DOMAIN: [
|
||||||
|
{
|
||||||
|
"name": "Test 1",
|
||||||
|
"command_topic": "command-topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Test 2",
|
||||||
|
"command_topic": "command-topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
)
|
||||||
async def test_unique_id(
|
async def test_unique_id(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test unique id option only creates one scene per unique_id."""
|
"""Test unique id option only creates one scene per unique_id."""
|
||||||
config = {
|
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, scene.DOMAIN)
|
||||||
mqtt.DOMAIN: {
|
|
||||||
scene.DOMAIN: [
|
|
||||||
{
|
|
||||||
"name": "Test 1",
|
|
||||||
"command_topic": "command-topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Test 2",
|
|
||||||
"command_topic": "command-topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await help_test_unique_id(
|
|
||||||
hass, mqtt_mock_entry_with_yaml_config, scene.DOMAIN, config
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_discovery_removal_scene(
|
async def test_discovery_removal_scene(
|
||||||
|
@ -252,10 +254,13 @@ async def test_reloadable(
|
||||||
await help_test_reloadable(hass, mqtt_client_mock, domain, config)
|
await help_test_reloadable(hass, mqtt_client_mock, domain, config)
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None:
|
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||||
|
async def test_setup_manual_entity_from_yaml(
|
||||||
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
|
) -> None:
|
||||||
"""Test setup manual configured MQTT entity."""
|
"""Test setup manual configured MQTT entity."""
|
||||||
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
platform = scene.DOMAIN
|
platform = scene.DOMAIN
|
||||||
await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
|
|
||||||
assert hass.states.get(f"{platform}.test")
|
assert hass.states.get(f"{platform}.test")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
"""The tests for mqtt select component."""
|
"""The tests for mqtt select component."""
|
||||||
import copy
|
import copy
|
||||||
import json
|
import json
|
||||||
|
from typing import Any
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -46,7 +47,6 @@ from .test_common import (
|
||||||
help_test_setting_attribute_via_mqtt_json_message,
|
help_test_setting_attribute_via_mqtt_json_message,
|
||||||
help_test_setting_attribute_with_template,
|
help_test_setting_attribute_with_template,
|
||||||
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
||||||
help_test_setup_manual_entity_from_yaml,
|
|
||||||
help_test_unique_id,
|
help_test_unique_id,
|
||||||
help_test_unload_config_entry_with_platform,
|
help_test_unload_config_entry_with_platform,
|
||||||
help_test_update_with_json_attrs_bad_json,
|
help_test_update_with_json_attrs_bad_json,
|
||||||
|
@ -436,33 +436,36 @@ async def test_discovery_update_attr(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"hass_config",
|
||||||
|
[
|
||||||
|
{
|
||||||
|
mqtt.DOMAIN: {
|
||||||
|
select.DOMAIN: [
|
||||||
|
{
|
||||||
|
"name": "Test 1",
|
||||||
|
"state_topic": "test-topic",
|
||||||
|
"command_topic": "test-topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
"options": ["milk", "beer"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Test 2",
|
||||||
|
"state_topic": "test-topic",
|
||||||
|
"command_topic": "test-topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
"options": ["milk", "beer"],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
)
|
||||||
async def test_unique_id(
|
async def test_unique_id(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test unique id option only creates one select per unique_id."""
|
"""Test unique id option only creates one select per unique_id."""
|
||||||
config = {
|
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN)
|
||||||
mqtt.DOMAIN: {
|
|
||||||
select.DOMAIN: [
|
|
||||||
{
|
|
||||||
"name": "Test 1",
|
|
||||||
"state_topic": "test-topic",
|
|
||||||
"command_topic": "test-topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
"options": ["milk", "beer"],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Test 2",
|
|
||||||
"state_topic": "test-topic",
|
|
||||||
"command_topic": "test-topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
"options": ["milk", "beer"],
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await help_test_unique_id(
|
|
||||||
hass, mqtt_mock_entry_with_yaml_config, select.DOMAIN, config
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_discovery_removal_select(
|
async def test_discovery_removal_select(
|
||||||
|
@ -573,11 +576,11 @@ async def test_entity_device_info_remove(
|
||||||
|
|
||||||
|
|
||||||
async def test_entity_id_update_subscriptions(
|
async def test_entity_id_update_subscriptions(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||||
await help_test_entity_id_update_subscriptions(
|
await help_test_entity_id_update_subscriptions(
|
||||||
hass, mqtt_mock_entry_with_yaml_config, select.DOMAIN, DEFAULT_CONFIG
|
hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -683,13 +686,13 @@ async def test_mqtt_payload_not_an_option_warning(
|
||||||
)
|
)
|
||||||
async def test_publishing_with_custom_encoding(
|
async def test_publishing_with_custom_encoding(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
service,
|
service: str,
|
||||||
topic,
|
topic: str,
|
||||||
parameters,
|
parameters: dict[str, Any],
|
||||||
payload,
|
payload: str,
|
||||||
template,
|
template: str | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test publishing MQTT payload with different encoding."""
|
"""Test publishing MQTT payload with different encoding."""
|
||||||
domain = select.DOMAIN
|
domain = select.DOMAIN
|
||||||
|
@ -698,7 +701,7 @@ async def test_publishing_with_custom_encoding(
|
||||||
|
|
||||||
await help_test_publishing_with_custom_encoding(
|
await help_test_publishing_with_custom_encoding(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
caplog,
|
caplog,
|
||||||
domain,
|
domain,
|
||||||
config,
|
config,
|
||||||
|
@ -729,20 +732,18 @@ async def test_reloadable(
|
||||||
)
|
)
|
||||||
async def test_encoding_subscribable_topics(
|
async def test_encoding_subscribable_topics(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
topic: str,
|
||||||
topic,
|
value: str,
|
||||||
value,
|
attribute: str | None,
|
||||||
attribute,
|
attribute_value: Any,
|
||||||
attribute_value,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test handling of incoming encoded payload."""
|
"""Test handling of incoming encoded payload."""
|
||||||
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][select.DOMAIN])
|
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][select.DOMAIN])
|
||||||
config["options"] = ["milk", "beer"]
|
config["options"] = ["milk", "beer"]
|
||||||
await help_test_encoding_subscribable_topics(
|
await help_test_encoding_subscribable_topics(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
caplog,
|
|
||||||
select.DOMAIN,
|
select.DOMAIN,
|
||||||
config,
|
config,
|
||||||
topic,
|
topic,
|
||||||
|
@ -752,10 +753,13 @@ async def test_encoding_subscribable_topics(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None:
|
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||||
|
async def test_setup_manual_entity_from_yaml(
|
||||||
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
|
) -> None:
|
||||||
"""Test setup manual configured MQTT entity."""
|
"""Test setup manual configured MQTT entity."""
|
||||||
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
platform = select.DOMAIN
|
platform = select.DOMAIN
|
||||||
await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
|
|
||||||
assert hass.states.get(f"{platform}.test")
|
assert hass.states.get(f"{platform}.test")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ import copy
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import json
|
import json
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from typing import Any
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
from freezegun.api import FrozenDateTimeFactory
|
from freezegun.api import FrozenDateTimeFactory
|
||||||
|
@ -56,7 +57,6 @@ from .test_common import (
|
||||||
help_test_setting_attribute_via_mqtt_json_message,
|
help_test_setting_attribute_via_mqtt_json_message,
|
||||||
help_test_setting_attribute_with_template,
|
help_test_setting_attribute_with_template,
|
||||||
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
||||||
help_test_setup_manual_entity_from_yaml,
|
|
||||||
help_test_unique_id,
|
help_test_unique_id,
|
||||||
help_test_unload_config_entry_with_platform,
|
help_test_unload_config_entry_with_platform,
|
||||||
help_test_update_with_json_attrs_bad_json,
|
help_test_update_with_json_attrs_bad_json,
|
||||||
|
@ -943,29 +943,32 @@ async def test_discovery_update_attr(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"hass_config",
|
||||||
|
[
|
||||||
|
{
|
||||||
|
mqtt.DOMAIN: {
|
||||||
|
sensor.DOMAIN: [
|
||||||
|
{
|
||||||
|
"name": "Test 1",
|
||||||
|
"state_topic": "test-topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Test 2",
|
||||||
|
"state_topic": "test-topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
)
|
||||||
async def test_unique_id(
|
async def test_unique_id(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test unique id option only creates one sensor per unique_id."""
|
"""Test unique id option only creates one sensor per unique_id."""
|
||||||
config = {
|
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN)
|
||||||
mqtt.DOMAIN: {
|
|
||||||
sensor.DOMAIN: [
|
|
||||||
{
|
|
||||||
"name": "Test 1",
|
|
||||||
"state_topic": "test-topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Test 2",
|
|
||||||
"state_topic": "test-topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await help_test_unique_id(
|
|
||||||
hass, mqtt_mock_entry_with_yaml_config, sensor.DOMAIN, config
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_discovery_removal_sensor(
|
async def test_discovery_removal_sensor(
|
||||||
|
@ -1123,11 +1126,11 @@ async def test_entity_device_info_remove(
|
||||||
|
|
||||||
|
|
||||||
async def test_entity_id_update_subscriptions(
|
async def test_entity_id_update_subscriptions(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||||
await help_test_entity_id_update_subscriptions(
|
await help_test_entity_id_update_subscriptions(
|
||||||
hass, mqtt_mock_entry_with_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
|
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1378,18 +1381,16 @@ async def test_skip_restoring_state_with_over_due_expire_trigger(
|
||||||
)
|
)
|
||||||
async def test_encoding_subscribable_topics(
|
async def test_encoding_subscribable_topics(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
topic: str,
|
||||||
topic,
|
value: str,
|
||||||
value,
|
attribute: str | None,
|
||||||
attribute,
|
attribute_value: Any,
|
||||||
attribute_value,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test handling of incoming encoded payload."""
|
"""Test handling of incoming encoded payload."""
|
||||||
await help_test_encoding_subscribable_topics(
|
await help_test_encoding_subscribable_topics(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
caplog,
|
|
||||||
sensor.DOMAIN,
|
sensor.DOMAIN,
|
||||||
DEFAULT_CONFIG[mqtt.DOMAIN][sensor.DOMAIN],
|
DEFAULT_CONFIG[mqtt.DOMAIN][sensor.DOMAIN],
|
||||||
topic,
|
topic,
|
||||||
|
@ -1400,10 +1401,13 @@ async def test_encoding_subscribable_topics(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None:
|
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||||
|
async def test_setup_manual_entity_from_yaml(
|
||||||
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
|
) -> None:
|
||||||
"""Test setup manual configured MQTT entity."""
|
"""Test setup manual configured MQTT entity."""
|
||||||
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
platform = sensor.DOMAIN
|
platform = sensor.DOMAIN
|
||||||
await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
|
|
||||||
assert hass.states.get(f"{platform}.test")
|
assert hass.states.get(f"{platform}.test")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,6 @@ from .test_common import (
|
||||||
help_test_setting_attribute_via_mqtt_json_message,
|
help_test_setting_attribute_via_mqtt_json_message,
|
||||||
help_test_setting_attribute_with_template,
|
help_test_setting_attribute_with_template,
|
||||||
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
||||||
help_test_setup_manual_entity_from_yaml,
|
|
||||||
help_test_unique_id,
|
help_test_unique_id,
|
||||||
help_test_unload_config_entry_with_platform,
|
help_test_unload_config_entry_with_platform,
|
||||||
help_test_update_with_json_attrs_bad_json,
|
help_test_update_with_json_attrs_bad_json,
|
||||||
|
@ -641,31 +640,34 @@ async def test_discovery_update_attr(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"hass_config",
|
||||||
|
[
|
||||||
|
{
|
||||||
|
mqtt.DOMAIN: {
|
||||||
|
siren.DOMAIN: [
|
||||||
|
{
|
||||||
|
"name": "Test 1",
|
||||||
|
"state_topic": "test-topic",
|
||||||
|
"command_topic": "command-topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Test 2",
|
||||||
|
"state_topic": "test-topic",
|
||||||
|
"command_topic": "command-topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
)
|
||||||
async def test_unique_id(
|
async def test_unique_id(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test unique id option only creates one siren per unique_id."""
|
"""Test unique id option only creates one siren per unique_id."""
|
||||||
config = {
|
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN)
|
||||||
mqtt.DOMAIN: {
|
|
||||||
siren.DOMAIN: [
|
|
||||||
{
|
|
||||||
"name": "Test 1",
|
|
||||||
"state_topic": "test-topic",
|
|
||||||
"command_topic": "command-topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Test 2",
|
|
||||||
"state_topic": "test-topic",
|
|
||||||
"command_topic": "command-topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await help_test_unique_id(
|
|
||||||
hass, mqtt_mock_entry_with_yaml_config, siren.DOMAIN, config
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_discovery_removal_siren(
|
async def test_discovery_removal_siren(
|
||||||
|
@ -924,11 +926,11 @@ async def test_entity_device_info_remove(
|
||||||
|
|
||||||
|
|
||||||
async def test_entity_id_update_subscriptions(
|
async def test_entity_id_update_subscriptions(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||||
await help_test_entity_id_update_subscriptions(
|
await help_test_entity_id_update_subscriptions(
|
||||||
hass, mqtt_mock_entry_with_yaml_config, siren.DOMAIN, DEFAULT_CONFIG
|
hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -976,13 +978,13 @@ async def test_entity_debug_info_message(
|
||||||
)
|
)
|
||||||
async def test_publishing_with_custom_encoding(
|
async def test_publishing_with_custom_encoding(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
service,
|
service: str,
|
||||||
topic,
|
topic: str,
|
||||||
parameters,
|
parameters: dict[str, Any],
|
||||||
payload,
|
payload: str,
|
||||||
template,
|
template: str | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test publishing MQTT payload with command templates and different encoding."""
|
"""Test publishing MQTT payload with command templates and different encoding."""
|
||||||
domain = siren.DOMAIN
|
domain = siren.DOMAIN
|
||||||
|
@ -991,7 +993,7 @@ async def test_publishing_with_custom_encoding(
|
||||||
|
|
||||||
await help_test_publishing_with_custom_encoding(
|
await help_test_publishing_with_custom_encoding(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
caplog,
|
caplog,
|
||||||
domain,
|
domain,
|
||||||
config,
|
config,
|
||||||
|
@ -1021,18 +1023,16 @@ async def test_reloadable(
|
||||||
)
|
)
|
||||||
async def test_encoding_subscribable_topics(
|
async def test_encoding_subscribable_topics(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
topic: str,
|
||||||
topic,
|
value: str,
|
||||||
value,
|
attribute: str | None,
|
||||||
attribute,
|
attribute_value: Any,
|
||||||
attribute_value,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test handling of incoming encoded payload."""
|
"""Test handling of incoming encoded payload."""
|
||||||
await help_test_encoding_subscribable_topics(
|
await help_test_encoding_subscribable_topics(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
caplog,
|
|
||||||
siren.DOMAIN,
|
siren.DOMAIN,
|
||||||
DEFAULT_CONFIG[mqtt.DOMAIN][siren.DOMAIN],
|
DEFAULT_CONFIG[mqtt.DOMAIN][siren.DOMAIN],
|
||||||
topic,
|
topic,
|
||||||
|
@ -1042,10 +1042,13 @@ async def test_encoding_subscribable_topics(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None:
|
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||||
|
async def test_setup_manual_entity_from_yaml(
|
||||||
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
|
) -> None:
|
||||||
"""Test setup manual configured MQTT entity."""
|
"""Test setup manual configured MQTT entity."""
|
||||||
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
platform = siren.DOMAIN
|
platform = siren.DOMAIN
|
||||||
await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
|
|
||||||
assert hass.states.get(f"{platform}.test")
|
assert hass.states.get(f"{platform}.test")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
"""The tests for the State vacuum Mqtt platform."""
|
"""The tests for the State vacuum Mqtt platform."""
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
import json
|
import json
|
||||||
|
from typing import Any
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -53,7 +54,6 @@ from .test_common import (
|
||||||
help_test_setting_attribute_via_mqtt_json_message,
|
help_test_setting_attribute_via_mqtt_json_message,
|
||||||
help_test_setting_attribute_with_template,
|
help_test_setting_attribute_with_template,
|
||||||
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
||||||
help_test_setup_manual_entity_from_yaml,
|
|
||||||
help_test_unique_id,
|
help_test_unique_id,
|
||||||
help_test_update_with_json_attrs_bad_json,
|
help_test_update_with_json_attrs_bad_json,
|
||||||
help_test_update_with_json_attrs_not_dict,
|
help_test_update_with_json_attrs_not_dict,
|
||||||
|
@ -482,31 +482,34 @@ async def test_discovery_update_attr(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"hass_config",
|
||||||
|
[
|
||||||
|
{
|
||||||
|
mqtt.DOMAIN: {
|
||||||
|
vacuum.DOMAIN: [
|
||||||
|
{
|
||||||
|
"schema": "state",
|
||||||
|
"name": "Test 1",
|
||||||
|
"command_topic": "command-topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"schema": "state",
|
||||||
|
"name": "Test 2",
|
||||||
|
"command_topic": "command-topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
)
|
||||||
async def test_unique_id(
|
async def test_unique_id(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test unique id option only creates one vacuum per unique_id."""
|
"""Test unique id option only creates one vacuum per unique_id."""
|
||||||
config = {
|
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN)
|
||||||
mqtt.DOMAIN: {
|
|
||||||
vacuum.DOMAIN: [
|
|
||||||
{
|
|
||||||
"schema": "state",
|
|
||||||
"name": "Test 1",
|
|
||||||
"command_topic": "command-topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"schema": "state",
|
|
||||||
"name": "Test 2",
|
|
||||||
"command_topic": "command-topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await help_test_unique_id(
|
|
||||||
hass, mqtt_mock_entry_with_yaml_config, vacuum.DOMAIN, config
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_discovery_removal_vacuum(
|
async def test_discovery_removal_vacuum(
|
||||||
|
@ -605,11 +608,11 @@ async def test_entity_device_info_remove(
|
||||||
|
|
||||||
|
|
||||||
async def test_entity_id_update_subscriptions(
|
async def test_entity_id_update_subscriptions(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||||
await help_test_entity_id_update_subscriptions(
|
await help_test_entity_id_update_subscriptions(
|
||||||
hass, mqtt_mock_entry_with_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -679,13 +682,13 @@ async def test_entity_debug_info_message(
|
||||||
)
|
)
|
||||||
async def test_publishing_with_custom_encoding(
|
async def test_publishing_with_custom_encoding(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
service,
|
service: str,
|
||||||
topic,
|
topic: str,
|
||||||
parameters,
|
parameters: dict[str, Any],
|
||||||
payload,
|
payload: str,
|
||||||
template,
|
template: str | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test publishing MQTT payload with different encoding."""
|
"""Test publishing MQTT payload with different encoding."""
|
||||||
domain = vacuum.DOMAIN
|
domain = vacuum.DOMAIN
|
||||||
|
@ -705,7 +708,7 @@ async def test_publishing_with_custom_encoding(
|
||||||
|
|
||||||
await help_test_publishing_with_custom_encoding(
|
await help_test_publishing_with_custom_encoding(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
caplog,
|
caplog,
|
||||||
domain,
|
domain,
|
||||||
config,
|
config,
|
||||||
|
@ -746,18 +749,16 @@ async def test_reloadable(
|
||||||
)
|
)
|
||||||
async def test_encoding_subscribable_topics(
|
async def test_encoding_subscribable_topics(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
topic: str,
|
||||||
topic,
|
value: str,
|
||||||
value,
|
attribute: str | None,
|
||||||
attribute,
|
attribute_value: Any,
|
||||||
attribute_value,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test handling of incoming encoded payload."""
|
"""Test handling of incoming encoded payload."""
|
||||||
await help_test_encoding_subscribable_topics(
|
await help_test_encoding_subscribable_topics(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
caplog,
|
|
||||||
vacuum.DOMAIN,
|
vacuum.DOMAIN,
|
||||||
DEFAULT_CONFIG[mqtt.DOMAIN][vacuum.DOMAIN],
|
DEFAULT_CONFIG[mqtt.DOMAIN][vacuum.DOMAIN],
|
||||||
topic,
|
topic,
|
||||||
|
@ -768,8 +769,11 @@ async def test_encoding_subscribable_topics(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None:
|
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||||
|
async def test_setup_manual_entity_from_yaml(
|
||||||
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
|
) -> None:
|
||||||
"""Test setup manual configured MQTT entity."""
|
"""Test setup manual configured MQTT entity."""
|
||||||
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
platform = vacuum.DOMAIN
|
platform = vacuum.DOMAIN
|
||||||
await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
|
|
||||||
assert hass.states.get(f"{platform}.mqtttest")
|
assert hass.states.get(f"{platform}.mqtttest")
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
"""The tests for the MQTT switch platform."""
|
"""The tests for the MQTT switch platform."""
|
||||||
import copy
|
import copy
|
||||||
|
from typing import Any
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -39,7 +40,6 @@ from .test_common import (
|
||||||
help_test_setting_attribute_via_mqtt_json_message,
|
help_test_setting_attribute_via_mqtt_json_message,
|
||||||
help_test_setting_attribute_with_template,
|
help_test_setting_attribute_with_template,
|
||||||
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
||||||
help_test_setup_manual_entity_from_yaml,
|
|
||||||
help_test_unique_id,
|
help_test_unique_id,
|
||||||
help_test_unload_config_entry_with_platform,
|
help_test_unload_config_entry_with_platform,
|
||||||
help_test_update_with_json_attrs_bad_json,
|
help_test_update_with_json_attrs_bad_json,
|
||||||
|
@ -403,31 +403,34 @@ async def test_discovery_update_attr(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"hass_config",
|
||||||
|
[
|
||||||
|
{
|
||||||
|
mqtt.DOMAIN: {
|
||||||
|
switch.DOMAIN: [
|
||||||
|
{
|
||||||
|
"name": "Test 1",
|
||||||
|
"state_topic": "test-topic",
|
||||||
|
"command_topic": "command-topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Test 2",
|
||||||
|
"state_topic": "test-topic",
|
||||||
|
"command_topic": "command-topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
)
|
||||||
async def test_unique_id(
|
async def test_unique_id(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test unique id option only creates one switch per unique_id."""
|
"""Test unique id option only creates one switch per unique_id."""
|
||||||
config = {
|
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN)
|
||||||
mqtt.DOMAIN: {
|
|
||||||
switch.DOMAIN: [
|
|
||||||
{
|
|
||||||
"name": "Test 1",
|
|
||||||
"state_topic": "test-topic",
|
|
||||||
"command_topic": "command-topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Test 2",
|
|
||||||
"state_topic": "test-topic",
|
|
||||||
"command_topic": "command-topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await help_test_unique_id(
|
|
||||||
hass, mqtt_mock_entry_with_yaml_config, switch.DOMAIN, config
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_discovery_removal_switch(
|
async def test_discovery_removal_switch(
|
||||||
|
@ -602,11 +605,11 @@ async def test_entity_device_info_remove(
|
||||||
|
|
||||||
|
|
||||||
async def test_entity_id_update_subscriptions(
|
async def test_entity_id_update_subscriptions(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||||
await help_test_entity_id_update_subscriptions(
|
await help_test_entity_id_update_subscriptions(
|
||||||
hass, mqtt_mock_entry_with_yaml_config, switch.DOMAIN, DEFAULT_CONFIG
|
hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -653,13 +656,13 @@ async def test_entity_debug_info_message(
|
||||||
)
|
)
|
||||||
async def test_publishing_with_custom_encoding(
|
async def test_publishing_with_custom_encoding(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
service,
|
service: str,
|
||||||
topic,
|
topic: str,
|
||||||
parameters,
|
parameters: dict[str, Any],
|
||||||
payload,
|
payload: str,
|
||||||
template,
|
template: str | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test publishing MQTT payload with different encoding."""
|
"""Test publishing MQTT payload with different encoding."""
|
||||||
domain = switch.DOMAIN
|
domain = switch.DOMAIN
|
||||||
|
@ -667,7 +670,7 @@ async def test_publishing_with_custom_encoding(
|
||||||
|
|
||||||
await help_test_publishing_with_custom_encoding(
|
await help_test_publishing_with_custom_encoding(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
caplog,
|
caplog,
|
||||||
domain,
|
domain,
|
||||||
config,
|
config,
|
||||||
|
@ -697,18 +700,16 @@ async def test_reloadable(
|
||||||
)
|
)
|
||||||
async def test_encoding_subscribable_topics(
|
async def test_encoding_subscribable_topics(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
topic: str,
|
||||||
topic,
|
value: str,
|
||||||
value,
|
attribute: str | None,
|
||||||
attribute,
|
attribute_value: Any,
|
||||||
attribute_value,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test handling of incoming encoded payload."""
|
"""Test handling of incoming encoded payload."""
|
||||||
await help_test_encoding_subscribable_topics(
|
await help_test_encoding_subscribable_topics(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
caplog,
|
|
||||||
switch.DOMAIN,
|
switch.DOMAIN,
|
||||||
DEFAULT_CONFIG[mqtt.DOMAIN][switch.DOMAIN],
|
DEFAULT_CONFIG[mqtt.DOMAIN][switch.DOMAIN],
|
||||||
topic,
|
topic,
|
||||||
|
@ -718,10 +719,13 @@ async def test_encoding_subscribable_topics(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None:
|
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||||
|
async def test_setup_manual_entity_from_yaml(
|
||||||
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
|
) -> None:
|
||||||
"""Test setup manual configured MQTT entity."""
|
"""Test setup manual configured MQTT entity."""
|
||||||
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
platform = switch.DOMAIN
|
platform = switch.DOMAIN
|
||||||
await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
|
|
||||||
assert hass.states.get(f"{platform}.test")
|
assert hass.states.get(f"{platform}.test")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
"""The tests for the MQTT text platform."""
|
"""The tests for the MQTT text platform."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -38,7 +39,6 @@ from .test_common import (
|
||||||
help_test_setting_attribute_via_mqtt_json_message,
|
help_test_setting_attribute_via_mqtt_json_message,
|
||||||
help_test_setting_attribute_with_template,
|
help_test_setting_attribute_with_template,
|
||||||
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
||||||
help_test_setup_manual_entity_from_yaml,
|
|
||||||
help_test_unique_id,
|
help_test_unique_id,
|
||||||
help_test_unload_config_entry_with_platform,
|
help_test_unload_config_entry_with_platform,
|
||||||
help_test_update_with_json_attrs_bad_json,
|
help_test_update_with_json_attrs_bad_json,
|
||||||
|
@ -454,31 +454,34 @@ async def test_discovery_update_attr(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"hass_config",
|
||||||
|
[
|
||||||
|
{
|
||||||
|
mqtt.DOMAIN: {
|
||||||
|
text.DOMAIN: [
|
||||||
|
{
|
||||||
|
"name": "Test 1",
|
||||||
|
"state_topic": "test-topic",
|
||||||
|
"command_topic": "command-topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Test 2",
|
||||||
|
"state_topic": "test-topic",
|
||||||
|
"command_topic": "command-topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
)
|
||||||
async def test_unique_id(
|
async def test_unique_id(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test unique id option only creates one text per unique_id."""
|
"""Test unique id option only creates one text per unique_id."""
|
||||||
config = {
|
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN)
|
||||||
mqtt.DOMAIN: {
|
|
||||||
text.DOMAIN: [
|
|
||||||
{
|
|
||||||
"name": "Test 1",
|
|
||||||
"state_topic": "test-topic",
|
|
||||||
"command_topic": "command-topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Test 2",
|
|
||||||
"state_topic": "test-topic",
|
|
||||||
"command_topic": "command-topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await help_test_unique_id(
|
|
||||||
hass, mqtt_mock_entry_with_yaml_config, text.DOMAIN, config
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_discovery_removal_text(
|
async def test_discovery_removal_text(
|
||||||
|
@ -627,11 +630,11 @@ async def test_entity_device_info_remove(
|
||||||
|
|
||||||
|
|
||||||
async def test_entity_id_update_subscriptions(
|
async def test_entity_id_update_subscriptions(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||||
await help_test_entity_id_update_subscriptions(
|
await help_test_entity_id_update_subscriptions(
|
||||||
hass, mqtt_mock_entry_with_yaml_config, text.DOMAIN, DEFAULT_CONFIG
|
hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN, DEFAULT_CONFIG
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -667,13 +670,13 @@ async def test_entity_debug_info_message(
|
||||||
)
|
)
|
||||||
async def test_publishing_with_custom_encoding(
|
async def test_publishing_with_custom_encoding(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
service,
|
service: str,
|
||||||
topic,
|
topic: str,
|
||||||
parameters,
|
parameters: dict[str, Any],
|
||||||
payload,
|
payload: str,
|
||||||
template,
|
template: str | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test publishing MQTT payload with different encoding."""
|
"""Test publishing MQTT payload with different encoding."""
|
||||||
domain = text.DOMAIN
|
domain = text.DOMAIN
|
||||||
|
@ -681,7 +684,7 @@ async def test_publishing_with_custom_encoding(
|
||||||
|
|
||||||
await help_test_publishing_with_custom_encoding(
|
await help_test_publishing_with_custom_encoding(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
caplog,
|
caplog,
|
||||||
domain,
|
domain,
|
||||||
config,
|
config,
|
||||||
|
@ -711,18 +714,16 @@ async def test_reloadable(
|
||||||
)
|
)
|
||||||
async def test_encoding_subscribable_topics(
|
async def test_encoding_subscribable_topics(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
topic: str,
|
||||||
topic,
|
value: str,
|
||||||
value,
|
attribute: str | None,
|
||||||
attribute,
|
attribute_value: Any,
|
||||||
attribute_value,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test handling of incoming encoded payload."""
|
"""Test handling of incoming encoded payload."""
|
||||||
await help_test_encoding_subscribable_topics(
|
await help_test_encoding_subscribable_topics(
|
||||||
hass,
|
hass,
|
||||||
mqtt_mock_entry_with_yaml_config,
|
mqtt_mock_entry_no_yaml_config,
|
||||||
caplog,
|
|
||||||
text.DOMAIN,
|
text.DOMAIN,
|
||||||
DEFAULT_CONFIG[mqtt.DOMAIN][text.DOMAIN],
|
DEFAULT_CONFIG[mqtt.DOMAIN][text.DOMAIN],
|
||||||
topic,
|
topic,
|
||||||
|
@ -732,10 +733,13 @@ async def test_encoding_subscribable_topics(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None:
|
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||||
|
async def test_setup_manual_entity_from_yaml(
|
||||||
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
|
) -> None:
|
||||||
"""Test setup manual configured MQTT entity."""
|
"""Test setup manual configured MQTT entity."""
|
||||||
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
platform = text.DOMAIN
|
platform = text.DOMAIN
|
||||||
await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
|
|
||||||
assert hass.states.get(f"{platform}.test")
|
assert hass.states.get(f"{platform}.test")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,6 @@ from .test_common import (
|
||||||
help_test_reloadable,
|
help_test_reloadable,
|
||||||
help_test_setting_attribute_via_mqtt_json_message,
|
help_test_setting_attribute_via_mqtt_json_message,
|
||||||
help_test_setting_attribute_with_template,
|
help_test_setting_attribute_with_template,
|
||||||
help_test_setup_manual_entity_from_yaml,
|
|
||||||
help_test_unique_id,
|
help_test_unique_id,
|
||||||
help_test_unload_config_entry_with_platform,
|
help_test_unload_config_entry_with_platform,
|
||||||
help_test_update_with_json_attrs_bad_json,
|
help_test_update_with_json_attrs_bad_json,
|
||||||
|
@ -529,31 +528,34 @@ async def test_discovery_update_attr(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"hass_config",
|
||||||
|
[
|
||||||
|
{
|
||||||
|
mqtt.DOMAIN: {
|
||||||
|
update.DOMAIN: [
|
||||||
|
{
|
||||||
|
"name": "Bear",
|
||||||
|
"state_topic": "installed-topic",
|
||||||
|
"latest_version_topic": "latest-topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Milk",
|
||||||
|
"state_topic": "installed-topic",
|
||||||
|
"latest_version_topic": "latest-topic",
|
||||||
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
)
|
||||||
async def test_unique_id(
|
async def test_unique_id(
|
||||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test unique id option only creates one update per unique_id."""
|
"""Test unique id option only creates one update per unique_id."""
|
||||||
config = {
|
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, update.DOMAIN)
|
||||||
mqtt.DOMAIN: {
|
|
||||||
update.DOMAIN: [
|
|
||||||
{
|
|
||||||
"name": "Bear",
|
|
||||||
"state_topic": "installed-topic",
|
|
||||||
"latest_version_topic": "latest-topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Milk",
|
|
||||||
"state_topic": "installed-topic",
|
|
||||||
"latest_version_topic": "latest-topic",
|
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await help_test_unique_id(
|
|
||||||
hass, mqtt_mock_entry_with_yaml_config, update.DOMAIN, config
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_discovery_removal_update(
|
async def test_discovery_removal_update(
|
||||||
|
@ -670,10 +672,13 @@ async def test_entity_id_update_discovery_update(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None:
|
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||||
|
async def test_setup_manual_entity_from_yaml(
|
||||||
|
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||||
|
) -> None:
|
||||||
"""Test setup manual configured MQTT entity."""
|
"""Test setup manual configured MQTT entity."""
|
||||||
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
platform = update.DOMAIN
|
platform = update.DOMAIN
|
||||||
await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
|
|
||||||
assert hass.states.get(f"{platform}.test")
|
assert hass.states.get(f"{platform}.test")
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue