Refactor common MQTT tests to use modern schema (#77583)

* Common tests availability

* Common tests attributes

* Common tests unique id

* Common tests discovery

* Common tests encoding

* Common tests device info

* Common tests entity_id updated

* Common tests entity debug info

* Common test entity category

* Common tests setup reload unload+corrections

* Cleanup sweep

* Comments from curent change

* Cleanup

* Remove unused legacy config
This commit is contained in:
Jan Bouwhuis 2022-09-09 11:15:48 +02:00 committed by GitHub
parent d53d59eb6c
commit 9a4c8f5f0e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 1125 additions and 1123 deletions

View file

@ -61,7 +61,7 @@ from .test_common import (
help_test_setup_manual_entity_from_yaml, 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,
help_test_update_with_json_attrs_not_dict, help_test_update_with_json_attrs_not_dict,
) )
@ -121,8 +121,6 @@ DEFAULT_CONFIG_REMOTE_CODE_TEXT = {
# Scheduled to be removed in HA core 2022.12 # Scheduled to be removed in HA core 2022.12
DEFAULT_CONFIG_LEGACY = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN]) DEFAULT_CONFIG_LEGACY = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
DEFAULT_CONFIG_LEGACY[alarm_control_panel.DOMAIN]["platform"] = mqtt.DOMAIN DEFAULT_CONFIG_LEGACY[alarm_control_panel.DOMAIN]["platform"] = mqtt.DOMAIN
DEFAULT_CONFIG_CODE_LEGACY = copy.deepcopy(DEFAULT_CONFIG_CODE[mqtt.DOMAIN])
DEFAULT_CONFIG_CODE_LEGACY[alarm_control_panel.DOMAIN]["platform"] = mqtt.DOMAIN
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
@ -588,7 +586,7 @@ async def test_availability_when_connection_lost(
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
DEFAULT_CONFIG_CODE_LEGACY, DEFAULT_CONFIG_CODE,
) )
@ -598,7 +596,7 @@ async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
DEFAULT_CONFIG_CODE_LEGACY, DEFAULT_CONFIG_CODE,
) )
@ -608,7 +606,7 @@ async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_conf
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
DEFAULT_CONFIG_CODE_LEGACY, DEFAULT_CONFIG_CODE,
) )
@ -618,7 +616,7 @@ async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_confi
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
DEFAULT_CONFIG_CODE_LEGACY, DEFAULT_CONFIG,
) )
@ -630,7 +628,7 @@ async def test_setting_attribute_via_mqtt_json_message(
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -642,7 +640,7 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
MQTT_ALARM_ATTRIBUTES_BLOCKED, MQTT_ALARM_ATTRIBUTES_BLOCKED,
) )
@ -653,7 +651,7 @@ async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_c
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -666,20 +664,20 @@ async def test_update_with_json_attrs_not_dict(
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
async def test_update_with_json_attrs_bad_JSON( async def test_update_with_json_attrs_bad_json(
hass, mqtt_mock_entry_with_yaml_config, caplog hass, mqtt_mock_entry_with_yaml_config, caplog
): ):
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_JSON( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -690,29 +688,29 @@ async def test_discovery_update_attr(hass, mqtt_mock_entry_no_yaml_config, caplo
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
caplog, caplog,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config): async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config):
"""Test unique id option only creates one alarm per unique_id.""" """Test unique id option only creates one alarm per unique_id."""
config = { config = {
alarm_control_panel.DOMAIN: [ mqtt.DOMAIN: {
{ alarm_control_panel.DOMAIN: [
"platform": "mqtt", {
"name": "Test 1", "name": "Test 1",
"state_topic": "test-topic", "state_topic": "test-topic",
"command_topic": "command-topic", "command_topic": "command-topic",
"unique_id": "TOTALLY_UNIQUE", "unique_id": "TOTALLY_UNIQUE",
}, },
{ {
"platform": "mqtt", "name": "Test 2",
"name": "Test 2", "state_topic": "test-topic",
"state_topic": "test-topic", "command_topic": "command-topic",
"command_topic": "command-topic", "unique_id": "TOTALLY_UNIQUE",
"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_with_yaml_config, alarm_control_panel.DOMAIN, config
@ -721,7 +719,7 @@ async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config):
async def test_discovery_removal_alarm(hass, mqtt_mock_entry_no_yaml_config, caplog): async def test_discovery_removal_alarm(hass, mqtt_mock_entry_no_yaml_config, caplog):
"""Test removal of discovered alarm_control_panel.""" """Test removal of discovered alarm_control_panel."""
data = json.dumps(DEFAULT_CONFIG_LEGACY[alarm_control_panel.DOMAIN]) data = json.dumps(DEFAULT_CONFIG[mqtt.DOMAIN][alarm_control_panel.DOMAIN])
await help_test_discovery_removal( await help_test_discovery_removal(
hass, mqtt_mock_entry_no_yaml_config, caplog, alarm_control_panel.DOMAIN, data hass, mqtt_mock_entry_no_yaml_config, caplog, alarm_control_panel.DOMAIN, data
) )
@ -731,8 +729,8 @@ async def test_discovery_update_alarm_topic_and_template(
hass, mqtt_mock_entry_no_yaml_config, caplog hass, mqtt_mock_entry_no_yaml_config, caplog
): ):
"""Test update of discovered alarm_control_panel.""" """Test update of discovered alarm_control_panel."""
config1 = copy.deepcopy(DEFAULT_CONFIG_LEGACY[alarm_control_panel.DOMAIN]) config1 = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][alarm_control_panel.DOMAIN])
config2 = copy.deepcopy(DEFAULT_CONFIG_LEGACY[alarm_control_panel.DOMAIN]) config2 = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][alarm_control_panel.DOMAIN])
config1["name"] = "Beer" config1["name"] = "Beer"
config2["name"] = "Milk" config2["name"] = "Milk"
config1["state_topic"] = "alarm/state1" config1["state_topic"] = "alarm/state1"
@ -766,8 +764,8 @@ async def test_discovery_update_alarm_template(
hass, mqtt_mock_entry_no_yaml_config, caplog hass, mqtt_mock_entry_no_yaml_config, caplog
): ):
"""Test update of discovered alarm_control_panel.""" """Test update of discovered alarm_control_panel."""
config1 = copy.deepcopy(DEFAULT_CONFIG_LEGACY[alarm_control_panel.DOMAIN]) config1 = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][alarm_control_panel.DOMAIN])
config2 = copy.deepcopy(DEFAULT_CONFIG_LEGACY[alarm_control_panel.DOMAIN]) config2 = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][alarm_control_panel.DOMAIN])
config1["name"] = "Beer" config1["name"] = "Beer"
config2["name"] = "Milk" config2["name"] = "Milk"
config1["state_topic"] = "alarm/state1" config1["state_topic"] = "alarm/state1"
@ -799,7 +797,7 @@ async def test_discovery_update_unchanged_alarm(
hass, mqtt_mock_entry_no_yaml_config, caplog hass, mqtt_mock_entry_no_yaml_config, caplog
): ):
"""Test update of discovered alarm_control_panel.""" """Test update of discovered alarm_control_panel."""
config1 = copy.deepcopy(DEFAULT_CONFIG_LEGACY[alarm_control_panel.DOMAIN]) config1 = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][alarm_control_panel.DOMAIN])
config1["name"] = "Beer" config1["name"] = "Beer"
data1 = json.dumps(config1) data1 = json.dumps(config1)
@ -851,7 +849,7 @@ async def test_encoding_subscribable_topics(
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
DEFAULT_CONFIG_LEGACY[alarm_control_panel.DOMAIN], DEFAULT_CONFIG[mqtt.DOMAIN][alarm_control_panel.DOMAIN],
topic, topic,
value, value,
) )
@ -863,7 +861,7 @@ async def test_entity_device_info_with_connection(hass, mqtt_mock_entry_no_yaml_
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -873,7 +871,7 @@ async def test_entity_device_info_with_identifier(hass, mqtt_mock_entry_no_yaml_
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -883,7 +881,7 @@ async def test_entity_device_info_update(hass, mqtt_mock_entry_no_yaml_config):
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -893,7 +891,7 @@ async def test_entity_device_info_remove(hass, mqtt_mock_entry_no_yaml_config):
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -903,7 +901,7 @@ async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_co
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -913,7 +911,7 @@ async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_c
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -923,7 +921,7 @@ async def test_entity_debug_info_message(hass, mqtt_mock_entry_no_yaml_config):
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
alarm_control_panel.SERVICE_ALARM_DISARM, alarm_control_panel.SERVICE_ALARM_DISARM,
command_payload="DISARM", command_payload="DISARM",
) )
@ -966,7 +964,7 @@ async def test_publishing_with_custom_encoding(
): ):
"""Test publishing MQTT payload with different encoding.""" """Test publishing MQTT payload with different encoding."""
domain = alarm_control_panel.DOMAIN domain = alarm_control_panel.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding(
hass, hass,
@ -987,12 +985,14 @@ async def test_publishing_with_custom_encoding(
async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path): async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path):
"""Test reloading the MQTT platform.""" """Test reloading the MQTT platform."""
domain = alarm_control_panel.DOMAIN domain = alarm_control_panel.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_reloadable( await help_test_reloadable(
hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config
) )
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path): async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup.""" """Test reloading the MQTT platform with late entry setup."""
domain = alarm_control_panel.DOMAIN domain = alarm_control_panel.DOMAIN
@ -1003,17 +1003,14 @@ async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
async def test_setup_manual_entity_from_yaml(hass): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = alarm_control_panel.DOMAIN platform = alarm_control_panel.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[platform]) await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
config["name"] = "test" assert hass.states.get(f"{platform}.test")
del config["platform"]
await help_test_setup_manual_entity_from_yaml(hass, platform, config)
assert hass.states.get(f"{platform}.test") is not None
async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path): async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path):
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = alarm_control_panel.DOMAIN domain = alarm_control_panel.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_unload_config_entry_with_platform( await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config
) )

View file

@ -45,7 +45,7 @@ from .test_common import (
help_test_setup_manual_entity_from_yaml, 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,
help_test_update_with_json_attrs_not_dict, help_test_update_with_json_attrs_not_dict,
) )
@ -542,7 +542,7 @@ async def test_availability_when_connection_lost(
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
binary_sensor.DOMAIN, binary_sensor.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -552,7 +552,7 @@ async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
binary_sensor.DOMAIN, binary_sensor.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -562,7 +562,7 @@ async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_conf
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
binary_sensor.DOMAIN, binary_sensor.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -572,7 +572,7 @@ async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_confi
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
binary_sensor.DOMAIN, binary_sensor.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -708,7 +708,7 @@ async def test_setting_attribute_via_mqtt_json_message(
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
binary_sensor.DOMAIN, binary_sensor.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -718,7 +718,7 @@ async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_c
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
binary_sensor.DOMAIN, binary_sensor.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -731,20 +731,20 @@ async def test_update_with_json_attrs_not_dict(
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
binary_sensor.DOMAIN, binary_sensor.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
async def test_update_with_json_attrs_bad_JSON( async def test_update_with_json_attrs_bad_json(
hass, mqtt_mock_entry_with_yaml_config, caplog hass, mqtt_mock_entry_with_yaml_config, caplog
): ):
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_JSON( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
binary_sensor.DOMAIN, binary_sensor.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -755,27 +755,27 @@ async def test_discovery_update_attr(hass, mqtt_mock_entry_no_yaml_config, caplo
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
caplog, caplog,
binary_sensor.DOMAIN, binary_sensor.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config): async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config):
"""Test unique id option only creates one sensor per unique_id.""" """Test unique id option only creates one sensor per unique_id."""
config = { config = {
binary_sensor.DOMAIN: [ mqtt.DOMAIN: {
{ binary_sensor.DOMAIN: [
"platform": "mqtt", {
"name": "Test 1", "name": "Test 1",
"state_topic": "test-topic", "state_topic": "test-topic",
"unique_id": "TOTALLY_UNIQUE", "unique_id": "TOTALLY_UNIQUE",
}, },
{ {
"platform": "mqtt", "name": "Test 2",
"name": "Test 2", "state_topic": "test-topic",
"state_topic": "test-topic", "unique_id": "TOTALLY_UNIQUE",
"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_with_yaml_config, binary_sensor.DOMAIN, config
@ -786,7 +786,7 @@ async def test_discovery_removal_binary_sensor(
hass, mqtt_mock_entry_no_yaml_config, caplog hass, mqtt_mock_entry_no_yaml_config, caplog
): ):
"""Test removal of discovered binary_sensor.""" """Test removal of discovered binary_sensor."""
data = json.dumps(DEFAULT_CONFIG_LEGACY[binary_sensor.DOMAIN]) data = json.dumps(DEFAULT_CONFIG[mqtt.DOMAIN][binary_sensor.DOMAIN])
await help_test_discovery_removal( await help_test_discovery_removal(
hass, mqtt_mock_entry_no_yaml_config, caplog, binary_sensor.DOMAIN, data hass, mqtt_mock_entry_no_yaml_config, caplog, binary_sensor.DOMAIN, data
) )
@ -796,8 +796,8 @@ async def test_discovery_update_binary_sensor_topic_template(
hass, mqtt_mock_entry_no_yaml_config, caplog hass, mqtt_mock_entry_no_yaml_config, caplog
): ):
"""Test update of discovered binary_sensor.""" """Test update of discovered binary_sensor."""
config1 = copy.deepcopy(DEFAULT_CONFIG_LEGACY[binary_sensor.DOMAIN]) config1 = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][binary_sensor.DOMAIN])
config2 = copy.deepcopy(DEFAULT_CONFIG_LEGACY[binary_sensor.DOMAIN]) config2 = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][binary_sensor.DOMAIN])
config1["name"] = "Beer" config1["name"] = "Beer"
config2["name"] = "Milk" config2["name"] = "Milk"
config1["state_topic"] = "sensor/state1" config1["state_topic"] = "sensor/state1"
@ -833,8 +833,8 @@ async def test_discovery_update_binary_sensor_template(
hass, mqtt_mock_entry_no_yaml_config, caplog hass, mqtt_mock_entry_no_yaml_config, caplog
): ):
"""Test update of discovered binary_sensor.""" """Test update of discovered binary_sensor."""
config1 = copy.deepcopy(DEFAULT_CONFIG_LEGACY[binary_sensor.DOMAIN]) config1 = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][binary_sensor.DOMAIN])
config2 = copy.deepcopy(DEFAULT_CONFIG_LEGACY[binary_sensor.DOMAIN]) config2 = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][binary_sensor.DOMAIN])
config1["name"] = "Beer" config1["name"] = "Beer"
config2["name"] = "Milk" config2["name"] = "Milk"
config1["state_topic"] = "sensor/state1" config1["state_topic"] = "sensor/state1"
@ -892,7 +892,7 @@ async def test_encoding_subscribable_topics(
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
binary_sensor.DOMAIN, binary_sensor.DOMAIN,
DEFAULT_CONFIG_LEGACY[binary_sensor.DOMAIN], DEFAULT_CONFIG[mqtt.DOMAIN][binary_sensor.DOMAIN],
topic, topic,
value, value,
attribute, attribute,
@ -904,7 +904,7 @@ async def test_discovery_update_unchanged_binary_sensor(
hass, mqtt_mock_entry_no_yaml_config, caplog hass, mqtt_mock_entry_no_yaml_config, caplog
): ):
"""Test update of discovered binary_sensor.""" """Test update of discovered binary_sensor."""
config1 = copy.deepcopy(DEFAULT_CONFIG_LEGACY[binary_sensor.DOMAIN]) config1 = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][binary_sensor.DOMAIN])
config1["name"] = "Beer" config1["name"] = "Beer"
data1 = json.dumps(config1) data1 = json.dumps(config1)
@ -942,7 +942,7 @@ async def test_entity_device_info_with_connection(hass, mqtt_mock_entry_no_yaml_
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
binary_sensor.DOMAIN, binary_sensor.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -952,7 +952,7 @@ async def test_entity_device_info_with_identifier(hass, mqtt_mock_entry_no_yaml_
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
binary_sensor.DOMAIN, binary_sensor.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -962,7 +962,7 @@ async def test_entity_device_info_update(hass, mqtt_mock_entry_no_yaml_config):
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
binary_sensor.DOMAIN, binary_sensor.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -972,7 +972,7 @@ async def test_entity_device_info_remove(hass, mqtt_mock_entry_no_yaml_config):
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
binary_sensor.DOMAIN, binary_sensor.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -982,7 +982,7 @@ async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_co
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
binary_sensor.DOMAIN, binary_sensor.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -992,7 +992,7 @@ async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_c
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
binary_sensor.DOMAIN, binary_sensor.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -1002,7 +1002,7 @@ async def test_entity_debug_info_message(hass, mqtt_mock_entry_no_yaml_config):
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
binary_sensor.DOMAIN, binary_sensor.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
None, None,
) )
@ -1010,12 +1010,14 @@ async def test_entity_debug_info_message(hass, mqtt_mock_entry_no_yaml_config):
async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path): async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path):
"""Test reloading the MQTT platform.""" """Test reloading the MQTT platform."""
domain = binary_sensor.DOMAIN domain = binary_sensor.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_reloadable( await help_test_reloadable(
hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config
) )
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path): async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup.""" """Test reloading the MQTT platform with late entry setup."""
domain = binary_sensor.DOMAIN domain = binary_sensor.DOMAIN
@ -1040,11 +1042,11 @@ async def test_cleanup_triggers_and_restoring_state(
): ):
"""Test cleanup old triggers at reloading and restoring the state.""" """Test cleanup old triggers at reloading and restoring the state."""
domain = binary_sensor.DOMAIN domain = binary_sensor.DOMAIN
config1 = copy.deepcopy(DEFAULT_CONFIG_LEGACY[domain]) config1 = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][domain])
config1["name"] = "test1" config1["name"] = "test1"
config1["expire_after"] = 30 config1["expire_after"] = 30
config1["state_topic"] = "test-topic1" config1["state_topic"] = "test-topic1"
config2 = copy.deepcopy(DEFAULT_CONFIG_LEGACY[domain]) config2 = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][domain])
config2["name"] = "test2" config2["name"] = "test2"
config2["expire_after"] = 5 config2["expire_after"] = 5
config2["state_topic"] = "test-topic2" config2["state_topic"] = "test-topic2"
@ -1053,8 +1055,8 @@ async def test_cleanup_triggers_and_restoring_state(
assert await async_setup_component( assert await async_setup_component(
hass, hass,
binary_sensor.DOMAIN, mqtt.DOMAIN,
{binary_sensor.DOMAIN: [config1, config2]}, {mqtt.DOMAIN: {binary_sensor.DOMAIN: [config1, config2]}},
) )
await hass.async_block_till_done() await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config() await mqtt_mock_entry_with_yaml_config()
@ -1070,7 +1072,7 @@ async def test_cleanup_triggers_and_restoring_state(
freezer.move_to("2022-02-02 12:01:10+01:00") freezer.move_to("2022-02-02 12:01:10+01:00")
await help_test_reload_with_config( await help_test_reload_with_config(
hass, caplog, tmp_path, {domain: [config1, config2]} hass, caplog, tmp_path, {mqtt.DOMAIN: {domain: [config1, config2]}}
) )
assert "Clean up expire after trigger for binary_sensor.test1" in caplog.text assert "Clean up expire after trigger for binary_sensor.test1" in caplog.text
assert "Clean up expire after trigger for binary_sensor.test2" not in caplog.text assert "Clean up expire after trigger for binary_sensor.test2" not in caplog.text
@ -1125,17 +1127,14 @@ async def test_skip_restoring_state_with_over_due_expire_trigger(
async def test_setup_manual_entity_from_yaml(hass): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = binary_sensor.DOMAIN platform = binary_sensor.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[platform]) await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
config["name"] = "test" assert hass.states.get(f"{platform}.test")
del config["platform"]
await help_test_setup_manual_entity_from_yaml(hass, platform, config)
assert hass.states.get(f"{platform}.test") is not None
async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path): async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path):
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = binary_sensor.DOMAIN domain = binary_sensor.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_unload_config_entry_with_platform( await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config
) )

View file

@ -38,7 +38,7 @@ from .test_common import (
help_test_setup_manual_entity_from_yaml, 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,
help_test_update_with_json_attrs_not_dict, help_test_update_with_json_attrs_not_dict,
) )
@ -140,25 +140,26 @@ async def test_availability_when_connection_lost(
): ):
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_with_yaml_config, button.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, button.DOMAIN, DEFAULT_CONFIG
) )
async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config): async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_with_yaml_config, button.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, button.DOMAIN, DEFAULT_CONFIG
) )
async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_config): async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
config = { config = {
button.DOMAIN: { mqtt.DOMAIN: {
"platform": "mqtt", button.DOMAIN: {
"name": "test", "name": "test",
"command_topic": "command-topic", "command_topic": "command-topic",
"payload_press": 1, "payload_press": 1,
}
} }
} }
@ -176,11 +177,12 @@ async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_conf
async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_config): async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability by custom payload with defined topic.""" """Test availability by custom payload with defined topic."""
config = { config = {
button.DOMAIN: { mqtt.DOMAIN: {
"platform": "mqtt", button.DOMAIN: {
"name": "test", "name": "test",
"command_topic": "command-topic", "command_topic": "command-topic",
"payload_press": 1, "payload_press": 1,
}
} }
} }
@ -200,7 +202,7 @@ async def test_setting_attribute_via_mqtt_json_message(
): ):
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message( await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_with_yaml_config, button.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, button.DOMAIN, DEFAULT_CONFIG
) )
@ -209,14 +211,14 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
): ):
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_blocked_attribute_via_mqtt_json_message( await help_test_setting_blocked_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG_LEGACY, None hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG, None
) )
async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_config): async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_config):
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template( await help_test_setting_attribute_with_template(
hass, mqtt_mock_entry_with_yaml_config, button.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, button.DOMAIN, DEFAULT_CONFIG
) )
@ -229,20 +231,20 @@ async def test_update_with_json_attrs_not_dict(
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
button.DOMAIN, button.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
async def test_update_with_json_attrs_bad_JSON( async def test_update_with_json_attrs_bad_json(
hass, mqtt_mock_entry_with_yaml_config, caplog hass, mqtt_mock_entry_with_yaml_config, caplog
): ):
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_JSON( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
button.DOMAIN, button.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -253,27 +255,27 @@ async def test_discovery_update_attr(hass, mqtt_mock_entry_no_yaml_config, caplo
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
caplog, caplog,
button.DOMAIN, button.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config): async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config):
"""Test unique id option only creates one button per unique_id.""" """Test unique id option only creates one button per unique_id."""
config = { config = {
button.DOMAIN: [ mqtt.DOMAIN: {
{ button.DOMAIN: [
"platform": "mqtt", {
"name": "Test 1", "name": "Test 1",
"command_topic": "command-topic", "command_topic": "command-topic",
"unique_id": "TOTALLY_UNIQUE", "unique_id": "TOTALLY_UNIQUE",
}, },
{ {
"platform": "mqtt", "name": "Test 2",
"name": "Test 2", "command_topic": "command-topic",
"command_topic": "command-topic", "unique_id": "TOTALLY_UNIQUE",
"unique_id": "TOTALLY_UNIQUE", },
}, ]
] }
} }
await help_test_unique_id( await help_test_unique_id(
hass, mqtt_mock_entry_with_yaml_config, button.DOMAIN, config hass, mqtt_mock_entry_with_yaml_config, button.DOMAIN, config
@ -290,8 +292,8 @@ async def test_discovery_removal_button(hass, mqtt_mock_entry_no_yaml_config, ca
async def test_discovery_update_button(hass, mqtt_mock_entry_no_yaml_config, caplog): async def test_discovery_update_button(hass, mqtt_mock_entry_no_yaml_config, caplog):
"""Test update of discovered button.""" """Test update of discovered button."""
config1 = copy.deepcopy(DEFAULT_CONFIG_LEGACY[button.DOMAIN]) config1 = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][button.DOMAIN])
config2 = copy.deepcopy(DEFAULT_CONFIG_LEGACY[button.DOMAIN]) config2 = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][button.DOMAIN])
config1["name"] = "Beer" config1["name"] = "Beer"
config2["name"] = "Milk" config2["name"] = "Milk"
@ -340,35 +342,35 @@ async def test_discovery_broken(hass, mqtt_mock_entry_no_yaml_config, caplog):
async def test_entity_device_info_with_connection(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_with_connection(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT button device registry integration.""" """Test MQTT button device registry integration."""
await help_test_entity_device_info_with_connection( await help_test_entity_device_info_with_connection(
hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_with_identifier(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_with_identifier(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT button device registry integration.""" """Test MQTT button device registry integration."""
await help_test_entity_device_info_with_identifier( await help_test_entity_device_info_with_identifier(
hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_update(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_update(hass, mqtt_mock_entry_no_yaml_config):
"""Test device registry update.""" """Test device registry update."""
await help_test_entity_device_info_update( await help_test_entity_device_info_update(
hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_remove(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_remove(hass, mqtt_mock_entry_no_yaml_config):
"""Test device registry remove.""" """Test device registry remove."""
await help_test_entity_device_info_remove( await help_test_entity_device_info_remove(
hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT discovery update when entity_id is updated.""" """Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update( await help_test_entity_id_update_discovery_update(
hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG
) )
@ -378,7 +380,7 @@ async def test_entity_debug_info_message(hass, mqtt_mock_entry_no_yaml_config):
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
button.DOMAIN, button.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
button.SERVICE_PRESS, button.SERVICE_PRESS,
command_payload="PRESS", command_payload="PRESS",
state_topic=None, state_topic=None,
@ -457,7 +459,7 @@ async def test_publishing_with_custom_encoding(
): ):
"""Test publishing MQTT payload with different encoding.""" """Test publishing MQTT payload with different encoding."""
domain = button.DOMAIN domain = button.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding(
hass, hass,
@ -476,12 +478,14 @@ async def test_publishing_with_custom_encoding(
async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path): async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path):
"""Test reloading the MQTT platform.""" """Test reloading the MQTT platform."""
domain = button.DOMAIN domain = button.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_reloadable( await help_test_reloadable(
hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config
) )
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path): async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup.""" """Test reloading the MQTT platform with late entry setup."""
domain = button.DOMAIN domain = button.DOMAIN
@ -492,17 +496,14 @@ async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
async def test_setup_manual_entity_from_yaml(hass): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = button.DOMAIN platform = button.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[platform]) await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
config["name"] = "test" assert hass.states.get(f"{platform}.test")
del config["platform"]
await help_test_setup_manual_entity_from_yaml(hass, platform, config)
assert hass.states.get(f"{platform}.test") is not None
async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path): async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path):
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = button.DOMAIN domain = button.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_unload_config_entry_with_platform( await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config
) )

View file

@ -37,7 +37,7 @@ from .test_common import (
help_test_setup_manual_entity_from_yaml, 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,
help_test_update_with_json_attrs_not_dict, help_test_update_with_json_attrs_not_dict,
) )
@ -195,28 +195,28 @@ async def test_availability_when_connection_lost(
): ):
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_with_yaml_config, camera.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, camera.DOMAIN, DEFAULT_CONFIG
) )
async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config): async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_with_yaml_config, camera.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, camera.DOMAIN, DEFAULT_CONFIG
) )
async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_config): async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
await help_test_default_availability_payload( await help_test_default_availability_payload(
hass, mqtt_mock_entry_with_yaml_config, camera.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, camera.DOMAIN, DEFAULT_CONFIG
) )
async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_config): async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability by custom payload with defined topic.""" """Test availability by custom payload with defined topic."""
await help_test_custom_availability_payload( await help_test_custom_availability_payload(
hass, mqtt_mock_entry_with_yaml_config, camera.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, camera.DOMAIN, DEFAULT_CONFIG
) )
@ -225,7 +225,7 @@ async def test_setting_attribute_via_mqtt_json_message(
): ):
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message( await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_with_yaml_config, camera.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, camera.DOMAIN, DEFAULT_CONFIG
) )
@ -237,7 +237,7 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
camera.DOMAIN, camera.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
MQTT_CAMERA_ATTRIBUTES_BLOCKED, MQTT_CAMERA_ATTRIBUTES_BLOCKED,
) )
@ -245,7 +245,7 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_config): async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_config):
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template( await help_test_setting_attribute_with_template(
hass, mqtt_mock_entry_with_yaml_config, camera.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, camera.DOMAIN, DEFAULT_CONFIG
) )
@ -258,20 +258,20 @@ async def test_update_with_json_attrs_not_dict(
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
camera.DOMAIN, camera.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
async def test_update_with_json_attrs_bad_JSON( async def test_update_with_json_attrs_bad_json(
hass, mqtt_mock_entry_with_yaml_config, caplog hass, mqtt_mock_entry_with_yaml_config, caplog
): ):
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_JSON( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
camera.DOMAIN, camera.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -282,27 +282,27 @@ async def test_discovery_update_attr(hass, mqtt_mock_entry_no_yaml_config, caplo
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
caplog, caplog,
camera.DOMAIN, camera.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config): async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config):
"""Test unique id option only creates one camera per unique_id.""" """Test unique id option only creates one camera per unique_id."""
config = { config = {
camera.DOMAIN: [ mqtt.DOMAIN: {
{ camera.DOMAIN: [
"platform": "mqtt", {
"name": "Test 1", "name": "Test 1",
"topic": "test-topic", "topic": "test-topic",
"unique_id": "TOTALLY_UNIQUE", "unique_id": "TOTALLY_UNIQUE",
}, },
{ {
"platform": "mqtt", "name": "Test 2",
"name": "Test 2", "topic": "test-topic",
"topic": "test-topic", "unique_id": "TOTALLY_UNIQUE",
"unique_id": "TOTALLY_UNIQUE", },
}, ]
] }
} }
await help_test_unique_id( await help_test_unique_id(
hass, mqtt_mock_entry_with_yaml_config, camera.DOMAIN, config hass, mqtt_mock_entry_with_yaml_config, camera.DOMAIN, config
@ -311,7 +311,7 @@ async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config):
async def test_discovery_removal_camera(hass, mqtt_mock_entry_no_yaml_config, caplog): async def test_discovery_removal_camera(hass, mqtt_mock_entry_no_yaml_config, caplog):
"""Test removal of discovered camera.""" """Test removal of discovered camera."""
data = json.dumps(DEFAULT_CONFIG_LEGACY[camera.DOMAIN]) data = json.dumps(DEFAULT_CONFIG[mqtt.DOMAIN][camera.DOMAIN])
await help_test_discovery_removal( await help_test_discovery_removal(
hass, mqtt_mock_entry_no_yaml_config, caplog, camera.DOMAIN, data hass, mqtt_mock_entry_no_yaml_config, caplog, camera.DOMAIN, data
) )
@ -359,28 +359,28 @@ async def test_discovery_broken(hass, mqtt_mock_entry_no_yaml_config, caplog):
async def test_entity_device_info_with_connection(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_with_connection(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT camera device registry integration.""" """Test MQTT camera device registry integration."""
await help_test_entity_device_info_with_connection( await help_test_entity_device_info_with_connection(
hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_with_identifier(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_with_identifier(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT camera device registry integration.""" """Test MQTT camera device registry integration."""
await help_test_entity_device_info_with_identifier( await help_test_entity_device_info_with_identifier(
hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_update(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_update(hass, mqtt_mock_entry_no_yaml_config):
"""Test device registry update.""" """Test device registry update."""
await help_test_entity_device_info_update( await help_test_entity_device_info_update(
hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_remove(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_remove(hass, mqtt_mock_entry_no_yaml_config):
"""Test device registry remove.""" """Test device registry remove."""
await help_test_entity_device_info_remove( await help_test_entity_device_info_remove(
hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG
) )
@ -390,7 +390,7 @@ async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_co
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
camera.DOMAIN, camera.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
["test_topic"], ["test_topic"],
) )
@ -398,7 +398,7 @@ async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_co
async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT discovery update when entity_id is updated.""" """Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update( await help_test_entity_id_update_discovery_update(
hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG
) )
@ -408,7 +408,7 @@ async def test_entity_debug_info_message(hass, mqtt_mock_entry_no_yaml_config):
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
camera.DOMAIN, camera.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
None, None,
state_topic="test_topic", state_topic="test_topic",
state_payload=b"ON", state_payload=b"ON",
@ -418,12 +418,14 @@ async def test_entity_debug_info_message(hass, mqtt_mock_entry_no_yaml_config):
async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path): async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path):
"""Test reloading the MQTT platform.""" """Test reloading the MQTT platform."""
domain = camera.DOMAIN domain = camera.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_reloadable( await help_test_reloadable(
hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config
) )
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path): async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup.""" """Test reloading the MQTT platform with late entry setup."""
domain = camera.DOMAIN domain = camera.DOMAIN
@ -434,17 +436,14 @@ async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
async def test_setup_manual_entity_from_yaml(hass): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = camera.DOMAIN platform = camera.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[platform]) await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
config["name"] = "test" assert hass.states.get(f"{platform}.test")
del config["platform"]
await help_test_setup_manual_entity_from_yaml(hass, platform, config)
assert hass.states.get(f"{platform}.test") is not None
async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path): async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path):
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = camera.DOMAIN domain = camera.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_unload_config_entry_with_platform( await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config
) )

View file

@ -52,7 +52,7 @@ from .test_common import (
help_test_setup_manual_entity_from_yaml, 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,
help_test_update_with_json_attrs_not_dict, help_test_update_with_json_attrs_not_dict,
) )
@ -686,28 +686,28 @@ async def test_availability_when_connection_lost(
): ):
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_with_yaml_config, climate.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, climate.DOMAIN, DEFAULT_CONFIG
) )
async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config): async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_with_yaml_config, climate.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, climate.DOMAIN, DEFAULT_CONFIG
) )
async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_config): async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
await help_test_default_availability_payload( await help_test_default_availability_payload(
hass, mqtt_mock_entry_with_yaml_config, climate.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, climate.DOMAIN, DEFAULT_CONFIG
) )
async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_config): async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability by custom payload with defined topic.""" """Test availability by custom payload with defined topic."""
await help_test_custom_availability_payload( await help_test_custom_availability_payload(
hass, mqtt_mock_entry_with_yaml_config, climate.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, climate.DOMAIN, DEFAULT_CONFIG
) )
@ -994,7 +994,7 @@ async def test_setting_attribute_via_mqtt_json_message(
): ):
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message( await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_with_yaml_config, climate.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, climate.DOMAIN, DEFAULT_CONFIG
) )
@ -1006,7 +1006,7 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
climate.DOMAIN, climate.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
MQTT_CLIMATE_ATTRIBUTES_BLOCKED, MQTT_CLIMATE_ATTRIBUTES_BLOCKED,
) )
@ -1014,7 +1014,7 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_config): async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_config):
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template( await help_test_setting_attribute_with_template(
hass, mqtt_mock_entry_with_yaml_config, climate.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, climate.DOMAIN, DEFAULT_CONFIG
) )
@ -1027,20 +1027,20 @@ async def test_update_with_json_attrs_not_dict(
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
climate.DOMAIN, climate.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
async def test_update_with_json_attrs_bad_JSON( async def test_update_with_json_attrs_bad_json(
hass, mqtt_mock_entry_with_yaml_config, caplog hass, mqtt_mock_entry_with_yaml_config, caplog
): ):
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_JSON( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
climate.DOMAIN, climate.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -1051,29 +1051,29 @@ async def test_discovery_update_attr(hass, mqtt_mock_entry_no_yaml_config, caplo
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
caplog, caplog,
climate.DOMAIN, climate.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config): async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config):
"""Test unique id option only creates one climate per unique_id.""" """Test unique id option only creates one climate per unique_id."""
config = { config = {
climate.DOMAIN: [ mqtt.DOMAIN: {
{ climate.DOMAIN: [
"platform": "mqtt", {
"name": "Test 1", "name": "Test 1",
"power_state_topic": "test-topic", "power_state_topic": "test-topic",
"power_command_topic": "test_topic", "power_command_topic": "test_topic",
"unique_id": "TOTALLY_UNIQUE", "unique_id": "TOTALLY_UNIQUE",
}, },
{ {
"platform": "mqtt", "name": "Test 2",
"name": "Test 2", "power_state_topic": "test-topic",
"power_state_topic": "test-topic", "power_command_topic": "test_topic",
"power_command_topic": "test_topic", "unique_id": "TOTALLY_UNIQUE",
"unique_id": "TOTALLY_UNIQUE", },
}, ]
] }
} }
await help_test_unique_id( await help_test_unique_id(
hass, mqtt_mock_entry_with_yaml_config, climate.DOMAIN, config hass, mqtt_mock_entry_with_yaml_config, climate.DOMAIN, config
@ -1106,7 +1106,7 @@ async def test_encoding_subscribable_topics(
attribute_value, attribute_value,
): ):
"""Test handling of incoming encoded payload.""" """Test handling of incoming encoded payload."""
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[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_with_yaml_config,
@ -1122,7 +1122,7 @@ async def test_encoding_subscribable_topics(
async def test_discovery_removal_climate(hass, mqtt_mock_entry_no_yaml_config, caplog): async def test_discovery_removal_climate(hass, mqtt_mock_entry_no_yaml_config, caplog):
"""Test removal of discovered climate.""" """Test removal of discovered climate."""
data = json.dumps(DEFAULT_CONFIG_LEGACY[climate.DOMAIN]) data = json.dumps(DEFAULT_CONFIG[mqtt.DOMAIN][climate.DOMAIN])
await help_test_discovery_removal( await help_test_discovery_removal(
hass, mqtt_mock_entry_no_yaml_config, caplog, climate.DOMAIN, data hass, mqtt_mock_entry_no_yaml_config, caplog, climate.DOMAIN, data
) )
@ -1168,39 +1168,40 @@ async def test_discovery_broken(hass, mqtt_mock_entry_no_yaml_config, caplog):
async def test_entity_device_info_with_connection(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_with_connection(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT climate device registry integration.""" """Test MQTT climate device registry integration."""
await help_test_entity_device_info_with_connection( await help_test_entity_device_info_with_connection(
hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_with_identifier(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_with_identifier(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT climate device registry integration.""" """Test MQTT climate device registry integration."""
await help_test_entity_device_info_with_identifier( await help_test_entity_device_info_with_identifier(
hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_update(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_update(hass, mqtt_mock_entry_no_yaml_config):
"""Test device registry update.""" """Test device registry update."""
await help_test_entity_device_info_update( await help_test_entity_device_info_update(
hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_remove(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_remove(hass, mqtt_mock_entry_no_yaml_config):
"""Test device registry remove.""" """Test device registry remove."""
await help_test_entity_device_info_remove( await help_test_entity_device_info_remove(
hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_config): async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_config):
"""Test MQTT subscriptions are managed when entity_id is updated.""" """Test MQTT subscriptions are managed when entity_id is updated."""
config = { config = {
climate.DOMAIN: { mqtt.DOMAIN: {
"platform": "mqtt", climate.DOMAIN: {
"name": "test", "name": "test",
"mode_state_topic": "test-topic", "mode_state_topic": "test-topic",
"availability_topic": "avty-topic", "availability_topic": "avty-topic",
}
} }
} }
await help_test_entity_id_update_subscriptions( await help_test_entity_id_update_subscriptions(
@ -1215,18 +1216,19 @@ async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_co
async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT discovery update when entity_id is updated.""" """Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update( await help_test_entity_id_update_discovery_update(
hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_debug_info_message(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_debug_info_message(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT debug info.""" """Test MQTT debug info."""
config = { config = {
climate.DOMAIN: { mqtt.DOMAIN: {
"platform": "mqtt", climate.DOMAIN: {
"name": "test", "name": "test",
"mode_command_topic": "command-topic", "mode_command_topic": "command-topic",
"mode_state_topic": "test-topic", "mode_state_topic": "test-topic",
}
} }
} }
await help_test_entity_debug_info_message( await help_test_entity_debug_info_message(
@ -1375,10 +1377,10 @@ async def test_publishing_with_custom_encoding(
): ):
"""Test publishing MQTT payload with different encoding.""" """Test publishing MQTT payload with different encoding."""
domain = climate.DOMAIN domain = climate.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[domain]) config = copy.deepcopy(DEFAULT_CONFIG)
if topic != "preset_mode_command_topic": if topic != "preset_mode_command_topic":
del config["preset_mode_command_topic"] del config[mqtt.DOMAIN][domain]["preset_mode_command_topic"]
del config["preset_modes"] del config[mqtt.DOMAIN][domain]["preset_modes"]
await help_test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding(
hass, hass,
@ -1397,12 +1399,14 @@ async def test_publishing_with_custom_encoding(
async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path): async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path):
"""Test reloading the MQTT platform.""" """Test reloading the MQTT platform."""
domain = climate.DOMAIN domain = climate.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_reloadable( await help_test_reloadable(
hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config
) )
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path): async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup.""" """Test reloading the MQTT platform with late entry setup."""
domain = climate.DOMAIN domain = climate.DOMAIN
@ -1413,17 +1417,14 @@ async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
async def test_setup_manual_entity_from_yaml(hass): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = climate.DOMAIN platform = climate.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[platform]) await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
config["name"] = "test" assert hass.states.get(f"{platform}.test")
del config["platform"]
await help_test_setup_manual_entity_from_yaml(hass, platform, config)
assert hass.states.get(f"{platform}.test") is not None
async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path): async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path):
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = climate.DOMAIN domain = climate.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_unload_config_entry_with_platform( await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config
) )

View file

@ -53,7 +53,7 @@ async def help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_with_yaml_config, domain, config hass, mqtt_mock_entry_with_yaml_config, domain, config
): ):
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
assert await async_setup_component(hass, domain, config) assert await async_setup_component(hass, mqtt.DOMAIN, config)
await hass.async_block_till_done() await hass.async_block_till_done()
mqtt_mock = await mqtt_mock_entry_with_yaml_config() mqtt_mock = await mqtt_mock_entry_with_yaml_config()
@ -72,8 +72,8 @@ async def help_test_availability_without_topic(
hass, mqtt_mock_entry_with_yaml_config, domain, config hass, mqtt_mock_entry_with_yaml_config, domain, config
): ):
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
assert "availability_topic" not in config[domain] assert "availability_topic" not in config[mqtt.DOMAIN][domain]
assert await async_setup_component(hass, domain, config) assert await async_setup_component(hass, mqtt.DOMAIN, config)
await hass.async_block_till_done() await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config() await mqtt_mock_entry_with_yaml_config()
@ -96,10 +96,10 @@ async def help_test_default_availability_payload(
""" """
# Add availability settings to config # Add availability settings to config
config = copy.deepcopy(config) config = copy.deepcopy(config)
config[domain]["availability_topic"] = "availability-topic" config[mqtt.DOMAIN][domain]["availability_topic"] = "availability-topic"
assert await async_setup_component( assert await async_setup_component(
hass, hass,
domain, mqtt.DOMAIN,
config, config,
) )
await hass.async_block_till_done() await hass.async_block_till_done()
@ -147,13 +147,13 @@ async def help_test_default_availability_list_payload(
""" """
# Add availability settings to config # Add availability settings to config
config = copy.deepcopy(config) config = copy.deepcopy(config)
config[domain]["availability"] = [ config[mqtt.DOMAIN][domain]["availability"] = [
{"topic": "availability-topic1"}, {"topic": "availability-topic1"},
{"topic": "availability-topic2"}, {"topic": "availability-topic2"},
] ]
assert await async_setup_component( assert await async_setup_component(
hass, hass,
domain, mqtt.DOMAIN,
config, config,
) )
await hass.async_block_till_done() await hass.async_block_till_done()
@ -213,14 +213,14 @@ async def help_test_default_availability_list_payload_all(
""" """
# Add availability settings to config # Add availability settings to config
config = copy.deepcopy(config) config = copy.deepcopy(config)
config[domain]["availability_mode"] = "all" config[mqtt.DOMAIN][domain]["availability_mode"] = "all"
config[domain]["availability"] = [ config[mqtt.DOMAIN][domain]["availability"] = [
{"topic": "availability-topic1"}, {"topic": "availability-topic1"},
{"topic": "availability-topic2"}, {"topic": "availability-topic2"},
] ]
assert await async_setup_component( assert await async_setup_component(
hass, hass,
domain, mqtt.DOMAIN,
config, config,
) )
await hass.async_block_till_done() await hass.async_block_till_done()
@ -281,14 +281,14 @@ async def help_test_default_availability_list_payload_any(
""" """
# Add availability settings to config # Add availability settings to config
config = copy.deepcopy(config) config = copy.deepcopy(config)
config[domain]["availability_mode"] = "any" config[mqtt.DOMAIN][domain]["availability_mode"] = "any"
config[domain]["availability"] = [ config[mqtt.DOMAIN][domain]["availability"] = [
{"topic": "availability-topic1"}, {"topic": "availability-topic1"},
{"topic": "availability-topic2"}, {"topic": "availability-topic2"},
] ]
assert await async_setup_component( assert await async_setup_component(
hass, hass,
domain, mqtt.DOMAIN,
config, config,
) )
await hass.async_block_till_done() await hass.async_block_till_done()
@ -331,7 +331,6 @@ async def help_test_default_availability_list_payload_any(
async def help_test_default_availability_list_single( async def help_test_default_availability_list_single(
hass, hass,
mqtt_mock_entry_with_yaml_config,
caplog, caplog,
domain, domain,
config, config,
@ -345,22 +344,17 @@ async def help_test_default_availability_list_single(
""" """
# Add availability settings to config # Add availability settings to config
config = copy.deepcopy(config) config = copy.deepcopy(config)
config[domain]["availability"] = [ config[mqtt.DOMAIN][domain]["availability"] = [
{"topic": "availability-topic1"}, {"topic": "availability-topic1"},
] ]
config[domain]["availability_topic"] = "availability-topic" config[mqtt.DOMAIN][domain]["availability_topic"] = "availability-topic"
assert await async_setup_component( assert not await async_setup_component(
hass, hass,
domain, mqtt.DOMAIN,
config, config,
) )
await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config()
state = hass.states.get(f"{domain}.test")
assert state is None
assert ( assert (
"Invalid config for [sensor.mqtt]: 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
) )
@ -380,12 +374,12 @@ async def help_test_custom_availability_payload(
""" """
# Add availability settings to config # Add availability settings to config
config = copy.deepcopy(config) config = copy.deepcopy(config)
config[domain]["availability_topic"] = "availability-topic" config[mqtt.DOMAIN][domain]["availability_topic"] = "availability-topic"
config[domain]["payload_available"] = "good" config[mqtt.DOMAIN][domain]["payload_available"] = "good"
config[domain]["payload_not_available"] = "nogood" config[mqtt.DOMAIN][domain]["payload_not_available"] = "nogood"
assert await async_setup_component( assert await async_setup_component(
hass, hass,
domain, mqtt.DOMAIN,
config, config,
) )
await hass.async_block_till_done() await hass.async_block_till_done()
@ -434,17 +428,17 @@ async def help_test_discovery_update_availability(
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry_no_yaml_config()
# Add availability settings to config # Add availability settings to config
config1 = copy.deepcopy(config) config1 = copy.deepcopy(config)
config1[domain]["availability_topic"] = "availability-topic1" config1[mqtt.DOMAIN][domain]["availability_topic"] = "availability-topic1"
config2 = copy.deepcopy(config) config2 = copy.deepcopy(config)
config2[domain]["availability"] = [ config2[mqtt.DOMAIN][domain]["availability"] = [
{"topic": "availability-topic2"}, {"topic": "availability-topic2"},
{"topic": "availability-topic3"}, {"topic": "availability-topic3"},
] ]
config3 = copy.deepcopy(config) config3 = copy.deepcopy(config)
config3[domain]["availability_topic"] = "availability-topic4" config3[mqtt.DOMAIN][domain]["availability_topic"] = "availability-topic4"
data1 = json.dumps(config1[domain]) data1 = json.dumps(config1[mqtt.DOMAIN][domain])
data2 = json.dumps(config2[domain]) data2 = json.dumps(config2[mqtt.DOMAIN][domain])
data3 = json.dumps(config3[domain]) data3 = json.dumps(config3[mqtt.DOMAIN][domain])
async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data1) async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data1)
await hass.async_block_till_done() await hass.async_block_till_done()
@ -508,10 +502,10 @@ async def help_test_setting_attribute_via_mqtt_json_message(
""" """
# Add JSON attributes settings to config # Add JSON attributes settings to config
config = copy.deepcopy(config) config = copy.deepcopy(config)
config[domain]["json_attributes_topic"] = "attr-topic" config[mqtt.DOMAIN][domain]["json_attributes_topic"] = "attr-topic"
assert await async_setup_component( assert await async_setup_component(
hass, hass,
domain, mqtt.DOMAIN,
config, config,
) )
await hass.async_block_till_done() await hass.async_block_till_done()
@ -535,8 +529,8 @@ async def help_test_setting_blocked_attribute_via_mqtt_json_message(
# Add JSON attributes settings to config # Add JSON attributes settings to config
config = copy.deepcopy(config) config = copy.deepcopy(config)
config[domain]["json_attributes_topic"] = "attr-topic" config[mqtt.DOMAIN][domain]["json_attributes_topic"] = "attr-topic"
data = json.dumps(config[domain]) data = json.dumps(config[mqtt.DOMAIN][domain])
async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data) async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data)
await hass.async_block_till_done() await hass.async_block_till_done()
val = "abc123" val = "abc123"
@ -561,11 +555,13 @@ async def help_test_setting_attribute_with_template(
""" """
# Add JSON attributes settings to config # Add JSON attributes settings to config
config = copy.deepcopy(config) config = copy.deepcopy(config)
config[domain]["json_attributes_topic"] = "attr-topic" config[mqtt.DOMAIN][domain]["json_attributes_topic"] = "attr-topic"
config[domain]["json_attributes_template"] = "{{ value_json['Timer1'] | tojson }}" config[mqtt.DOMAIN][domain][
"json_attributes_template"
] = "{{ value_json['Timer1'] | tojson }}"
assert await async_setup_component( assert await async_setup_component(
hass, hass,
domain, mqtt.DOMAIN,
config, config,
) )
await hass.async_block_till_done() await hass.async_block_till_done()
@ -589,10 +585,10 @@ async def help_test_update_with_json_attrs_not_dict(
""" """
# Add JSON attributes settings to config # Add JSON attributes settings to config
config = copy.deepcopy(config) config = copy.deepcopy(config)
config[domain]["json_attributes_topic"] = "attr-topic" config[mqtt.DOMAIN][domain]["json_attributes_topic"] = "attr-topic"
assert await async_setup_component( assert await async_setup_component(
hass, hass,
domain, mqtt.DOMAIN,
config, config,
) )
await hass.async_block_till_done() await hass.async_block_till_done()
@ -605,7 +601,7 @@ async def help_test_update_with_json_attrs_not_dict(
assert "JSON result was not a dictionary" in caplog.text assert "JSON result was not a dictionary" in caplog.text
async def help_test_update_with_json_attrs_bad_JSON( async def help_test_update_with_json_attrs_bad_json(
hass, mqtt_mock_entry_with_yaml_config, caplog, domain, config hass, mqtt_mock_entry_with_yaml_config, caplog, domain, config
): ):
"""Test JSON validation of attributes. """Test JSON validation of attributes.
@ -614,10 +610,10 @@ async def help_test_update_with_json_attrs_bad_JSON(
""" """
# Add JSON attributes settings to config # Add JSON attributes settings to config
config = copy.deepcopy(config) config = copy.deepcopy(config)
config[domain]["json_attributes_topic"] = "attr-topic" config[mqtt.DOMAIN][domain]["json_attributes_topic"] = "attr-topic"
assert await async_setup_component( assert await async_setup_component(
hass, hass,
domain, mqtt.DOMAIN,
config, config,
) )
await hass.async_block_till_done() await hass.async_block_till_done()
@ -640,11 +636,11 @@ async def help_test_discovery_update_attr(
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry_no_yaml_config()
# Add JSON attributes settings to config # Add JSON attributes settings to config
config1 = copy.deepcopy(config) config1 = copy.deepcopy(config)
config1[domain]["json_attributes_topic"] = "attr-topic1" config1[mqtt.DOMAIN][domain]["json_attributes_topic"] = "attr-topic1"
config2 = copy.deepcopy(config) config2 = copy.deepcopy(config)
config2[domain]["json_attributes_topic"] = "attr-topic2" config2[mqtt.DOMAIN][domain]["json_attributes_topic"] = "attr-topic2"
data1 = json.dumps(config1[domain]) data1 = json.dumps(config1[mqtt.DOMAIN][domain])
data2 = json.dumps(config2[domain]) data2 = json.dumps(config2[mqtt.DOMAIN][domain])
async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data1) async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data1)
await hass.async_block_till_done() await hass.async_block_till_done()
@ -669,7 +665,7 @@ async def help_test_discovery_update_attr(
async def help_test_unique_id(hass, mqtt_mock_entry_with_yaml_config, domain, config): async def help_test_unique_id(hass, mqtt_mock_entry_with_yaml_config, domain, config):
"""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, domain, config) assert await async_setup_component(hass, mqtt.DOMAIN, config)
await hass.async_block_till_done() await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config() 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
@ -881,7 +877,7 @@ async def help_test_encoding_subscribable_topics(
await hass.async_block_till_done() await hass.async_block_till_done()
assert await async_setup_component( assert await async_setup_component(
hass, domain, {domain: [config1, config2, config3]} hass, mqtt.DOMAIN, {mqtt.DOMAIN: {domain: [config1, config2, config3]}}
) )
await hass.async_block_till_done() await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config() await mqtt_mock_entry_with_yaml_config()
@ -944,7 +940,7 @@ async def help_test_entity_device_info_with_identifier(
""" """
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry_no_yaml_config()
# Add device settings to config # Add device settings to config
config = copy.deepcopy(config[domain]) config = copy.deepcopy(config[mqtt.DOMAIN][domain])
config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID) config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID)
config["unique_id"] = "veryunique" config["unique_id"] = "veryunique"
@ -975,7 +971,7 @@ async def help_test_entity_device_info_with_connection(
""" """
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry_no_yaml_config()
# Add device settings to config # Add device settings to config
config = copy.deepcopy(config[domain]) config = copy.deepcopy(config[mqtt.DOMAIN][domain])
config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_MAC) config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_MAC)
config["unique_id"] = "veryunique" config["unique_id"] = "veryunique"
@ -1005,7 +1001,7 @@ async def help_test_entity_device_info_remove(
"""Test device registry remove.""" """Test device registry remove."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry_no_yaml_config()
# Add device settings to config # Add device settings to config
config = copy.deepcopy(config[domain]) config = copy.deepcopy(config[mqtt.DOMAIN][domain])
config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID) config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID)
config["unique_id"] = "veryunique" config["unique_id"] = "veryunique"
@ -1037,7 +1033,7 @@ async def help_test_entity_device_info_update(
""" """
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry_no_yaml_config()
# Add device settings to config # Add device settings to config
config = copy.deepcopy(config[domain]) config = copy.deepcopy(config[mqtt.DOMAIN][domain])
config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID) config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID)
config["unique_id"] = "veryunique" config["unique_id"] = "veryunique"
@ -1067,19 +1063,19 @@ async def help_test_entity_id_update_subscriptions(
"""Test MQTT subscriptions are managed when entity_id is updated.""" """Test MQTT subscriptions are managed when entity_id is updated."""
# Add unique_id to config # Add unique_id to config
config = copy.deepcopy(config) config = copy.deepcopy(config)
config[domain]["unique_id"] = "TOTALLY_UNIQUE" config[mqtt.DOMAIN][domain]["unique_id"] = "TOTALLY_UNIQUE"
if topics is None: if topics is None:
# Add default topics to config # Add default topics to config
config[domain]["availability_topic"] = "avty-topic" config[mqtt.DOMAIN][domain]["availability_topic"] = "avty-topic"
config[domain]["state_topic"] = "test-topic" config[mqtt.DOMAIN][domain]["state_topic"] = "test-topic"
topics = ["avty-topic", "test-topic"] topics = ["avty-topic", "test-topic"]
assert len(topics) > 0 assert len(topics) > 0
registry = mock_registry(hass, {}) registry = mock_registry(hass, {})
assert await async_setup_component( assert await async_setup_component(
hass, hass,
domain, mqtt.DOMAIN,
config, config,
) )
await hass.async_block_till_done() await hass.async_block_till_done()
@ -1111,16 +1107,16 @@ async def help_test_entity_id_update_discovery_update(
# Add unique_id to config # Add unique_id to config
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry_no_yaml_config()
config = copy.deepcopy(config) config = copy.deepcopy(config)
config[domain]["unique_id"] = "TOTALLY_UNIQUE" config[mqtt.DOMAIN][domain]["unique_id"] = "TOTALLY_UNIQUE"
if topic is None: if topic is None:
# Add default topic to config # Add default topic to config
config[domain]["availability_topic"] = "avty-topic" config[mqtt.DOMAIN][domain]["availability_topic"] = "avty-topic"
topic = "avty-topic" topic = "avty-topic"
ent_registry = mock_registry(hass, {}) ent_registry = mock_registry(hass, {})
data = json.dumps(config[domain]) data = json.dumps(config[mqtt.DOMAIN][domain])
async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data) async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data)
await hass.async_block_till_done() await hass.async_block_till_done()
@ -1135,8 +1131,8 @@ async def help_test_entity_id_update_discovery_update(
ent_registry.async_update_entity(f"{domain}.test", new_entity_id=f"{domain}.milk") ent_registry.async_update_entity(f"{domain}.test", new_entity_id=f"{domain}.milk")
await hass.async_block_till_done() await hass.async_block_till_done()
config[domain]["availability_topic"] = f"{topic}_2" config[mqtt.DOMAIN][domain]["availability_topic"] = f"{topic}_2"
data = json.dumps(config[domain]) data = json.dumps(config[mqtt.DOMAIN][domain])
async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data) async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data)
await hass.async_block_till_done() await hass.async_block_till_done()
assert len(hass.states.async_entity_ids(domain)) == 1 assert len(hass.states.async_entity_ids(domain)) == 1
@ -1155,9 +1151,10 @@ async def help_test_entity_debug_info(
""" """
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry_no_yaml_config()
# Add device settings to config # Add device settings to config
config = copy.deepcopy(config[domain]) config = copy.deepcopy(config[mqtt.DOMAIN][domain])
config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID) config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID)
config["unique_id"] = "veryunique" config["unique_id"] = "veryunique"
config["platform"] = "mqtt"
registry = dr.async_get(hass) registry = dr.async_get(hass)
@ -1192,7 +1189,7 @@ async def help_test_entity_debug_info_max_messages(
""" """
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry_no_yaml_config()
# Add device settings to config # Add device settings to config
config = copy.deepcopy(config[domain]) config = copy.deepcopy(config[mqtt.DOMAIN][domain])
config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID) config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID)
config["unique_id"] = "veryunique" config["unique_id"] = "veryunique"
@ -1256,7 +1253,7 @@ async def help_test_entity_debug_info_message(
""" """
# Add device settings to config # Add device settings to config
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry_no_yaml_config()
config = copy.deepcopy(config[domain]) config = copy.deepcopy(config[mqtt.DOMAIN][domain])
config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID) config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID)
config["unique_id"] = "veryunique" config["unique_id"] = "veryunique"
@ -1359,9 +1356,10 @@ async def help_test_entity_debug_info_remove(
""" """
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry_no_yaml_config()
# Add device settings to config # Add device settings to config
config = copy.deepcopy(config[domain]) config = copy.deepcopy(config[mqtt.DOMAIN][domain])
config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID) config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID)
config["unique_id"] = "veryunique" config["unique_id"] = "veryunique"
config["platform"] = "mqtt"
registry = dr.async_get(hass) registry = dr.async_get(hass)
@ -1405,9 +1403,10 @@ async def help_test_entity_debug_info_update_entity_id(
""" """
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry_no_yaml_config()
# Add device settings to config # Add device settings to config
config = copy.deepcopy(config[domain]) config = copy.deepcopy(config[mqtt.DOMAIN][domain])
config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID) config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID)
config["unique_id"] = "veryunique" config["unique_id"] = "veryunique"
config["platform"] = "mqtt"
dev_registry = dr.async_get(hass) dev_registry = dr.async_get(hass)
ent_registry = mock_registry(hass, {}) ent_registry = mock_registry(hass, {})
@ -1461,7 +1460,7 @@ async def help_test_entity_disabled_by_default(
"""Test device registry remove.""" """Test device registry remove."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry_no_yaml_config()
# Add device settings to config # Add device settings to config
config = copy.deepcopy(config[domain]) config = copy.deepcopy(config[mqtt.DOMAIN][domain])
config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID) config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID)
config["enabled_by_default"] = False config["enabled_by_default"] = False
config["unique_id"] = "veryunique1" config["unique_id"] = "veryunique1"
@ -1500,7 +1499,7 @@ async def help_test_entity_category(
"""Test device registry remove.""" """Test device registry remove."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry_no_yaml_config()
# Add device settings to config # Add device settings to config
config = copy.deepcopy(config[domain]) config = copy.deepcopy(config[mqtt.DOMAIN][domain])
config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID) config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID)
ent_registry = er.async_get(hass) ent_registry = er.async_get(hass)
@ -1564,7 +1563,7 @@ async def help_test_publishing_with_custom_encoding(
setup_config = [] setup_config = []
service_data = {} service_data = {}
for test_id, test_data in test_config.items(): for test_id, test_data in test_config.items():
test_config_setup = copy.deepcopy(config) test_config_setup = copy.deepcopy(config[mqtt.DOMAIN][domain])
test_config_setup.update( test_config_setup.update(
{ {
topic: f"cmd/{test_id}", topic: f"cmd/{test_id}",
@ -1573,7 +1572,7 @@ async def help_test_publishing_with_custom_encoding(
) )
if test_data["encoding"] is not None: if test_data["encoding"] is not None:
test_config_setup["encoding"] = test_data["encoding"] test_config_setup["encoding"] = test_data["encoding"]
if test_data["cmd_tpl"]: if template and test_data["cmd_tpl"]:
test_config_setup[ test_config_setup[
template template
] = f"{{{{ (('%.1f'|format({tpl_par}))[0] if is_number({tpl_par}) else {tpl_par}[0]) | ord | pack('b') }}}}" ] = f"{{{{ (('%.1f'|format({tpl_par}))[0] if is_number({tpl_par}) else {tpl_par}[0]) | ord | pack('b') }}}}"
@ -1587,8 +1586,8 @@ async def help_test_publishing_with_custom_encoding(
# setup test entities # setup test entities
assert await async_setup_component( assert await async_setup_component(
hass, hass,
domain, mqtt.DOMAIN,
{domain: setup_config}, {mqtt.DOMAIN: {domain: setup_config}},
) )
await hass.async_block_till_done() await hass.async_block_till_done()
mqtt_mock = await mqtt_mock_entry_with_yaml_config() mqtt_mock = await mqtt_mock_entry_with_yaml_config()
@ -1698,24 +1697,29 @@ async def help_test_reloadable(
hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config
): ):
"""Test reloading an MQTT platform.""" """Test reloading an MQTT platform."""
config = copy.deepcopy(config[mqtt.DOMAIN][domain])
# Create and test an old config of 2 entities based on the config supplied # Create and test an old config of 2 entities based on the config supplied
old_config_1 = copy.deepcopy(config) old_config_1 = copy.deepcopy(config)
old_config_1["name"] = "test_old_1" old_config_1["name"] = "test_old_1"
old_config_2 = copy.deepcopy(config) old_config_2 = copy.deepcopy(config)
old_config_2["name"] = "test_old_2" old_config_2["name"] = "test_old_2"
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
old_config_3 = copy.deepcopy(config) old_config_3 = copy.deepcopy(config)
old_config_3["name"] = "test_old_3" old_config_3["name"] = "test_old_3"
old_config_3.pop("platform") old_config_3["platform"] = mqtt.DOMAIN
old_config_4 = copy.deepcopy(config) old_config_4 = copy.deepcopy(config)
old_config_4["name"] = "test_old_4" old_config_4["name"] = "test_old_4"
old_config_4.pop("platform") old_config_4["platform"] = mqtt.DOMAIN
old_config = { old_config = {
domain: [old_config_1, old_config_2], mqtt.DOMAIN: {domain: [old_config_1, old_config_2]},
"mqtt": {domain: [old_config_3, old_config_4]}, domain: [old_config_3, old_config_4],
} }
assert await async_setup_component(hass, domain, old_config) assert await async_setup_component(hass, domain, old_config)
assert await async_setup_component(hass, mqtt.DOMAIN, old_config)
await hass.async_block_till_done() await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config() await mqtt_mock_entry_with_yaml_config()
@ -1731,21 +1735,24 @@ async def help_test_reloadable(
new_config_1["name"] = "test_new_1" new_config_1["name"] = "test_new_1"
new_config_2 = copy.deepcopy(config) new_config_2 = copy.deepcopy(config)
new_config_2["name"] = "test_new_2" new_config_2["name"] = "test_new_2"
new_config_extra = copy.deepcopy(config)
new_config_extra["name"] = "test_new_5"
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
new_config_3 = copy.deepcopy(config) new_config_3 = copy.deepcopy(config)
new_config_3["name"] = "test_new_3" new_config_3["name"] = "test_new_3"
new_config_3.pop("platform") new_config_3["platform"] = mqtt.DOMAIN
new_config_4 = copy.deepcopy(config) new_config_4 = copy.deepcopy(config)
new_config_4["name"] = "test_new_4" new_config_4["name"] = "test_new_4"
new_config_4.pop("platform") new_config_4["platform"] = mqtt.DOMAIN
new_config_5 = copy.deepcopy(config) new_config_extra_legacy = copy.deepcopy(config)
new_config_5["name"] = "test_new_5" new_config_extra_legacy["name"] = "test_new_6"
new_config_6 = copy.deepcopy(config) new_config_extra_legacy["platform"] = mqtt.DOMAIN
new_config_6["name"] = "test_new_6"
new_config_6.pop("platform")
new_config = { new_config = {
domain: [new_config_1, new_config_2, new_config_5], mqtt.DOMAIN: {domain: [new_config_1, new_config_2, new_config_extra]},
"mqtt": {domain: [new_config_3, new_config_4, new_config_6]}, domain: [new_config_3, new_config_4, new_config_extra_legacy],
} }
await help_test_reload_with_config(hass, caplog, tmp_path, new_config) await help_test_reload_with_config(hass, caplog, tmp_path, new_config)
@ -1760,9 +1767,12 @@ async def help_test_reloadable(
assert hass.states.get(f"{domain}.test_new_6") assert hass.states.get(f"{domain}.test_new_6")
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def help_test_reloadable_late(hass, caplog, tmp_path, domain, config): async def help_test_reloadable_late(hass, caplog, tmp_path, domain, config):
"""Test reloading an MQTT platform when config entry is setup late.""" """Test reloading an MQTT platform when config entry is setup is late."""
# Create and test an old config of 2 entities based on the config supplied # Create and test an old config of 2 entities based on the config supplied
# using the deprecated platform schema
old_config_1 = copy.deepcopy(config) old_config_1 = copy.deepcopy(config)
old_config_1["name"] = "test_old_1" old_config_1["name"] = "test_old_1"
old_config_2 = copy.deepcopy(config) old_config_2 = copy.deepcopy(config)
@ -1815,7 +1825,7 @@ async def help_test_reloadable_late(hass, caplog, tmp_path, domain, config):
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, platform, config): async def help_test_setup_manual_entity_from_yaml(hass, config):
"""Help to test setup from yaml through configuration entry.""" """Help to test setup from yaml through configuration entry."""
calls = MagicMock() calls = MagicMock()
@ -1823,9 +1833,7 @@ async def help_test_setup_manual_entity_from_yaml(hass, platform, config):
"""Mock reload.""" """Mock reload."""
calls() calls()
config_structure = {mqtt.DOMAIN: {platform: config}} assert await async_setup_component(hass, mqtt.DOMAIN, config)
await async_setup_component(hass, mqtt.DOMAIN, config_structure)
# Mock config entry # Mock config entry
entry = MockConfigEntry(domain=mqtt.DOMAIN, data={mqtt.CONF_BROKER: "test-broker"}) entry = MockConfigEntry(domain=mqtt.DOMAIN, data={mqtt.CONF_BROKER: "test-broker"})
entry.add_to_hass(hass) entry.add_to_hass(hass)
@ -1864,14 +1872,14 @@ async def help_test_unload_config_entry_with_platform(
"""Test unloading the MQTT config entry with a specific platform domain.""" """Test unloading the MQTT config entry with a specific platform domain."""
# prepare setup through configuration.yaml # prepare setup through configuration.yaml
config_setup = copy.deepcopy(config) config_setup = copy.deepcopy(config)
config_setup["name"] = "config_setup" config_setup[mqtt.DOMAIN][domain]["name"] = "config_setup"
config_name = config_setup config_name = config_setup
assert await async_setup_component(hass, domain, {domain: [config_setup]}) assert await async_setup_component(hass, mqtt.DOMAIN, config_setup)
await hass.async_block_till_done() await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config() await mqtt_mock_entry_with_yaml_config()
# prepare setup through discovery # prepare setup through discovery
discovery_setup = copy.deepcopy(config) discovery_setup = copy.deepcopy(config[mqtt.DOMAIN][domain])
discovery_setup["name"] = "discovery_setup" discovery_setup["name"] = "discovery_setup"
async_fire_mqtt_message( async_fire_mqtt_message(
hass, f"homeassistant/{domain}/bla/config", json.dumps(discovery_setup) hass, f"homeassistant/{domain}/bla/config", json.dumps(discovery_setup)

View file

@ -74,7 +74,7 @@ from .test_common import (
help_test_setup_manual_entity_from_yaml, 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,
help_test_update_with_json_attrs_not_dict, help_test_update_with_json_attrs_not_dict,
) )
@ -2444,28 +2444,28 @@ async def test_availability_when_connection_lost(
): ):
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_with_yaml_config, cover.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, cover.DOMAIN, DEFAULT_CONFIG
) )
async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config): async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_with_yaml_config, cover.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, cover.DOMAIN, DEFAULT_CONFIG
) )
async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_config): async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
await help_test_default_availability_payload( await help_test_default_availability_payload(
hass, mqtt_mock_entry_with_yaml_config, cover.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, cover.DOMAIN, DEFAULT_CONFIG
) )
async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_config): async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability by custom payload with defined topic.""" """Test availability by custom payload with defined topic."""
await help_test_custom_availability_payload( await help_test_custom_availability_payload(
hass, mqtt_mock_entry_with_yaml_config, cover.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, cover.DOMAIN, DEFAULT_CONFIG
) )
@ -2514,7 +2514,7 @@ async def test_setting_attribute_via_mqtt_json_message(
): ):
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message( await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_with_yaml_config, cover.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, cover.DOMAIN, DEFAULT_CONFIG
) )
@ -2526,7 +2526,7 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
cover.DOMAIN, cover.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
MQTT_COVER_ATTRIBUTES_BLOCKED, MQTT_COVER_ATTRIBUTES_BLOCKED,
) )
@ -2534,7 +2534,7 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_config): async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_config):
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template( await help_test_setting_attribute_with_template(
hass, mqtt_mock_entry_with_yaml_config, cover.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, cover.DOMAIN, DEFAULT_CONFIG
) )
@ -2547,7 +2547,7 @@ async def test_update_with_json_attrs_not_dict(
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
cover.DOMAIN, cover.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -2555,12 +2555,12 @@ async def test_update_with_json_attrs_bad_json(
hass, mqtt_mock_entry_with_yaml_config, caplog hass, mqtt_mock_entry_with_yaml_config, caplog
): ):
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_JSON( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
cover.DOMAIN, cover.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -2571,27 +2571,27 @@ async def test_discovery_update_attr(hass, mqtt_mock_entry_no_yaml_config, caplo
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
caplog, caplog,
cover.DOMAIN, cover.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config): async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config):
"""Test unique_id option only creates one cover per id.""" """Test unique_id option only creates one cover per id."""
config = { config = {
cover.DOMAIN: [ mqtt.DOMAIN: {
{ cover.DOMAIN: [
"platform": "mqtt", {
"name": "Test 1", "name": "Test 1",
"state_topic": "test-topic", "state_topic": "test-topic",
"unique_id": "TOTALLY_UNIQUE", "unique_id": "TOTALLY_UNIQUE",
}, },
{ {
"platform": "mqtt", "name": "Test 2",
"name": "Test 2", "state_topic": "test-topic",
"state_topic": "test-topic", "unique_id": "TOTALLY_UNIQUE",
"unique_id": "TOTALLY_UNIQUE", },
}, ]
] }
} }
await help_test_unique_id( await help_test_unique_id(
hass, mqtt_mock_entry_with_yaml_config, cover.DOMAIN, config hass, mqtt_mock_entry_with_yaml_config, cover.DOMAIN, config
@ -2646,42 +2646,42 @@ async def test_discovery_broken(hass, mqtt_mock_entry_no_yaml_config, caplog):
async def test_entity_device_info_with_connection(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_with_connection(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT cover device registry integration.""" """Test MQTT cover device registry integration."""
await help_test_entity_device_info_with_connection( await help_test_entity_device_info_with_connection(
hass, mqtt_mock_entry_no_yaml_config, cover.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, cover.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_with_identifier(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_with_identifier(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT cover device registry integration.""" """Test MQTT cover device registry integration."""
await help_test_entity_device_info_with_identifier( await help_test_entity_device_info_with_identifier(
hass, mqtt_mock_entry_no_yaml_config, cover.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, cover.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_update(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_update(hass, mqtt_mock_entry_no_yaml_config):
"""Test device registry update.""" """Test device registry update."""
await help_test_entity_device_info_update( await help_test_entity_device_info_update(
hass, mqtt_mock_entry_no_yaml_config, cover.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, cover.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_remove(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_remove(hass, mqtt_mock_entry_no_yaml_config):
"""Test device registry remove.""" """Test device registry remove."""
await help_test_entity_device_info_remove( await help_test_entity_device_info_remove(
hass, mqtt_mock_entry_no_yaml_config, cover.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, cover.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_config): async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_config):
"""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_LEGACY hass, mqtt_mock_entry_with_yaml_config, cover.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT discovery update when entity_id is updated.""" """Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update( await help_test_entity_id_update_discovery_update(
hass, mqtt_mock_entry_no_yaml_config, cover.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, cover.DOMAIN, DEFAULT_CONFIG
) )
@ -2691,7 +2691,7 @@ async def test_entity_debug_info_message(hass, mqtt_mock_entry_no_yaml_config):
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
cover.DOMAIN, cover.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
SERVICE_OPEN_COVER, SERVICE_OPEN_COVER,
command_payload="OPEN", command_payload="OPEN",
) )
@ -3342,8 +3342,8 @@ async def test_publishing_with_custom_encoding(
): ):
"""Test publishing MQTT payload with different encoding.""" """Test publishing MQTT payload with different encoding."""
domain = cover.DOMAIN domain = cover.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
config["position_topic"] = "some-position-topic" config[mqtt.DOMAIN][domain]["position_topic"] = "some-position-topic"
await help_test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding(
hass, hass,
@ -3362,12 +3362,14 @@ async def test_publishing_with_custom_encoding(
async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path): async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path):
"""Test reloading the MQTT platform.""" """Test reloading the MQTT platform."""
domain = cover.DOMAIN domain = cover.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_reloadable( await help_test_reloadable(
hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config
) )
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path): async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup.""" """Test reloading the MQTT platform with late entry setup."""
domain = cover.DOMAIN domain = cover.DOMAIN
@ -3399,7 +3401,7 @@ async def test_encoding_subscribable_topics(
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
cover.DOMAIN, cover.DOMAIN,
DEFAULT_CONFIG_LEGACY[cover.DOMAIN], DEFAULT_CONFIG[mqtt.DOMAIN][cover.DOMAIN],
topic, topic,
value, value,
attribute, attribute,
@ -3411,17 +3413,14 @@ async def test_encoding_subscribable_topics(
async def test_setup_manual_entity_from_yaml(hass): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = cover.DOMAIN platform = cover.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[platform]) await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
config["name"] = "test" assert hass.states.get(f"{platform}.test")
del config["platform"]
await help_test_setup_manual_entity_from_yaml(hass, platform, config)
assert hass.states.get(f"{platform}.test") is not None
async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path): async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path):
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = cover.DOMAIN domain = cover.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_unload_config_entry_with_platform( await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config
) )

View file

@ -1,6 +1,5 @@
"""The tests for the MQTT device_tracker platform.""" """The tests for the MQTT device_tracker platform."""
import copy
from unittest.mock import patch from unittest.mock import patch
import pytest import pytest
@ -27,11 +26,6 @@ DEFAULT_CONFIG = {
} }
} }
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
DEFAULT_CONFIG_LEGACY = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
DEFAULT_CONFIG_LEGACY[device_tracker.DOMAIN]["platform"] = mqtt.DOMAIN
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def device_tracker_platform_only(): def device_tracker_platform_only():
@ -440,7 +434,7 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
device_tracker.DOMAIN, device_tracker.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
None, None,
) )
@ -451,8 +445,10 @@ async def test_setup_with_modern_schema(hass, mock_device_tracker_conf):
entity_id = f"{device_tracker.DOMAIN}.{dev_id}" entity_id = f"{device_tracker.DOMAIN}.{dev_id}"
topic = "/location/jan" topic = "/location/jan"
config = {"name": dev_id, "state_topic": topic} config = {
mqtt.DOMAIN: {device_tracker.DOMAIN: {"name": dev_id, "state_topic": topic}}
}
await help_test_setup_manual_entity_from_yaml(hass, device_tracker.DOMAIN, config) 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

View file

@ -59,7 +59,7 @@ from .test_common import (
help_test_setup_manual_entity_from_yaml, 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,
help_test_update_with_json_attrs_not_dict, help_test_update_with_json_attrs_not_dict,
) )
@ -1365,7 +1365,7 @@ async def test_encoding_subscribable_topics(
attribute_value, attribute_value,
): ):
"""Test handling of incoming encoded payload.""" """Test handling of incoming encoded payload."""
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[fan.DOMAIN]) config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][fan.DOMAIN])
config[ATTR_PRESET_MODES] = ["eco", "auto"] config[ATTR_PRESET_MODES] = ["eco", "auto"]
config[CONF_PRESET_MODE_COMMAND_TOPIC] = "fan/some_preset_mode_command_topic" config[CONF_PRESET_MODE_COMMAND_TOPIC] = "fan/some_preset_mode_command_topic"
config[CONF_PERCENTAGE_COMMAND_TOPIC] = "fan/some_percentage_command_topic" config[CONF_PERCENTAGE_COMMAND_TOPIC] = "fan/some_percentage_command_topic"
@ -1639,14 +1639,14 @@ async def test_availability_when_connection_lost(
): ):
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_with_yaml_config, fan.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, fan.DOMAIN, DEFAULT_CONFIG
) )
async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config): async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_with_yaml_config, fan.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, fan.DOMAIN, DEFAULT_CONFIG
) )
@ -1656,7 +1656,7 @@ async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_conf
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
fan.DOMAIN, fan.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
True, True,
"state-topic", "state-topic",
"1", "1",
@ -1669,7 +1669,7 @@ async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_confi
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
fan.DOMAIN, fan.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
True, True,
"state-topic", "state-topic",
"1", "1",
@ -1681,7 +1681,7 @@ async def test_setting_attribute_via_mqtt_json_message(
): ):
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message( await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_with_yaml_config, fan.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, fan.DOMAIN, DEFAULT_CONFIG
) )
@ -1693,7 +1693,7 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
fan.DOMAIN, fan.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
MQTT_FAN_ATTRIBUTES_BLOCKED, MQTT_FAN_ATTRIBUTES_BLOCKED,
) )
@ -1701,7 +1701,7 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_config): async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_config):
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template( await help_test_setting_attribute_with_template(
hass, mqtt_mock_entry_with_yaml_config, fan.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, fan.DOMAIN, DEFAULT_CONFIG
) )
@ -1714,7 +1714,7 @@ async def test_update_with_json_attrs_not_dict(
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
fan.DOMAIN, fan.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -1722,41 +1722,41 @@ async def test_update_with_json_attrs_bad_json(
hass, mqtt_mock_entry_with_yaml_config, caplog hass, mqtt_mock_entry_with_yaml_config, caplog
): ):
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_JSON( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
fan.DOMAIN, fan.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
async def test_discovery_update_attr(hass, mqtt_mock_entry_no_yaml_config, caplog): async def test_discovery_update_attr(hass, mqtt_mock_entry_no_yaml_config, caplog):
"""Test update of discovered MQTTAttributes.""" """Test update of discovered MQTTAttributes."""
await help_test_discovery_update_attr( await help_test_discovery_update_attr(
hass, mqtt_mock_entry_no_yaml_config, caplog, fan.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, caplog, fan.DOMAIN, DEFAULT_CONFIG
) )
async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config): async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config):
"""Test unique_id option only creates one fan per id.""" """Test unique_id option only creates one fan per id."""
config = { config = {
fan.DOMAIN: [ mqtt.DOMAIN: {
{ fan.DOMAIN: [
"platform": "mqtt", {
"name": "Test 1", "name": "Test 1",
"state_topic": "test-topic", "state_topic": "test-topic",
"command_topic": "test_topic", "command_topic": "test_topic",
"unique_id": "TOTALLY_UNIQUE", "unique_id": "TOTALLY_UNIQUE",
}, },
{ {
"platform": "mqtt", "name": "Test 2",
"name": "Test 2", "state_topic": "test-topic",
"state_topic": "test-topic", "command_topic": "test_topic",
"command_topic": "test_topic", "unique_id": "TOTALLY_UNIQUE",
"unique_id": "TOTALLY_UNIQUE", },
}, ]
] }
} }
await help_test_unique_id( await help_test_unique_id(
hass, mqtt_mock_entry_with_yaml_config, fan.DOMAIN, config hass, mqtt_mock_entry_with_yaml_config, fan.DOMAIN, config
@ -1812,42 +1812,42 @@ async def test_discovery_broken(hass, mqtt_mock_entry_no_yaml_config, caplog):
async def test_entity_device_info_with_connection(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_with_connection(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT fan device registry integration.""" """Test MQTT fan device registry integration."""
await help_test_entity_device_info_with_connection( await help_test_entity_device_info_with_connection(
hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_with_identifier(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_with_identifier(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT fan device registry integration.""" """Test MQTT fan device registry integration."""
await help_test_entity_device_info_with_identifier( await help_test_entity_device_info_with_identifier(
hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_update(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_update(hass, mqtt_mock_entry_no_yaml_config):
"""Test device registry update.""" """Test device registry update."""
await help_test_entity_device_info_update( await help_test_entity_device_info_update(
hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_remove(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_remove(hass, mqtt_mock_entry_no_yaml_config):
"""Test device registry remove.""" """Test device registry remove."""
await help_test_entity_device_info_remove( await help_test_entity_device_info_remove(
hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_config): async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_config):
"""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_LEGACY hass, mqtt_mock_entry_with_yaml_config, fan.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT discovery update when entity_id is updated.""" """Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update( await help_test_entity_id_update_discovery_update(
hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG
) )
@ -1857,7 +1857,7 @@ async def test_entity_debug_info_message(hass, mqtt_mock_entry_no_yaml_config):
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
fan.DOMAIN, fan.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
fan.SERVICE_TURN_ON, fan.SERVICE_TURN_ON,
) )
@ -1914,9 +1914,9 @@ async def test_publishing_with_custom_encoding(
): ):
"""Test publishing MQTT payload with different encoding.""" """Test publishing MQTT payload with different encoding."""
domain = fan.DOMAIN domain = fan.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[domain]) config = copy.deepcopy(DEFAULT_CONFIG)
if topic == "preset_mode_command_topic": if topic == "preset_mode_command_topic":
config["preset_modes"] = ["auto", "eco"] config[mqtt.DOMAIN][domain]["preset_modes"] = ["auto", "eco"]
await help_test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding(
hass, hass,
@ -1935,12 +1935,14 @@ async def test_publishing_with_custom_encoding(
async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path): async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path):
"""Test reloading the MQTT platform.""" """Test reloading the MQTT platform."""
domain = fan.DOMAIN domain = fan.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_reloadable( await help_test_reloadable(
hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config
) )
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path): async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup.""" """Test reloading the MQTT platform with late entry setup."""
domain = fan.DOMAIN domain = fan.DOMAIN
@ -1951,17 +1953,14 @@ async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
async def test_setup_manual_entity_from_yaml(hass): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = fan.DOMAIN platform = fan.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[platform]) await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
config["name"] = "test" assert hass.states.get(f"{platform}.test")
del config["platform"]
await help_test_setup_manual_entity_from_yaml(hass, platform, config)
assert hass.states.get(f"{platform}.test") is not None
async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path): async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path):
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = fan.DOMAIN domain = fan.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_unload_config_entry_with_platform( await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config
) )

View file

@ -61,7 +61,7 @@ from .test_common import (
help_test_setup_manual_entity_from_yaml, 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,
help_test_update_with_json_attrs_not_dict, help_test_update_with_json_attrs_not_dict,
) )
@ -750,7 +750,7 @@ async def test_encoding_subscribable_topics(
attribute_value, attribute_value,
): ):
"""Test handling of incoming encoded payload.""" """Test handling of incoming encoded payload."""
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[humidifier.DOMAIN]) config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][humidifier.DOMAIN])
config["modes"] = ["eco", "auto"] config["modes"] = ["eco", "auto"]
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(
@ -996,14 +996,14 @@ async def test_availability_when_connection_lost(
): ):
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_with_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG
) )
async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config): async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_with_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG
) )
@ -1013,7 +1013,7 @@ async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_conf
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
humidifier.DOMAIN, humidifier.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
True, True,
"state-topic", "state-topic",
"1", "1",
@ -1026,7 +1026,7 @@ async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_confi
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
humidifier.DOMAIN, humidifier.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
True, True,
"state-topic", "state-topic",
"1", "1",
@ -1038,7 +1038,7 @@ async def test_setting_attribute_via_mqtt_json_message(
): ):
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message( await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_with_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG
) )
@ -1050,7 +1050,7 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
humidifier.DOMAIN, humidifier.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
MQTT_HUMIDIFIER_ATTRIBUTES_BLOCKED, MQTT_HUMIDIFIER_ATTRIBUTES_BLOCKED,
) )
@ -1058,7 +1058,7 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_config): async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_config):
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template( await help_test_setting_attribute_with_template(
hass, mqtt_mock_entry_with_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG
) )
@ -1071,7 +1071,7 @@ async def test_update_with_json_attrs_not_dict(
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
humidifier.DOMAIN, humidifier.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -1079,12 +1079,12 @@ async def test_update_with_json_attrs_bad_json(
hass, mqtt_mock_entry_with_yaml_config, caplog hass, mqtt_mock_entry_with_yaml_config, caplog
): ):
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_JSON( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
humidifier.DOMAIN, humidifier.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -1095,31 +1095,31 @@ async def test_discovery_update_attr(hass, mqtt_mock_entry_no_yaml_config, caplo
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
caplog, caplog,
humidifier.DOMAIN, humidifier.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config): async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config):
"""Test unique_id option only creates one fan per id.""" """Test unique_id option only creates one fan per id."""
config = { config = {
humidifier.DOMAIN: [ mqtt.DOMAIN: {
{ humidifier.DOMAIN: [
"platform": "mqtt", {
"name": "Test 1", "name": "Test 1",
"state_topic": "test-topic", "state_topic": "test-topic",
"command_topic": "test_topic", "command_topic": "test_topic",
"target_humidity_command_topic": "humidity-command-topic", "target_humidity_command_topic": "humidity-command-topic",
"unique_id": "TOTALLY_UNIQUE", "unique_id": "TOTALLY_UNIQUE",
}, },
{ {
"platform": "mqtt", "name": "Test 2",
"name": "Test 2", "state_topic": "test-topic",
"state_topic": "test-topic", "command_topic": "test_topic",
"command_topic": "test_topic", "target_humidity_command_topic": "humidity-command-topic",
"target_humidity_command_topic": "humidity-command-topic", "unique_id": "TOTALLY_UNIQUE",
"unique_id": "TOTALLY_UNIQUE", },
}, ]
] }
} }
await help_test_unique_id( await help_test_unique_id(
hass, mqtt_mock_entry_with_yaml_config, humidifier.DOMAIN, config hass, mqtt_mock_entry_with_yaml_config, humidifier.DOMAIN, config
@ -1191,42 +1191,42 @@ async def test_discovery_broken(hass, mqtt_mock_entry_no_yaml_config, caplog):
async def test_entity_device_info_with_connection(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_with_connection(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT fan device registry integration.""" """Test MQTT fan device registry integration."""
await help_test_entity_device_info_with_connection( await help_test_entity_device_info_with_connection(
hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_with_identifier(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_with_identifier(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT fan device registry integration.""" """Test MQTT fan device registry integration."""
await help_test_entity_device_info_with_identifier( await help_test_entity_device_info_with_identifier(
hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_update(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_update(hass, mqtt_mock_entry_no_yaml_config):
"""Test device registry update.""" """Test device registry update."""
await help_test_entity_device_info_update( await help_test_entity_device_info_update(
hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_remove(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_remove(hass, mqtt_mock_entry_no_yaml_config):
"""Test device registry remove.""" """Test device registry remove."""
await help_test_entity_device_info_remove( await help_test_entity_device_info_remove(
hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_config): async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_config):
"""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_LEGACY hass, mqtt_mock_entry_with_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT discovery update when entity_id is updated.""" """Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update( await help_test_entity_id_update_discovery_update(
hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG
) )
@ -1236,7 +1236,7 @@ async def test_entity_debug_info_message(hass, mqtt_mock_entry_no_yaml_config):
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
humidifier.DOMAIN, humidifier.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
humidifier.SERVICE_TURN_ON, humidifier.SERVICE_TURN_ON,
) )
@ -1286,9 +1286,9 @@ async def test_publishing_with_custom_encoding(
): ):
"""Test publishing MQTT payload with different encoding.""" """Test publishing MQTT payload with different encoding."""
domain = humidifier.DOMAIN domain = humidifier.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[domain]) config = copy.deepcopy(DEFAULT_CONFIG)
if topic == "mode_command_topic": if topic == "mode_command_topic":
config["modes"] = ["auto", "eco"] config[mqtt.DOMAIN][domain]["modes"] = ["auto", "eco"]
await help_test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding(
hass, hass,
@ -1307,12 +1307,14 @@ async def test_publishing_with_custom_encoding(
async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path): async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path):
"""Test reloading the MQTT platform.""" """Test reloading the MQTT platform."""
domain = humidifier.DOMAIN domain = humidifier.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_reloadable( await help_test_reloadable(
hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config
) )
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path): async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup.""" """Test reloading the MQTT platform with late entry setup."""
domain = humidifier.DOMAIN domain = humidifier.DOMAIN
@ -1323,11 +1325,8 @@ async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
async def test_setup_manual_entity_from_yaml(hass): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = humidifier.DOMAIN platform = humidifier.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[platform]) await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
config["name"] = "test" assert hass.states.get(f"{platform}.test")
del config["platform"]
await help_test_setup_manual_entity_from_yaml(hass, platform, config)
assert hass.states.get(f"{platform}.test") is not None
async def test_config_schema_validation(hass): async def test_config_schema_validation(hass):
@ -1344,7 +1343,7 @@ async def test_config_schema_validation(hass):
async def test_unload_config_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path): async def test_unload_config_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path):
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = humidifier.DOMAIN domain = humidifier.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_unload_config_entry_with_platform( await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config
) )

View file

@ -1485,9 +1485,17 @@ async def test_setup_override_configuration(hass, caplog, tmp_path):
@patch("homeassistant.components.mqtt.PLATFORMS", []) @patch("homeassistant.components.mqtt.PLATFORMS", [])
async def test_setup_manual_mqtt_with_platform_key(hass, caplog): async def test_setup_manual_mqtt_with_platform_key(hass, caplog):
"""Test set up a manual MQTT item with a platform key.""" """Test set up a manual MQTT item with a platform key."""
config = {"platform": "mqtt", "name": "test", "command_topic": "test-topic"} config = {
mqtt.DOMAIN: {
"light": {
"platform": "mqtt",
"name": "test",
"command_topic": "test-topic",
}
}
}
with pytest.raises(AssertionError): with pytest.raises(AssertionError):
await help_test_setup_manual_entity_from_yaml(hass, "light", 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
@ -1497,9 +1505,9 @@ async def test_setup_manual_mqtt_with_platform_key(hass, caplog):
@patch("homeassistant.components.mqtt.PLATFORMS", []) @patch("homeassistant.components.mqtt.PLATFORMS", [])
async def test_setup_manual_mqtt_with_invalid_config(hass, caplog): async def test_setup_manual_mqtt_with_invalid_config(hass, caplog):
"""Test set up a manual MQTT item with an invalid config.""" """Test set up a manual MQTT item with an invalid config."""
config = {"name": "test"} config = {mqtt.DOMAIN: {"light": {"name": "test"}}}
with pytest.raises(AssertionError): with pytest.raises(AssertionError):
await help_test_setup_manual_entity_from_yaml(hass, "light", 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
@ -1509,8 +1517,8 @@ async def test_setup_manual_mqtt_with_invalid_config(hass, caplog):
@patch("homeassistant.components.mqtt.PLATFORMS", []) @patch("homeassistant.components.mqtt.PLATFORMS", [])
async def test_setup_manual_mqtt_empty_platform(hass, caplog): async def test_setup_manual_mqtt_empty_platform(hass, caplog):
"""Test set up a manual MQTT platform without items.""" """Test set up a manual MQTT platform without items."""
config = [] config = {mqtt.DOMAIN: {"light": []}}
await help_test_setup_manual_entity_from_yaml(hass, "light", config) await help_test_setup_manual_entity_from_yaml(hass, config)
assert "voluptuous.error.MultipleInvalid" not in caplog.text assert "voluptuous.error.MultipleInvalid" not in caplog.text
@ -2797,7 +2805,11 @@ async def test_publish_or_subscribe_without_valid_config_entry(hass, caplog):
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.LIGHT]) @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.LIGHT])
async def test_reload_entry_with_new_config(hass, tmp_path): async def test_reload_entry_with_new_config(hass, tmp_path):
"""Test reloading the config entry with a new yaml config.""" """Test reloading the config entry with a new yaml config."""
config_old = [{"name": "test_old1", "command_topic": "test-topic_old"}] # Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
config_old = {
"mqtt": {"light": [{"name": "test_old1", "command_topic": "test-topic_old"}]}
}
config_yaml_new = { config_yaml_new = {
"mqtt": { "mqtt": {
"light": [{"name": "test_new_modern", "command_topic": "test-topic_new"}] "light": [{"name": "test_new_modern", "command_topic": "test-topic_new"}]
@ -2812,7 +2824,7 @@ async def test_reload_entry_with_new_config(hass, tmp_path):
} }
], ],
} }
await help_test_setup_manual_entity_from_yaml(hass, "light", config_old) await help_test_setup_manual_entity_from_yaml(hass, config_old)
assert hass.states.get("light.test_old1") is not None assert hass.states.get("light.test_old1") is not None
await help_test_entry_reload_with_new_config(hass, tmp_path, config_yaml_new) await help_test_entry_reload_with_new_config(hass, tmp_path, config_yaml_new)
@ -2824,7 +2836,9 @@ async def test_reload_entry_with_new_config(hass, tmp_path):
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.LIGHT]) @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.LIGHT])
async def test_disabling_and_enabling_entry(hass, tmp_path, caplog): async def test_disabling_and_enabling_entry(hass, tmp_path, caplog):
"""Test disabling and enabling the config entry.""" """Test disabling and enabling the config entry."""
config_old = [{"name": "test_old1", "command_topic": "test-topic_old"}] config_old = {
"mqtt": {"light": [{"name": "test_old1", "command_topic": "test-topic_old"}]}
}
config_yaml_new = { config_yaml_new = {
"mqtt": { "mqtt": {
"light": [{"name": "test_new_modern", "command_topic": "test-topic_new"}] "light": [{"name": "test_new_modern", "command_topic": "test-topic_new"}]
@ -2839,7 +2853,7 @@ async def test_disabling_and_enabling_entry(hass, tmp_path, caplog):
} }
], ],
} }
await help_test_setup_manual_entity_from_yaml(hass, "light", config_old) await help_test_setup_manual_entity_from_yaml(hass, config_old)
assert hass.states.get("light.test_old1") is not None assert hass.states.get("light.test_old1") is not None
mqtt_config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0] mqtt_config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0]
@ -2929,7 +2943,9 @@ async def test_setup_manual_items_with_unique_ids(
hass, tmp_path, caplog, config, unique hass, tmp_path, caplog, config, unique
): ):
"""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, "light", config) await help_test_setup_manual_entity_from_yaml(
hass, {mqtt.DOMAIN: {"light": 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

View file

@ -58,7 +58,7 @@ 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, 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,
) )
@ -95,8 +95,6 @@ DEFAULT_CONFIG_2 = {mqtt.DOMAIN: {vacuum.DOMAIN: {"name": "test"}}}
# Scheduled to be removed in HA core 2022.12 # Scheduled to be removed in HA core 2022.12
DEFAULT_CONFIG_LEGACY = deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN]) DEFAULT_CONFIG_LEGACY = deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
DEFAULT_CONFIG_LEGACY[vacuum.DOMAIN][CONF_PLATFORM] = mqtt.DOMAIN DEFAULT_CONFIG_LEGACY[vacuum.DOMAIN][CONF_PLATFORM] = mqtt.DOMAIN
DEFAULT_CONFIG_2_LEGACY = deepcopy(DEFAULT_CONFIG_2[mqtt.DOMAIN])
DEFAULT_CONFIG_2_LEGACY[vacuum.DOMAIN][CONF_PLATFORM] = mqtt.DOMAIN
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
@ -108,7 +106,7 @@ def vacuum_platform_only():
async def test_default_supported_features(hass, mqtt_mock_entry_with_yaml_config): async def test_default_supported_features(hass, mqtt_mock_entry_with_yaml_config):
"""Test that the correct supported features.""" """Test that the correct supported features."""
assert await async_setup_component(hass, vacuum.DOMAIN, DEFAULT_CONFIG_LEGACY) assert await async_setup_component(hass, mqtt.DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done() await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config() await mqtt_mock_entry_with_yaml_config()
entity = hass.states.get("vacuum.mqtttest") entity = hass.states.get("vacuum.mqtttest")
@ -616,28 +614,28 @@ async def test_availability_when_connection_lost(
): ):
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_with_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2_LEGACY hass, mqtt_mock_entry_with_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
) )
async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config): async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_with_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2_LEGACY hass, mqtt_mock_entry_with_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
) )
async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_config): async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
await help_test_default_availability_payload( await help_test_default_availability_payload(
hass, mqtt_mock_entry_with_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2_LEGACY hass, mqtt_mock_entry_with_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
) )
async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_config): async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability by custom payload with defined topic.""" """Test availability by custom payload with defined topic."""
await help_test_custom_availability_payload( await help_test_custom_availability_payload(
hass, mqtt_mock_entry_with_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2_LEGACY hass, mqtt_mock_entry_with_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
) )
@ -646,7 +644,7 @@ async def test_setting_attribute_via_mqtt_json_message(
): ):
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message( await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_with_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2_LEGACY hass, mqtt_mock_entry_with_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
) )
@ -658,7 +656,7 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
vacuum.DOMAIN, vacuum.DOMAIN,
DEFAULT_CONFIG_2_LEGACY, DEFAULT_CONFIG_2,
MQTT_LEGACY_VACUUM_ATTRIBUTES_BLOCKED, MQTT_LEGACY_VACUUM_ATTRIBUTES_BLOCKED,
) )
@ -666,7 +664,7 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_config): async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_config):
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template( await help_test_setting_attribute_with_template(
hass, mqtt_mock_entry_with_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2_LEGACY hass, mqtt_mock_entry_with_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
) )
@ -679,20 +677,20 @@ async def test_update_with_json_attrs_not_dict(
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
vacuum.DOMAIN, vacuum.DOMAIN,
DEFAULT_CONFIG_2_LEGACY, DEFAULT_CONFIG_2,
) )
async def test_update_with_json_attrs_bad_JSON( async def test_update_with_json_attrs_bad_json(
hass, mqtt_mock_entry_with_yaml_config, caplog hass, mqtt_mock_entry_with_yaml_config, caplog
): ):
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_JSON( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
vacuum.DOMAIN, vacuum.DOMAIN,
DEFAULT_CONFIG_2_LEGACY, DEFAULT_CONFIG_2,
) )
@ -703,27 +701,27 @@ async def test_discovery_update_attr(hass, mqtt_mock_entry_no_yaml_config, caplo
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
caplog, caplog,
vacuum.DOMAIN, vacuum.DOMAIN,
DEFAULT_CONFIG_2_LEGACY, DEFAULT_CONFIG_2,
) )
async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config): async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config):
"""Test unique id option only creates one vacuum per unique_id.""" """Test unique id option only creates one vacuum per unique_id."""
config = { config = {
vacuum.DOMAIN: [ mqtt.DOMAIN: {
{ vacuum.DOMAIN: [
"platform": "mqtt", {
"name": "Test 1", "name": "Test 1",
"command_topic": "test_topic", "command_topic": "test_topic",
"unique_id": "TOTALLY_UNIQUE", "unique_id": "TOTALLY_UNIQUE",
}, },
{ {
"platform": "mqtt", "name": "Test 2",
"name": "Test 2", "command_topic": "test_topic",
"command_topic": "test_topic", "unique_id": "TOTALLY_UNIQUE",
"unique_id": "TOTALLY_UNIQUE", },
}, ]
] }
} }
await help_test_unique_id( await help_test_unique_id(
hass, mqtt_mock_entry_with_yaml_config, vacuum.DOMAIN, config hass, mqtt_mock_entry_with_yaml_config, vacuum.DOMAIN, config
@ -732,7 +730,7 @@ async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config):
async def test_discovery_removal_vacuum(hass, mqtt_mock_entry_no_yaml_config, caplog): async def test_discovery_removal_vacuum(hass, mqtt_mock_entry_no_yaml_config, caplog):
"""Test removal of discovered vacuum.""" """Test removal of discovered vacuum."""
data = json.dumps(DEFAULT_CONFIG_2_LEGACY[vacuum.DOMAIN]) data = json.dumps(DEFAULT_CONFIG_2[mqtt.DOMAIN][vacuum.DOMAIN])
await help_test_discovery_removal( await help_test_discovery_removal(
hass, mqtt_mock_entry_no_yaml_config, caplog, vacuum.DOMAIN, data hass, mqtt_mock_entry_no_yaml_config, caplog, vacuum.DOMAIN, data
) )
@ -778,41 +776,42 @@ async def test_discovery_broken(hass, mqtt_mock_entry_no_yaml_config, caplog):
async def test_entity_device_info_with_connection(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_with_connection(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT vacuum device registry integration.""" """Test MQTT vacuum device registry integration."""
await help_test_entity_device_info_with_connection( await help_test_entity_device_info_with_connection(
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2_LEGACY hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
) )
async def test_entity_device_info_with_identifier(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_with_identifier(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT vacuum device registry integration.""" """Test MQTT vacuum device registry integration."""
await help_test_entity_device_info_with_identifier( await help_test_entity_device_info_with_identifier(
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2_LEGACY hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
) )
async def test_entity_device_info_update(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_update(hass, mqtt_mock_entry_no_yaml_config):
"""Test device registry update.""" """Test device registry update."""
await help_test_entity_device_info_update( await help_test_entity_device_info_update(
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2_LEGACY hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
) )
async def test_entity_device_info_remove(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_remove(hass, mqtt_mock_entry_no_yaml_config):
"""Test device registry remove.""" """Test device registry remove."""
await help_test_entity_device_info_remove( await help_test_entity_device_info_remove(
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2_LEGACY hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
) )
async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_config): async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_config):
"""Test MQTT subscriptions are managed when entity_id is updated.""" """Test MQTT subscriptions are managed when entity_id is updated."""
config = { config = {
vacuum.DOMAIN: { mqtt.DOMAIN: {
"platform": "mqtt", vacuum.DOMAIN: {
"name": "test", "name": "test",
"battery_level_topic": "test-topic", "battery_level_topic": "test-topic",
"battery_level_template": "{{ value_json.battery_level }}", "battery_level_template": "{{ value_json.battery_level }}",
"command_topic": "command-topic", "command_topic": "command-topic",
"availability_topic": "avty-topic", "availability_topic": "avty-topic",
}
} }
} }
await help_test_entity_id_update_subscriptions( await help_test_entity_id_update_subscriptions(
@ -827,20 +826,21 @@ async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_co
async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT discovery update when entity_id is updated.""" """Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update( await help_test_entity_id_update_discovery_update(
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2_LEGACY hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
) )
async def test_entity_debug_info_message(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_debug_info_message(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT debug info.""" """Test MQTT debug info."""
config = { config = {
vacuum.DOMAIN: { mqtt.DOMAIN: {
"platform": "mqtt", vacuum.DOMAIN: {
"name": "test", "name": "test",
"battery_level_topic": "state-topic", "battery_level_topic": "state-topic",
"battery_level_template": "{{ value_json.battery_level }}", "battery_level_template": "{{ value_json.battery_level }}",
"command_topic": "command-topic", "command_topic": "command-topic",
"payload_turn_on": "ON", "payload_turn_on": "ON",
}
} }
} }
await help_test_entity_debug_info_message( await help_test_entity_debug_info_message(
@ -904,8 +904,8 @@ async def test_publishing_with_custom_encoding(
): ):
"""Test publishing MQTT payload with different encoding.""" """Test publishing MQTT payload with different encoding."""
domain = vacuum.DOMAIN domain = vacuum.DOMAIN
config = deepcopy(DEFAULT_CONFIG_LEGACY[domain]) config = deepcopy(DEFAULT_CONFIG)
config["supported_features"] = [ config[mqtt.DOMAIN][domain]["supported_features"] = [
"turn_on", "turn_on",
"turn_off", "turn_off",
"clean_spot", "clean_spot",
@ -930,12 +930,14 @@ async def test_publishing_with_custom_encoding(
async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path): async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path):
"""Test reloading the MQTT platform.""" """Test reloading the MQTT platform."""
domain = vacuum.DOMAIN domain = vacuum.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_reloadable( await help_test_reloadable(
hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config
) )
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path): async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup.""" """Test reloading the MQTT platform with late entry setup."""
domain = vacuum.DOMAIN domain = vacuum.DOMAIN
@ -975,7 +977,7 @@ async def test_encoding_subscribable_topics(
): ):
"""Test handling of incoming encoded payload.""" """Test handling of incoming encoded payload."""
domain = vacuum.DOMAIN domain = vacuum.DOMAIN
config = deepcopy(DEFAULT_CONFIG_LEGACY[domain]) config = deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][domain])
config[CONF_SUPPORTED_FEATURES] = [ config[CONF_SUPPORTED_FEATURES] = [
"turn_on", "turn_on",
"turn_off", "turn_off",
@ -1007,11 +1009,8 @@ async def test_encoding_subscribable_topics(
async def test_setup_manual_entity_from_yaml(hass): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = vacuum.DOMAIN platform = vacuum.DOMAIN
config = deepcopy(DEFAULT_CONFIG_LEGACY[platform]) await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
config["name"] = "test" assert hass.states.get(f"{platform}.mqtttest")
del config["platform"]
await help_test_setup_manual_entity_from_yaml(hass, platform, config)
assert hass.states.get(f"{platform}.test") is not None
# Test deprecated YAML configuration under the platform key # Test deprecated YAML configuration under the platform key

View file

@ -223,7 +223,7 @@ from .test_common import (
help_test_setup_manual_entity_from_yaml, 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,
help_test_update_with_json_attrs_not_dict, help_test_update_with_json_attrs_not_dict,
) )
@ -2094,28 +2094,28 @@ async def test_availability_when_connection_lost(
): ):
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config): async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_config): async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
await help_test_default_availability_payload( await help_test_default_availability_payload(
hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_config): async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability by custom payload with defined topic.""" """Test availability by custom payload with defined topic."""
await help_test_custom_availability_payload( await help_test_custom_availability_payload(
hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG
) )
@ -2124,7 +2124,7 @@ async def test_setting_attribute_via_mqtt_json_message(
): ):
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message( await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG
) )
@ -2136,7 +2136,7 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
light.DOMAIN, light.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
MQTT_LIGHT_ATTRIBUTES_BLOCKED, MQTT_LIGHT_ATTRIBUTES_BLOCKED,
) )
@ -2144,7 +2144,7 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_config): async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_config):
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template( await help_test_setting_attribute_with_template(
hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG
) )
@ -2157,20 +2157,20 @@ async def test_update_with_json_attrs_not_dict(
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
light.DOMAIN, light.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
async def test_update_with_json_attrs_bad_JSON( async def test_update_with_json_attrs_bad_json(
hass, mqtt_mock_entry_with_yaml_config, caplog hass, mqtt_mock_entry_with_yaml_config, caplog
): ):
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_JSON( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
light.DOMAIN, light.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -2181,29 +2181,29 @@ async def test_discovery_update_attr(hass, mqtt_mock_entry_no_yaml_config, caplo
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
caplog, caplog,
light.DOMAIN, light.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config): async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config):
"""Test unique id option only creates one light per unique_id.""" """Test unique id option only creates one light per unique_id."""
config = { config = {
light.DOMAIN: [ mqtt.DOMAIN: {
{ light.DOMAIN: [
"platform": "mqtt", {
"name": "Test 1", "name": "Test 1",
"state_topic": "test-topic", "state_topic": "test-topic",
"command_topic": "test_topic", "command_topic": "test_topic",
"unique_id": "TOTALLY_UNIQUE", "unique_id": "TOTALLY_UNIQUE",
}, },
{ {
"platform": "mqtt", "name": "Test 2",
"name": "Test 2", "state_topic": "test-topic",
"state_topic": "test-topic", "command_topic": "test_topic",
"command_topic": "test_topic", "unique_id": "TOTALLY_UNIQUE",
"unique_id": "TOTALLY_UNIQUE", },
}, ]
] }
} }
await help_test_unique_id( await help_test_unique_id(
hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, config hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, config
@ -2744,42 +2744,42 @@ async def test_discovery_broken(hass, mqtt_mock_entry_no_yaml_config, caplog):
async def test_entity_device_info_with_connection(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_with_connection(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT light device registry integration.""" """Test MQTT light device registry integration."""
await help_test_entity_device_info_with_connection( await help_test_entity_device_info_with_connection(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_with_identifier(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_with_identifier(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT light device registry integration.""" """Test MQTT light device registry integration."""
await help_test_entity_device_info_with_identifier( await help_test_entity_device_info_with_identifier(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_update(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_update(hass, mqtt_mock_entry_no_yaml_config):
"""Test device registry update.""" """Test device registry update."""
await help_test_entity_device_info_update( await help_test_entity_device_info_update(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_remove(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_remove(hass, mqtt_mock_entry_no_yaml_config):
"""Test device registry remove.""" """Test device registry remove."""
await help_test_entity_device_info_remove( await help_test_entity_device_info_remove(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_config): async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_config):
"""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_LEGACY hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT discovery update when entity_id is updated.""" """Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update( await help_test_entity_id_update_discovery_update(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
) )
@ -2789,7 +2789,7 @@ async def test_entity_debug_info_message(hass, mqtt_mock_entry_no_yaml_config):
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
light.DOMAIN, light.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
light.SERVICE_TURN_ON, light.SERVICE_TURN_ON,
) )
@ -2914,11 +2914,11 @@ async def test_publishing_with_custom_encoding(
): ):
"""Test publishing MQTT payload with different encoding.""" """Test publishing MQTT payload with different encoding."""
domain = light.DOMAIN domain = light.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[domain]) config = copy.deepcopy(DEFAULT_CONFIG)
if topic == "effect_command_topic": if topic == "effect_command_topic":
config["effect_list"] = ["random", "color_loop"] config[mqtt.DOMAIN][domain]["effect_list"] = ["random", "color_loop"]
elif topic == "white_command_topic": elif topic == "white_command_topic":
config["rgb_command_topic"] = "some-cmd-topic" config[mqtt.DOMAIN][domain]["rgb_command_topic"] = "some-cmd-topic"
await help_test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding(
hass, hass,
@ -2939,12 +2939,14 @@ async def test_publishing_with_custom_encoding(
async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path): async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path):
"""Test reloading the MQTT platform.""" """Test reloading the MQTT platform."""
domain = light.DOMAIN domain = light.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_reloadable( await help_test_reloadable(
hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config
) )
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path): async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup.""" """Test reloading the MQTT platform with late entry setup."""
domain = light.DOMAIN domain = light.DOMAIN
@ -2993,7 +2995,7 @@ async def test_encoding_subscribable_topics(
init_payload, init_payload,
): ):
"""Test handling of incoming encoded payload.""" """Test handling of incoming encoded payload."""
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[light.DOMAIN]) config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][light.DOMAIN])
config[CONF_EFFECT_COMMAND_TOPIC] = "light/CONF_EFFECT_COMMAND_TOPIC" config[CONF_EFFECT_COMMAND_TOPIC] = "light/CONF_EFFECT_COMMAND_TOPIC"
config[CONF_RGB_COMMAND_TOPIC] = "light/CONF_RGB_COMMAND_TOPIC" config[CONF_RGB_COMMAND_TOPIC] = "light/CONF_RGB_COMMAND_TOPIC"
config[CONF_BRIGHTNESS_COMMAND_TOPIC] = "light/CONF_BRIGHTNESS_COMMAND_TOPIC" config[CONF_BRIGHTNESS_COMMAND_TOPIC] = "light/CONF_BRIGHTNESS_COMMAND_TOPIC"
@ -3036,7 +3038,7 @@ async def test_encoding_subscribable_topics_brightness(
init_payload, init_payload,
): ):
"""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_LEGACY[light.DOMAIN]) config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][light.DOMAIN])
config[CONF_BRIGHTNESS_COMMAND_TOPIC] = "light/CONF_BRIGHTNESS_COMMAND_TOPIC" config[CONF_BRIGHTNESS_COMMAND_TOPIC] = "light/CONF_BRIGHTNESS_COMMAND_TOPIC"
await help_test_encoding_subscribable_topics( await help_test_encoding_subscribable_topics(
@ -3138,17 +3140,14 @@ async def test_sending_mqtt_effect_command_with_template(
async def test_setup_manual_entity_from_yaml(hass): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = light.DOMAIN platform = light.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[platform]) await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
config["name"] = "test" assert hass.states.get(f"{platform}.test")
del config["platform"]
await help_test_setup_manual_entity_from_yaml(hass, platform, config)
assert hass.states.get(f"{platform}.test") is not None
async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path): async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path):
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = light.DOMAIN domain = light.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_unload_config_entry_with_platform( await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config
) )

View file

@ -125,7 +125,7 @@ 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, 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,
) )
@ -1854,28 +1854,28 @@ async def test_availability_when_connection_lost(
): ):
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config): async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_config): async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
await help_test_default_availability_payload( await help_test_default_availability_payload(
hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_config): async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability by custom payload with defined topic.""" """Test availability by custom payload with defined topic."""
await help_test_custom_availability_payload( await help_test_custom_availability_payload(
hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG
) )
@ -1884,7 +1884,7 @@ async def test_setting_attribute_via_mqtt_json_message(
): ):
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message( await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG
) )
@ -1896,7 +1896,7 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
light.DOMAIN, light.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
MQTT_LIGHT_ATTRIBUTES_BLOCKED, MQTT_LIGHT_ATTRIBUTES_BLOCKED,
) )
@ -1904,7 +1904,7 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_config): async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_config):
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template( await help_test_setting_attribute_with_template(
hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG
) )
@ -1917,20 +1917,20 @@ async def test_update_with_json_attrs_not_dict(
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
light.DOMAIN, light.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
async def test_update_with_json_attrs_bad_JSON( async def test_update_with_json_attrs_bad_json(
hass, mqtt_mock_entry_with_yaml_config, caplog hass, mqtt_mock_entry_with_yaml_config, caplog
): ):
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_JSON( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
light.DOMAIN, light.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -1941,31 +1941,31 @@ async def test_discovery_update_attr(hass, mqtt_mock_entry_no_yaml_config, caplo
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
caplog, caplog,
light.DOMAIN, light.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config): async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config):
"""Test unique id option only creates one light per unique_id.""" """Test unique id option only creates one light per unique_id."""
config = { config = {
light.DOMAIN: [ mqtt.DOMAIN: {
{ light.DOMAIN: [
"platform": "mqtt", {
"name": "Test 1", "name": "Test 1",
"schema": "json", "schema": "json",
"state_topic": "test-topic", "state_topic": "test-topic",
"command_topic": "test_topic", "command_topic": "test_topic",
"unique_id": "TOTALLY_UNIQUE", "unique_id": "TOTALLY_UNIQUE",
}, },
{ {
"platform": "mqtt", "name": "Test 2",
"name": "Test 2", "schema": "json",
"schema": "json", "state_topic": "test-topic",
"state_topic": "test-topic", "command_topic": "test_topic",
"command_topic": "test_topic", "unique_id": "TOTALLY_UNIQUE",
"unique_id": "TOTALLY_UNIQUE", },
}, ]
] }
} }
await help_test_unique_id( await help_test_unique_id(
hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, config hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, config
@ -2057,7 +2057,7 @@ async def test_entity_device_info_with_connection(hass, mqtt_mock_entry_no_yaml_
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
light.DOMAIN, light.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -2067,7 +2067,7 @@ async def test_entity_device_info_with_identifier(hass, mqtt_mock_entry_no_yaml_
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
light.DOMAIN, light.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -2077,7 +2077,7 @@ async def test_entity_device_info_update(hass, mqtt_mock_entry_no_yaml_config):
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
light.DOMAIN, light.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -2087,27 +2087,21 @@ async def test_entity_device_info_remove(hass, mqtt_mock_entry_no_yaml_config):
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
light.DOMAIN, light.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_config): async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_config):
"""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, light.DOMAIN, DEFAULT_CONFIG
mqtt_mock_entry_with_yaml_config,
light.DOMAIN,
DEFAULT_CONFIG_LEGACY,
) )
async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT discovery update when entity_id is updated.""" """Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update( await help_test_entity_id_update_discovery_update(
hass, hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
mqtt_mock_entry_no_yaml_config,
light.DOMAIN,
DEFAULT_CONFIG_LEGACY,
) )
@ -2117,7 +2111,7 @@ async def test_entity_debug_info_message(hass, mqtt_mock_entry_no_yaml_config):
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
light.DOMAIN, light.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
light.SERVICE_TURN_ON, light.SERVICE_TURN_ON,
command_payload='{"state":"ON"}', command_payload='{"state":"ON"}',
state_payload='{"state":"ON"}', state_payload='{"state":"ON"}',
@ -2182,9 +2176,9 @@ async def test_publishing_with_custom_encoding(
): ):
"""Test publishing MQTT payload with different encoding.""" """Test publishing MQTT payload with different encoding."""
domain = light.DOMAIN domain = light.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[domain]) config = copy.deepcopy(DEFAULT_CONFIG)
if topic == "effect_command_topic": if topic == "effect_command_topic":
config["effect_list"] = ["random", "color_loop"] config[mqtt.DOMAIN][domain]["effect_list"] = ["random", "color_loop"]
await help_test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding(
hass, hass,
@ -2205,12 +2199,14 @@ async def test_publishing_with_custom_encoding(
async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path): async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path):
"""Test reloading the MQTT platform.""" """Test reloading the MQTT platform."""
domain = light.DOMAIN domain = light.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_reloadable( await help_test_reloadable(
hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config
) )
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path): async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup.""" """Test reloading the MQTT platform with late entry setup."""
domain = light.DOMAIN domain = light.DOMAIN
@ -2241,7 +2237,7 @@ async def test_encoding_subscribable_topics(
init_payload, init_payload,
): ):
"""Test handling of incoming encoded payload.""" """Test handling of incoming encoded payload."""
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[light.DOMAIN]) config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][light.DOMAIN])
config["color_mode"] = True config["color_mode"] = True
config["supported_color_modes"] = [ config["supported_color_modes"] = [
"color_temp", "color_temp",
@ -2269,11 +2265,8 @@ async def test_encoding_subscribable_topics(
async def test_setup_manual_entity_from_yaml(hass): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = light.DOMAIN platform = light.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[platform]) await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
config["name"] = "test" assert hass.states.get(f"{platform}.test")
del config["platform"]
await help_test_setup_manual_entity_from_yaml(hass, platform, config)
assert hass.states.get(f"{platform}.test") is not None
# Test deprecated YAML configuration under the platform key # Test deprecated YAML configuration under the platform key

View file

@ -71,7 +71,7 @@ from .test_common import (
help_test_setup_manual_entity_from_yaml, 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,
help_test_update_with_json_attrs_not_dict, help_test_update_with_json_attrs_not_dict,
) )
@ -846,28 +846,28 @@ async def test_availability_when_connection_lost(
): ):
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config): async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_config): async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
await help_test_default_availability_payload( await help_test_default_availability_payload(
hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_config): async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability by custom payload with defined topic.""" """Test availability by custom payload with defined topic."""
await help_test_custom_availability_payload( await help_test_custom_availability_payload(
hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG
) )
@ -876,7 +876,7 @@ async def test_setting_attribute_via_mqtt_json_message(
): ):
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message( await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG
) )
@ -888,7 +888,7 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
light.DOMAIN, light.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
MQTT_LIGHT_ATTRIBUTES_BLOCKED, MQTT_LIGHT_ATTRIBUTES_BLOCKED,
) )
@ -896,7 +896,7 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_config): async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_config):
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template( await help_test_setting_attribute_with_template(
hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG
) )
@ -909,20 +909,20 @@ async def test_update_with_json_attrs_not_dict(
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
light.DOMAIN, light.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
async def test_update_with_json_attrs_bad_JSON( async def test_update_with_json_attrs_bad_json(
hass, mqtt_mock_entry_with_yaml_config, caplog hass, mqtt_mock_entry_with_yaml_config, caplog
): ):
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_JSON( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
light.DOMAIN, light.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -933,33 +933,35 @@ async def test_discovery_update_attr(hass, mqtt_mock_entry_no_yaml_config, caplo
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
caplog, caplog,
light.DOMAIN, light.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config): async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config):
"""Test unique id option only creates one light per unique_id.""" """Test unique id option only creates one light per unique_id."""
config = { config = {
light.DOMAIN: [ mqtt.DOMAIN: {
{ light.DOMAIN: [
"platform": "mqtt", {
"name": "Test 1", "name": "Test 1",
"schema": "template", "schema": "template",
"state_topic": "test-topic", "state_topic": "test-topic",
"command_topic": "test_topic", "command_topic": "test_topic",
"command_on_template": "on,{{ transition }}", "command_on_template": "on,{{ transition }}",
"command_off_template": "off,{{ transition|d }}", "command_off_template": "off,{{ transition|d }}",
"unique_id": "TOTALLY_UNIQUE", "unique_id": "TOTALLY_UNIQUE",
}, },
{ {
"platform": "mqtt", "name": "Test 2",
"name": "Test 2", "schema": "template",
"schema": "template", "state_topic": "test-topic2",
"state_topic": "test-topic", "command_topic": "test_topic2",
"command_topic": "test_topic", "command_on_template": "on,{{ transition }}",
"unique_id": "TOTALLY_UNIQUE", "command_off_template": "off,{{ transition|d }}",
}, "unique_id": "TOTALLY_UNIQUE",
] },
]
}
} }
await help_test_unique_id( await help_test_unique_id(
hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, config hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, config
@ -1048,56 +1050,57 @@ async def test_discovery_broken(hass, mqtt_mock_entry_no_yaml_config, caplog):
async def test_entity_device_info_with_connection(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_with_connection(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT light device registry integration.""" """Test MQTT light device registry integration."""
await help_test_entity_device_info_with_connection( await help_test_entity_device_info_with_connection(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_with_identifier(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_with_identifier(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT light device registry integration.""" """Test MQTT light device registry integration."""
await help_test_entity_device_info_with_identifier( await help_test_entity_device_info_with_identifier(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_update(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_update(hass, mqtt_mock_entry_no_yaml_config):
"""Test device registry update.""" """Test device registry update."""
await help_test_entity_device_info_update( await help_test_entity_device_info_update(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_remove(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_remove(hass, mqtt_mock_entry_no_yaml_config):
"""Test device registry remove.""" """Test device registry remove."""
await help_test_entity_device_info_remove( await help_test_entity_device_info_remove(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_config): async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_config):
"""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_LEGACY hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT discovery update when entity_id is updated.""" """Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update( await help_test_entity_id_update_discovery_update(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_debug_info_message(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_debug_info_message(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT debug info.""" """Test MQTT debug info."""
config = { config = {
light.DOMAIN: { mqtt.DOMAIN: {
"platform": "mqtt", light.DOMAIN: {
"schema": "template", "schema": "template",
"name": "test", "name": "test",
"command_topic": "test-topic", "command_topic": "test-topic",
"command_on_template": "ON", "command_on_template": "ON",
"command_off_template": "off,{{ transition|d }}", "command_off_template": "off,{{ transition|d }}",
"state_template": '{{ value.split(",")[0] }}', "state_template": '{{ value.split(",")[0] }}',
}
} }
} }
await help_test_entity_debug_info_message( await help_test_entity_debug_info_message(
@ -1169,9 +1172,9 @@ async def test_publishing_with_custom_encoding(
): ):
"""Test publishing MQTT payload with different encoding.""" """Test publishing MQTT payload with different encoding."""
domain = light.DOMAIN domain = light.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[domain]) config = copy.deepcopy(DEFAULT_CONFIG)
if topic == "effect_command_topic": if topic == "effect_command_topic":
config["effect_list"] = ["random", "color_loop"] config[mqtt.DOMAIN][domain]["effect_list"] = ["random", "color_loop"]
await help_test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding(
hass, hass,
@ -1192,12 +1195,14 @@ async def test_publishing_with_custom_encoding(
async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path): async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path):
"""Test reloading the MQTT platform.""" """Test reloading the MQTT platform."""
domain = light.DOMAIN domain = light.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_reloadable( await help_test_reloadable(
hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config
) )
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path): async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup.""" """Test reloading the MQTT platform with late entry setup."""
domain = light.DOMAIN domain = light.DOMAIN
@ -1222,7 +1227,7 @@ async def test_encoding_subscribable_topics(
init_payload, init_payload,
): ):
"""Test handling of incoming encoded payload.""" """Test handling of incoming encoded payload."""
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[light.DOMAIN]) config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][light.DOMAIN])
config["state_template"] = "{{ value }}" config["state_template"] = "{{ value }}"
await help_test_encoding_subscribable_topics( await help_test_encoding_subscribable_topics(
hass, hass,
@ -1241,17 +1246,14 @@ async def test_encoding_subscribable_topics(
async def test_setup_manual_entity_from_yaml(hass): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = light.DOMAIN platform = light.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[platform]) await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
config["name"] = "test" assert hass.states.get(f"{platform}.test")
del config["platform"]
await help_test_setup_manual_entity_from_yaml(hass, platform, config)
assert hass.states.get(f"{platform}.test") is not None
async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path): async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path):
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = light.DOMAIN domain = light.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_unload_config_entry_with_platform( await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config
) )

View file

@ -49,7 +49,7 @@ from .test_common import (
help_test_setup_manual_entity_from_yaml, 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,
help_test_update_with_json_attrs_not_dict, help_test_update_with_json_attrs_not_dict,
) )
@ -452,28 +452,28 @@ async def test_availability_when_connection_lost(
): ):
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_with_yaml_config, lock.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, lock.DOMAIN, DEFAULT_CONFIG
) )
async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config): async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_with_yaml_config, lock.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, lock.DOMAIN, DEFAULT_CONFIG
) )
async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_config): async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
await help_test_default_availability_payload( await help_test_default_availability_payload(
hass, mqtt_mock_entry_with_yaml_config, lock.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, lock.DOMAIN, DEFAULT_CONFIG
) )
async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_config): async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability by custom payload with defined topic.""" """Test availability by custom payload with defined topic."""
await help_test_custom_availability_payload( await help_test_custom_availability_payload(
hass, mqtt_mock_entry_with_yaml_config, lock.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, lock.DOMAIN, DEFAULT_CONFIG
) )
@ -482,7 +482,7 @@ async def test_setting_attribute_via_mqtt_json_message(
): ):
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message( await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_with_yaml_config, lock.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, lock.DOMAIN, DEFAULT_CONFIG
) )
@ -494,7 +494,7 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
lock.DOMAIN, lock.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
MQTT_LOCK_ATTRIBUTES_BLOCKED, MQTT_LOCK_ATTRIBUTES_BLOCKED,
) )
@ -502,7 +502,7 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_config): async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_config):
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template( await help_test_setting_attribute_with_template(
hass, mqtt_mock_entry_with_yaml_config, lock.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, lock.DOMAIN, DEFAULT_CONFIG
) )
@ -515,7 +515,7 @@ async def test_update_with_json_attrs_not_dict(
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
lock.DOMAIN, lock.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -523,41 +523,41 @@ async def test_update_with_json_attrs_bad_json(
hass, mqtt_mock_entry_with_yaml_config, caplog hass, mqtt_mock_entry_with_yaml_config, caplog
): ):
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_JSON( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
lock.DOMAIN, lock.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
async def test_discovery_update_attr(hass, mqtt_mock_entry_no_yaml_config, caplog): async def test_discovery_update_attr(hass, mqtt_mock_entry_no_yaml_config, caplog):
"""Test update of discovered MQTTAttributes.""" """Test update of discovered MQTTAttributes."""
await help_test_discovery_update_attr( await help_test_discovery_update_attr(
hass, mqtt_mock_entry_no_yaml_config, caplog, lock.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, caplog, lock.DOMAIN, DEFAULT_CONFIG
) )
async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config): async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config):
"""Test unique id option only creates one lock per unique_id.""" """Test unique id option only creates one lock per unique_id."""
config = { config = {
lock.DOMAIN: [ mqtt.DOMAIN: {
{ lock.DOMAIN: [
"platform": "mqtt", {
"name": "Test 1", "name": "Test 1",
"state_topic": "test-topic", "state_topic": "test-topic",
"command_topic": "test_topic", "command_topic": "test_topic",
"unique_id": "TOTALLY_UNIQUE", "unique_id": "TOTALLY_UNIQUE",
}, },
{ {
"platform": "mqtt", "name": "Test 2",
"name": "Test 2", "state_topic": "test-topic",
"state_topic": "test-topic", "command_topic": "test_topic",
"command_topic": "test_topic", "unique_id": "TOTALLY_UNIQUE",
"unique_id": "TOTALLY_UNIQUE", },
}, ]
] }
} }
await help_test_unique_id( await help_test_unique_id(
hass, mqtt_mock_entry_with_yaml_config, lock.DOMAIN, config hass, mqtt_mock_entry_with_yaml_config, lock.DOMAIN, config
@ -626,42 +626,42 @@ async def test_discovery_broken(hass, mqtt_mock_entry_no_yaml_config, caplog):
async def test_entity_device_info_with_connection(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_with_connection(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT lock device registry integration.""" """Test MQTT lock device registry integration."""
await help_test_entity_device_info_with_connection( await help_test_entity_device_info_with_connection(
hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_with_identifier(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_with_identifier(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT lock device registry integration.""" """Test MQTT lock device registry integration."""
await help_test_entity_device_info_with_identifier( await help_test_entity_device_info_with_identifier(
hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_update(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_update(hass, mqtt_mock_entry_no_yaml_config):
"""Test device registry update.""" """Test device registry update."""
await help_test_entity_device_info_update( await help_test_entity_device_info_update(
hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_remove(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_remove(hass, mqtt_mock_entry_no_yaml_config):
"""Test device registry remove.""" """Test device registry remove."""
await help_test_entity_device_info_remove( await help_test_entity_device_info_remove(
hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_config): async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_config):
"""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_LEGACY hass, mqtt_mock_entry_with_yaml_config, lock.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT discovery update when entity_id is updated.""" """Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update( await help_test_entity_id_update_discovery_update(
hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG
) )
@ -671,7 +671,7 @@ async def test_entity_debug_info_message(hass, mqtt_mock_entry_no_yaml_config):
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
lock.DOMAIN, lock.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
SERVICE_LOCK, SERVICE_LOCK,
command_payload="LOCK", command_payload="LOCK",
) )
@ -701,7 +701,7 @@ async def test_publishing_with_custom_encoding(
): ):
"""Test publishing MQTT payload with different encoding.""" """Test publishing MQTT payload with different encoding."""
domain = lock.DOMAIN domain = lock.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding(
hass, hass,
@ -720,12 +720,14 @@ async def test_publishing_with_custom_encoding(
async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path): async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path):
"""Test reloading the MQTT platform.""" """Test reloading the MQTT platform."""
domain = lock.DOMAIN domain = lock.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_reloadable( await help_test_reloadable(
hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config
) )
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path): async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup.""" """Test reloading the MQTT platform with late entry setup."""
domain = lock.DOMAIN domain = lock.DOMAIN
@ -754,7 +756,7 @@ async def test_encoding_subscribable_topics(
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
lock.DOMAIN, lock.DOMAIN,
DEFAULT_CONFIG_LEGACY[lock.DOMAIN], DEFAULT_CONFIG[mqtt.DOMAIN][lock.DOMAIN],
topic, topic,
value, value,
attribute, attribute,
@ -765,17 +767,14 @@ async def test_encoding_subscribable_topics(
async def test_setup_manual_entity_from_yaml(hass, caplog, tmp_path): async def test_setup_manual_entity_from_yaml(hass, caplog, tmp_path):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = lock.DOMAIN platform = lock.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[platform]) await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
config["name"] = "test" assert hass.states.get(f"{platform}.test")
del config["platform"]
await help_test_setup_manual_entity_from_yaml(hass, platform, config)
assert hass.states.get(f"{platform}.test") is not None
async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path): async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path):
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = lock.DOMAIN domain = lock.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_unload_config_entry_with_platform( await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config
) )

View file

@ -59,7 +59,7 @@ from .test_common import (
help_test_setup_manual_entity_from_yaml, 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,
help_test_update_with_json_attrs_not_dict, help_test_update_with_json_attrs_not_dict,
) )
@ -446,28 +446,28 @@ async def test_availability_when_connection_lost(
): ):
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_with_yaml_config, number.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, number.DOMAIN, DEFAULT_CONFIG
) )
async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config): async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_with_yaml_config, number.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, number.DOMAIN, DEFAULT_CONFIG
) )
async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_config): async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
await help_test_default_availability_payload( await help_test_default_availability_payload(
hass, mqtt_mock_entry_with_yaml_config, number.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, number.DOMAIN, DEFAULT_CONFIG
) )
async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_config): async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability by custom payload with defined topic.""" """Test availability by custom payload with defined topic."""
await help_test_custom_availability_payload( await help_test_custom_availability_payload(
hass, mqtt_mock_entry_with_yaml_config, number.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, number.DOMAIN, DEFAULT_CONFIG
) )
@ -476,7 +476,7 @@ async def test_setting_attribute_via_mqtt_json_message(
): ):
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message( await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_with_yaml_config, number.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, number.DOMAIN, DEFAULT_CONFIG
) )
@ -488,7 +488,7 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
number.DOMAIN, number.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
MQTT_NUMBER_ATTRIBUTES_BLOCKED, MQTT_NUMBER_ATTRIBUTES_BLOCKED,
) )
@ -496,7 +496,7 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_config): async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_config):
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template( await help_test_setting_attribute_with_template(
hass, mqtt_mock_entry_with_yaml_config, number.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, number.DOMAIN, DEFAULT_CONFIG
) )
@ -509,20 +509,20 @@ async def test_update_with_json_attrs_not_dict(
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
number.DOMAIN, number.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
async def test_update_with_json_attrs_bad_JSON( async def test_update_with_json_attrs_bad_json(
hass, mqtt_mock_entry_with_yaml_config, caplog hass, mqtt_mock_entry_with_yaml_config, caplog
): ):
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_JSON( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
number.DOMAIN, number.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -533,29 +533,29 @@ async def test_discovery_update_attr(hass, mqtt_mock_entry_no_yaml_config, caplo
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
caplog, caplog,
number.DOMAIN, number.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config): async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config):
"""Test unique id option only creates one number per unique_id.""" """Test unique id option only creates one number per unique_id."""
config = { config = {
number.DOMAIN: [ mqtt.DOMAIN: {
{ number.DOMAIN: [
"platform": "mqtt", {
"name": "Test 1", "name": "Test 1",
"state_topic": "test-topic", "state_topic": "test-topic",
"command_topic": "test-topic", "command_topic": "test-topic",
"unique_id": "TOTALLY_UNIQUE", "unique_id": "TOTALLY_UNIQUE",
}, },
{ {
"platform": "mqtt", "name": "Test 2",
"name": "Test 2", "state_topic": "test-topic",
"state_topic": "test-topic", "command_topic": "test-topic",
"command_topic": "test-topic", "unique_id": "TOTALLY_UNIQUE",
"unique_id": "TOTALLY_UNIQUE", },
}, ]
] }
} }
await help_test_unique_id( await help_test_unique_id(
hass, mqtt_mock_entry_with_yaml_config, number.DOMAIN, config hass, mqtt_mock_entry_with_yaml_config, number.DOMAIN, config
@ -564,7 +564,7 @@ async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config):
async def test_discovery_removal_number(hass, mqtt_mock_entry_no_yaml_config, caplog): async def test_discovery_removal_number(hass, mqtt_mock_entry_no_yaml_config, caplog):
"""Test removal of discovered number.""" """Test removal of discovered number."""
data = json.dumps(DEFAULT_CONFIG_LEGACY[number.DOMAIN]) data = json.dumps(DEFAULT_CONFIG[mqtt.DOMAIN][number.DOMAIN])
await help_test_discovery_removal( await help_test_discovery_removal(
hass, mqtt_mock_entry_no_yaml_config, caplog, number.DOMAIN, data hass, mqtt_mock_entry_no_yaml_config, caplog, number.DOMAIN, data
) )
@ -624,42 +624,42 @@ async def test_discovery_broken(hass, mqtt_mock_entry_no_yaml_config, caplog):
async def test_entity_device_info_with_connection(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_with_connection(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT number device registry integration.""" """Test MQTT number device registry integration."""
await help_test_entity_device_info_with_connection( await help_test_entity_device_info_with_connection(
hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_with_identifier(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_with_identifier(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT number device registry integration.""" """Test MQTT number device registry integration."""
await help_test_entity_device_info_with_identifier( await help_test_entity_device_info_with_identifier(
hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_update(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_update(hass, mqtt_mock_entry_no_yaml_config):
"""Test device registry update.""" """Test device registry update."""
await help_test_entity_device_info_update( await help_test_entity_device_info_update(
hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_remove(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_remove(hass, mqtt_mock_entry_no_yaml_config):
"""Test device registry remove.""" """Test device registry remove."""
await help_test_entity_device_info_remove( await help_test_entity_device_info_remove(
hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_config): async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_config):
"""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_LEGACY hass, mqtt_mock_entry_with_yaml_config, number.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT discovery update when entity_id is updated.""" """Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update( await help_test_entity_id_update_discovery_update(
hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG
) )
@ -669,7 +669,7 @@ async def test_entity_debug_info_message(hass, mqtt_mock_entry_no_yaml_config):
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
number.DOMAIN, number.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
SERVICE_SET_VALUE, SERVICE_SET_VALUE,
service_parameters={ATTR_VALUE: 45}, service_parameters={ATTR_VALUE: 45},
command_payload="45", command_payload="45",
@ -882,7 +882,7 @@ async def test_publishing_with_custom_encoding(
): ):
"""Test publishing MQTT payload with different encoding.""" """Test publishing MQTT payload with different encoding."""
domain = NUMBER_DOMAIN domain = NUMBER_DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding(
hass, hass,
@ -901,12 +901,14 @@ async def test_publishing_with_custom_encoding(
async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path): async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path):
"""Test reloading the MQTT platform.""" """Test reloading the MQTT platform."""
domain = number.DOMAIN domain = number.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_reloadable( await help_test_reloadable(
hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config
) )
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path): async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup.""" """Test reloading the MQTT platform with late entry setup."""
domain = number.DOMAIN domain = number.DOMAIN
@ -935,8 +937,8 @@ async def test_encoding_subscribable_topics(
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
"number", number.DOMAIN,
DEFAULT_CONFIG_LEGACY["number"], DEFAULT_CONFIG[mqtt.DOMAIN][number.DOMAIN],
topic, topic,
value, value,
attribute, attribute,
@ -947,17 +949,14 @@ async def test_encoding_subscribable_topics(
async def test_setup_manual_entity_from_yaml(hass): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = number.DOMAIN platform = number.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[platform]) await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
config["name"] = "test" assert hass.states.get(f"{platform}.test")
del config["platform"]
await help_test_setup_manual_entity_from_yaml(hass, platform, config)
assert hass.states.get(f"{platform}.test") is not None
async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path): async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path):
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = number.DOMAIN domain = number.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_unload_config_entry_with_platform( await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config
) )

View file

@ -87,25 +87,26 @@ async def test_availability_when_connection_lost(
): ):
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_with_yaml_config, scene.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, scene.DOMAIN, DEFAULT_CONFIG
) )
async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config): async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_with_yaml_config, scene.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, scene.DOMAIN, DEFAULT_CONFIG
) )
async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_config): async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
config = { config = {
scene.DOMAIN: { mqtt.DOMAIN: {
"platform": "mqtt", scene.DOMAIN: {
"name": "test", "name": "test",
"command_topic": "command-topic", "command_topic": "command-topic",
"payload_on": 1, "payload_on": 1,
}
} }
} }
@ -123,11 +124,12 @@ async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_conf
async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_config): async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability by custom payload with defined topic.""" """Test availability by custom payload with defined topic."""
config = { config = {
scene.DOMAIN: { mqtt.DOMAIN: {
"platform": "mqtt", scene.DOMAIN: {
"name": "test", "name": "test",
"command_topic": "command-topic", "command_topic": "command-topic",
"payload_on": 1, "payload_on": 1,
}
} }
} }
@ -145,20 +147,20 @@ async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_confi
async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config): async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config):
"""Test unique id option only creates one scene per unique_id.""" """Test unique id option only creates one scene per unique_id."""
config = { config = {
scene.DOMAIN: [ mqtt.DOMAIN: {
{ scene.DOMAIN: [
"platform": "mqtt", {
"name": "Test 1", "name": "Test 1",
"command_topic": "command-topic", "command_topic": "command-topic",
"unique_id": "TOTALLY_UNIQUE", "unique_id": "TOTALLY_UNIQUE",
}, },
{ {
"platform": "mqtt", "name": "Test 2",
"name": "Test 2", "command_topic": "command-topic",
"command_topic": "command-topic", "unique_id": "TOTALLY_UNIQUE",
"unique_id": "TOTALLY_UNIQUE", },
}, ]
] }
} }
await help_test_unique_id( await help_test_unique_id(
hass, mqtt_mock_entry_with_yaml_config, scene.DOMAIN, config hass, mqtt_mock_entry_with_yaml_config, scene.DOMAIN, config
@ -175,8 +177,8 @@ async def test_discovery_removal_scene(hass, mqtt_mock_entry_no_yaml_config, cap
async def test_discovery_update_payload(hass, mqtt_mock_entry_no_yaml_config, caplog): async def test_discovery_update_payload(hass, mqtt_mock_entry_no_yaml_config, caplog):
"""Test update of discovered scene.""" """Test update of discovered scene."""
config1 = copy.deepcopy(DEFAULT_CONFIG_LEGACY[scene.DOMAIN]) config1 = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][scene.DOMAIN])
config2 = copy.deepcopy(DEFAULT_CONFIG_LEGACY[scene.DOMAIN]) config2 = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][scene.DOMAIN])
config1["name"] = "Beer" config1["name"] = "Beer"
config2["name"] = "Milk" config2["name"] = "Milk"
config1["payload_on"] = "ON" config1["payload_on"] = "ON"
@ -223,12 +225,14 @@ async def test_discovery_broken(hass, mqtt_mock_entry_no_yaml_config, caplog):
async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path): async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path):
"""Test reloading the MQTT platform.""" """Test reloading the MQTT platform."""
domain = scene.DOMAIN domain = scene.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_reloadable( await help_test_reloadable(
hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config
) )
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path): async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup.""" """Test reloading the MQTT platform with late entry setup."""
domain = scene.DOMAIN domain = scene.DOMAIN
@ -239,17 +243,14 @@ async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
async def test_setup_manual_entity_from_yaml(hass): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = scene.DOMAIN platform = scene.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[platform]) await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
config["name"] = "test" assert hass.states.get(f"{platform}.test")
del config["platform"]
await help_test_setup_manual_entity_from_yaml(hass, platform, config)
assert hass.states.get(f"{platform}.test") is not None
async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path): async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path):
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = scene.DOMAIN domain = scene.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_unload_config_entry_with_platform( await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config
) )

View file

@ -49,7 +49,7 @@ from .test_common import (
help_test_setup_manual_entity_from_yaml, 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,
help_test_update_with_json_attrs_not_dict, help_test_update_with_json_attrs_not_dict,
) )
@ -323,28 +323,28 @@ async def test_availability_when_connection_lost(
): ):
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_with_yaml_config, select.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, select.DOMAIN, DEFAULT_CONFIG
) )
async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config): async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_with_yaml_config, select.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, select.DOMAIN, DEFAULT_CONFIG
) )
async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_config): async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
await help_test_default_availability_payload( await help_test_default_availability_payload(
hass, mqtt_mock_entry_with_yaml_config, select.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, select.DOMAIN, DEFAULT_CONFIG
) )
async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_config): async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability by custom payload with defined topic.""" """Test availability by custom payload with defined topic."""
await help_test_custom_availability_payload( await help_test_custom_availability_payload(
hass, mqtt_mock_entry_with_yaml_config, select.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, select.DOMAIN, DEFAULT_CONFIG
) )
@ -353,7 +353,7 @@ async def test_setting_attribute_via_mqtt_json_message(
): ):
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message( await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_with_yaml_config, select.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, select.DOMAIN, DEFAULT_CONFIG
) )
@ -365,7 +365,7 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
select.DOMAIN, select.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
MQTT_SELECT_ATTRIBUTES_BLOCKED, MQTT_SELECT_ATTRIBUTES_BLOCKED,
) )
@ -373,7 +373,7 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_config): async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_config):
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template( await help_test_setting_attribute_with_template(
hass, mqtt_mock_entry_with_yaml_config, select.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, select.DOMAIN, DEFAULT_CONFIG
) )
@ -386,20 +386,20 @@ async def test_update_with_json_attrs_not_dict(
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
select.DOMAIN, select.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
async def test_update_with_json_attrs_bad_JSON( async def test_update_with_json_attrs_bad_json(
hass, mqtt_mock_entry_with_yaml_config, caplog hass, mqtt_mock_entry_with_yaml_config, caplog
): ):
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_JSON( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
select.DOMAIN, select.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -410,31 +410,31 @@ async def test_discovery_update_attr(hass, mqtt_mock_entry_no_yaml_config, caplo
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
caplog, caplog,
select.DOMAIN, select.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config): async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config):
"""Test unique id option only creates one select per unique_id.""" """Test unique id option only creates one select per unique_id."""
config = { config = {
select.DOMAIN: [ mqtt.DOMAIN: {
{ select.DOMAIN: [
"platform": "mqtt", {
"name": "Test 1", "name": "Test 1",
"state_topic": "test-topic", "state_topic": "test-topic",
"command_topic": "test-topic", "command_topic": "test-topic",
"unique_id": "TOTALLY_UNIQUE", "unique_id": "TOTALLY_UNIQUE",
"options": ["milk", "beer"], "options": ["milk", "beer"],
}, },
{ {
"platform": "mqtt", "name": "Test 2",
"name": "Test 2", "state_topic": "test-topic",
"state_topic": "test-topic", "command_topic": "test-topic",
"command_topic": "test-topic", "unique_id": "TOTALLY_UNIQUE",
"unique_id": "TOTALLY_UNIQUE", "options": ["milk", "beer"],
"options": ["milk", "beer"], },
}, ]
] }
} }
await help_test_unique_id( await help_test_unique_id(
hass, mqtt_mock_entry_with_yaml_config, select.DOMAIN, config hass, mqtt_mock_entry_with_yaml_config, select.DOMAIN, config
@ -443,7 +443,7 @@ async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config):
async def test_discovery_removal_select(hass, mqtt_mock_entry_no_yaml_config, caplog): async def test_discovery_removal_select(hass, mqtt_mock_entry_no_yaml_config, caplog):
"""Test removal of discovered select.""" """Test removal of discovered select."""
data = json.dumps(DEFAULT_CONFIG_LEGACY[select.DOMAIN]) data = json.dumps(DEFAULT_CONFIG[mqtt.DOMAIN][select.DOMAIN])
await help_test_discovery_removal( await help_test_discovery_removal(
hass, mqtt_mock_entry_no_yaml_config, caplog, select.DOMAIN, data hass, mqtt_mock_entry_no_yaml_config, caplog, select.DOMAIN, data
) )
@ -501,42 +501,42 @@ async def test_discovery_broken(hass, mqtt_mock_entry_no_yaml_config, caplog):
async def test_entity_device_info_with_connection(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_with_connection(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT select device registry integration.""" """Test MQTT select device registry integration."""
await help_test_entity_device_info_with_connection( await help_test_entity_device_info_with_connection(
hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_with_identifier(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_with_identifier(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT select device registry integration.""" """Test MQTT select device registry integration."""
await help_test_entity_device_info_with_identifier( await help_test_entity_device_info_with_identifier(
hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_update(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_update(hass, mqtt_mock_entry_no_yaml_config):
"""Test device registry update.""" """Test device registry update."""
await help_test_entity_device_info_update( await help_test_entity_device_info_update(
hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_remove(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_remove(hass, mqtt_mock_entry_no_yaml_config):
"""Test device registry remove.""" """Test device registry remove."""
await help_test_entity_device_info_remove( await help_test_entity_device_info_remove(
hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_config): async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_config):
"""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_LEGACY hass, mqtt_mock_entry_with_yaml_config, select.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT discovery update when entity_id is updated.""" """Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update( await help_test_entity_id_update_discovery_update(
hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG
) )
@ -546,7 +546,7 @@ async def test_entity_debug_info_message(hass, mqtt_mock_entry_no_yaml_config):
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
select.DOMAIN, select.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
select.SERVICE_SELECT_OPTION, select.SERVICE_SELECT_OPTION,
service_parameters={ATTR_OPTION: "beer"}, service_parameters={ATTR_OPTION: "beer"},
command_payload="beer", command_payload="beer",
@ -635,8 +635,8 @@ async def test_publishing_with_custom_encoding(
): ):
"""Test publishing MQTT payload with different encoding.""" """Test publishing MQTT payload with different encoding."""
domain = select.DOMAIN domain = select.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
config["options"] = ["milk", "beer"] config[mqtt.DOMAIN][domain]["options"] = ["milk", "beer"]
await help_test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding(
hass, hass,
@ -655,12 +655,14 @@ async def test_publishing_with_custom_encoding(
async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path): async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path):
"""Test reloading the MQTT platform.""" """Test reloading the MQTT platform."""
domain = select.DOMAIN domain = select.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_reloadable( await help_test_reloadable(
hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config
) )
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path): async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup.""" """Test reloading the MQTT platform with late entry setup."""
domain = select.DOMAIN domain = select.DOMAIN
@ -685,13 +687,13 @@ async def test_encoding_subscribable_topics(
attribute_value, attribute_value,
): ):
"""Test handling of incoming encoded payload.""" """Test handling of incoming encoded payload."""
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY["select"]) 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_with_yaml_config,
caplog, caplog,
"select", select.DOMAIN,
config, config,
topic, topic,
value, value,
@ -703,17 +705,14 @@ async def test_encoding_subscribable_topics(
async def test_setup_manual_entity_from_yaml(hass): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = select.DOMAIN platform = select.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[platform]) await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
config["name"] = "test" assert hass.states.get(f"{platform}.test")
del config["platform"]
await help_test_setup_manual_entity_from_yaml(hass, platform, config)
assert hass.states.get(f"{platform}.test") is not None
async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path): async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path):
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = select.DOMAIN domain = select.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_unload_config_entry_with_platform( await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config
) )

View file

@ -59,7 +59,7 @@ from .test_common import (
help_test_setup_manual_entity_from_yaml, 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,
help_test_update_with_json_attrs_not_dict, help_test_update_with_json_attrs_not_dict,
) )
@ -585,21 +585,21 @@ async def test_availability_when_connection_lost(
): ):
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_with_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
) )
async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config): async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_with_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
) )
async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_config): async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
await help_test_default_availability_payload( await help_test_default_availability_payload(
hass, mqtt_mock_entry_with_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
) )
@ -608,7 +608,7 @@ async def test_default_availability_list_payload(
): ):
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
await help_test_default_availability_list_payload( await help_test_default_availability_list_payload(
hass, mqtt_mock_entry_with_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
) )
@ -617,7 +617,7 @@ async def test_default_availability_list_payload_all(
): ):
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
await help_test_default_availability_list_payload_all( await help_test_default_availability_list_payload_all(
hass, mqtt_mock_entry_with_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
) )
@ -626,34 +626,31 @@ async def test_default_availability_list_payload_any(
): ):
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
await help_test_default_availability_list_payload_any( await help_test_default_availability_list_payload_any(
hass, mqtt_mock_entry_with_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
) )
async def test_default_availability_list_single( async def test_default_availability_list_single(hass, caplog):
hass, mqtt_mock_entry_no_yaml_config, caplog
):
"""Test availability list and availability_topic are mutually exclusive.""" """Test availability list and availability_topic are mutually exclusive."""
await help_test_default_availability_list_single( await help_test_default_availability_list_single(
hass, hass,
mqtt_mock_entry_no_yaml_config,
caplog, caplog,
sensor.DOMAIN, sensor.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_config): async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability by custom payload with defined topic.""" """Test availability by custom payload with defined topic."""
await help_test_custom_availability_payload( await help_test_custom_availability_payload(
hass, mqtt_mock_entry_with_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
) )
async def test_discovery_update_availability(hass, mqtt_mock_entry_no_yaml_config): async def test_discovery_update_availability(hass, mqtt_mock_entry_no_yaml_config):
"""Test availability discovery update.""" """Test availability discovery update."""
await help_test_discovery_update_availability( await help_test_discovery_update_availability(
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
) )
@ -760,7 +757,7 @@ async def test_setting_attribute_via_mqtt_json_message(
): ):
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message( await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_with_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
) )
@ -772,7 +769,7 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
sensor.DOMAIN, sensor.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
MQTT_SENSOR_ATTRIBUTES_BLOCKED, MQTT_SENSOR_ATTRIBUTES_BLOCKED,
) )
@ -780,7 +777,7 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_config): async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_config):
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template( await help_test_setting_attribute_with_template(
hass, mqtt_mock_entry_with_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
) )
@ -793,20 +790,20 @@ async def test_update_with_json_attrs_not_dict(
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
sensor.DOMAIN, sensor.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
async def test_update_with_json_attrs_bad_JSON( async def test_update_with_json_attrs_bad_json(
hass, mqtt_mock_entry_with_yaml_config, caplog hass, mqtt_mock_entry_with_yaml_config, caplog
): ):
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_JSON( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
sensor.DOMAIN, sensor.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -817,27 +814,27 @@ async def test_discovery_update_attr(hass, mqtt_mock_entry_no_yaml_config, caplo
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
caplog, caplog,
sensor.DOMAIN, sensor.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config): async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config):
"""Test unique id option only creates one sensor per unique_id.""" """Test unique id option only creates one sensor per unique_id."""
config = { config = {
sensor.DOMAIN: [ mqtt.DOMAIN: {
{ sensor.DOMAIN: [
"platform": "mqtt", {
"name": "Test 1", "name": "Test 1",
"state_topic": "test-topic", "state_topic": "test-topic",
"unique_id": "TOTALLY_UNIQUE", "unique_id": "TOTALLY_UNIQUE",
}, },
{ {
"platform": "mqtt", "name": "Test 2",
"name": "Test 2", "state_topic": "test-topic",
"state_topic": "test-topic", "unique_id": "TOTALLY_UNIQUE",
"unique_id": "TOTALLY_UNIQUE", },
}, ]
] }
} }
await help_test_unique_id( await help_test_unique_id(
hass, mqtt_mock_entry_with_yaml_config, sensor.DOMAIN, config hass, mqtt_mock_entry_with_yaml_config, sensor.DOMAIN, config
@ -951,42 +948,42 @@ async def test_discovery_broken(hass, mqtt_mock_entry_no_yaml_config, caplog):
async def test_entity_device_info_with_connection(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_with_connection(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT sensor device registry integration.""" """Test MQTT sensor device registry integration."""
await help_test_entity_device_info_with_connection( await help_test_entity_device_info_with_connection(
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_with_identifier(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_with_identifier(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT sensor device registry integration.""" """Test MQTT sensor device registry integration."""
await help_test_entity_device_info_with_identifier( await help_test_entity_device_info_with_identifier(
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_update(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_update(hass, mqtt_mock_entry_no_yaml_config):
"""Test device registry update.""" """Test device registry update."""
await help_test_entity_device_info_update( await help_test_entity_device_info_update(
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_remove(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_remove(hass, mqtt_mock_entry_no_yaml_config):
"""Test device registry remove.""" """Test device registry remove."""
await help_test_entity_device_info_remove( await help_test_entity_device_info_remove(
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_config): async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_config):
"""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_LEGACY hass, mqtt_mock_entry_with_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT discovery update when entity_id is updated.""" """Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update( await help_test_entity_id_update_discovery_update(
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
) )
@ -1021,42 +1018,42 @@ async def test_entity_device_info_with_hub(hass, mqtt_mock_entry_no_yaml_config)
async def test_entity_debug_info(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_debug_info(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT sensor debug info.""" """Test MQTT sensor debug info."""
await help_test_entity_debug_info( await help_test_entity_debug_info(
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_debug_info_max_messages(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_debug_info_max_messages(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT sensor debug info.""" """Test MQTT sensor debug info."""
await help_test_entity_debug_info_max_messages( await help_test_entity_debug_info_max_messages(
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_debug_info_message(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_debug_info_message(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT debug info.""" """Test MQTT debug info."""
await help_test_entity_debug_info_message( await help_test_entity_debug_info_message(
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG_LEGACY, None hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG, None
) )
async def test_entity_debug_info_remove(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_debug_info_remove(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT sensor debug info.""" """Test MQTT sensor debug info."""
await help_test_entity_debug_info_remove( await help_test_entity_debug_info_remove(
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_debug_info_update_entity_id(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_debug_info_update_entity_id(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT sensor debug info.""" """Test MQTT sensor debug info."""
await help_test_entity_debug_info_update_entity_id( await help_test_entity_debug_info_update_entity_id(
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_disabled_by_default(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_disabled_by_default(hass, mqtt_mock_entry_no_yaml_config):
"""Test entity disabled by default.""" """Test entity disabled by default."""
await help_test_entity_disabled_by_default( await help_test_entity_disabled_by_default(
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
) )
@ -1064,7 +1061,7 @@ async def test_entity_disabled_by_default(hass, mqtt_mock_entry_no_yaml_config):
async def test_entity_category(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_category(hass, mqtt_mock_entry_no_yaml_config):
"""Test entity category.""" """Test entity category."""
await help_test_entity_category( await help_test_entity_category(
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
) )
@ -1101,12 +1098,14 @@ async def test_value_template_with_entity_id(hass, mqtt_mock_entry_with_yaml_con
async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path): async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path):
"""Test reloading the MQTT platform.""" """Test reloading the MQTT platform."""
domain = sensor.DOMAIN domain = sensor.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_reloadable( await help_test_reloadable(
hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config
) )
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path): async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup.""" """Test reloading the MQTT platform with late entry setup."""
domain = sensor.DOMAIN domain = sensor.DOMAIN
@ -1230,7 +1229,7 @@ async def test_encoding_subscribable_topics(
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
sensor.DOMAIN, sensor.DOMAIN,
DEFAULT_CONFIG_LEGACY[sensor.DOMAIN], DEFAULT_CONFIG[mqtt.DOMAIN][sensor.DOMAIN],
topic, topic,
value, value,
attribute, attribute,
@ -1242,17 +1241,14 @@ async def test_encoding_subscribable_topics(
async def test_setup_manual_entity_from_yaml(hass): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = sensor.DOMAIN platform = sensor.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[platform]) await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
config["name"] = "test" assert hass.states.get(f"{platform}.test")
del config["platform"]
await help_test_setup_manual_entity_from_yaml(hass, platform, config)
assert hass.states.get(f"{platform}.test") is not None
async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path): async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path):
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = sensor.DOMAIN domain = sensor.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_unload_config_entry_with_platform( await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config
) )

View file

@ -46,7 +46,7 @@ from .test_common import (
help_test_setup_manual_entity_from_yaml, 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,
help_test_update_with_json_attrs_not_dict, help_test_update_with_json_attrs_not_dict,
) )
@ -457,27 +457,28 @@ async def test_availability_when_connection_lost(
): ):
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_with_yaml_config, siren.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, siren.DOMAIN, DEFAULT_CONFIG
) )
async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config): async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_with_yaml_config, siren.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, siren.DOMAIN, DEFAULT_CONFIG
) )
async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_config): async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
config = { config = {
siren.DOMAIN: { mqtt.DOMAIN: {
"platform": "mqtt", siren.DOMAIN: {
"name": "test", "name": "test",
"state_topic": "state-topic", "state_topic": "state-topic",
"command_topic": "command-topic", "command_topic": "command-topic",
"payload_on": 1, "payload_on": 1,
"payload_off": 0, "payload_off": 0,
}
} }
} }
@ -495,13 +496,14 @@ async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_conf
async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_config): async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability by custom payload with defined topic.""" """Test availability by custom payload with defined topic."""
config = { config = {
siren.DOMAIN: { mqtt.DOMAIN: {
"platform": "mqtt", siren.DOMAIN: {
"name": "test", "name": "test",
"state_topic": "state-topic", "state_topic": "state-topic",
"command_topic": "command-topic", "command_topic": "command-topic",
"payload_on": 1, "payload_on": 1,
"payload_off": 0, "payload_off": 0,
}
} }
} }
@ -558,7 +560,7 @@ async def test_setting_attribute_via_mqtt_json_message(
): ):
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message( await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_with_yaml_config, siren.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, siren.DOMAIN, DEFAULT_CONFIG
) )
@ -567,14 +569,14 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
): ):
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_blocked_attribute_via_mqtt_json_message( await help_test_setting_blocked_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG_LEGACY, {} hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG, {}
) )
async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_config): async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_config):
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template( await help_test_setting_attribute_with_template(
hass, mqtt_mock_entry_with_yaml_config, siren.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, siren.DOMAIN, DEFAULT_CONFIG
) )
@ -587,20 +589,20 @@ async def test_update_with_json_attrs_not_dict(
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
siren.DOMAIN, siren.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
async def test_update_with_json_attrs_bad_JSON( async def test_update_with_json_attrs_bad_json(
hass, mqtt_mock_entry_with_yaml_config, caplog hass, mqtt_mock_entry_with_yaml_config, caplog
): ):
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_JSON( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
siren.DOMAIN, siren.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -611,29 +613,29 @@ async def test_discovery_update_attr(hass, mqtt_mock_entry_no_yaml_config, caplo
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
caplog, caplog,
siren.DOMAIN, siren.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config): async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config):
"""Test unique id option only creates one siren per unique_id.""" """Test unique id option only creates one siren per unique_id."""
config = { config = {
siren.DOMAIN: [ mqtt.DOMAIN: {
{ siren.DOMAIN: [
"platform": "mqtt", {
"name": "Test 1", "name": "Test 1",
"state_topic": "test-topic", "state_topic": "test-topic",
"command_topic": "command-topic", "command_topic": "command-topic",
"unique_id": "TOTALLY_UNIQUE", "unique_id": "TOTALLY_UNIQUE",
}, },
{ {
"platform": "mqtt", "name": "Test 2",
"name": "Test 2", "state_topic": "test-topic",
"state_topic": "test-topic", "command_topic": "command-topic",
"command_topic": "command-topic", "unique_id": "TOTALLY_UNIQUE",
"unique_id": "TOTALLY_UNIQUE", },
}, ]
] }
} }
await help_test_unique_id( await help_test_unique_id(
hass, mqtt_mock_entry_with_yaml_config, siren.DOMAIN, config hass, mqtt_mock_entry_with_yaml_config, siren.DOMAIN, config
@ -656,8 +658,8 @@ async def test_discovery_update_siren_topic_template(
hass, mqtt_mock_entry_no_yaml_config, caplog hass, mqtt_mock_entry_no_yaml_config, caplog
): ):
"""Test update of discovered siren.""" """Test update of discovered siren."""
config1 = copy.deepcopy(DEFAULT_CONFIG_LEGACY[siren.DOMAIN]) config1 = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][siren.DOMAIN])
config2 = copy.deepcopy(DEFAULT_CONFIG_LEGACY[siren.DOMAIN]) config2 = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][siren.DOMAIN])
config1["name"] = "Beer" config1["name"] = "Beer"
config2["name"] = "Milk" config2["name"] = "Milk"
config1["state_topic"] = "siren/state1" config1["state_topic"] = "siren/state1"
@ -693,8 +695,8 @@ async def test_discovery_update_siren_template(
hass, mqtt_mock_entry_no_yaml_config, caplog hass, mqtt_mock_entry_no_yaml_config, caplog
): ):
"""Test update of discovered siren.""" """Test update of discovered siren."""
config1 = copy.deepcopy(DEFAULT_CONFIG_LEGACY[siren.DOMAIN]) config1 = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][siren.DOMAIN])
config2 = copy.deepcopy(DEFAULT_CONFIG_LEGACY[siren.DOMAIN]) config2 = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][siren.DOMAIN])
config1["name"] = "Beer" config1["name"] = "Beer"
config2["name"] = "Milk" config2["name"] = "Milk"
config1["state_topic"] = "siren/state1" config1["state_topic"] = "siren/state1"
@ -844,42 +846,42 @@ async def test_discovery_broken(hass, mqtt_mock_entry_no_yaml_config, caplog):
async def test_entity_device_info_with_connection(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_with_connection(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT siren device registry integration.""" """Test MQTT siren device registry integration."""
await help_test_entity_device_info_with_connection( await help_test_entity_device_info_with_connection(
hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_with_identifier(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_with_identifier(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT siren device registry integration.""" """Test MQTT siren device registry integration."""
await help_test_entity_device_info_with_identifier( await help_test_entity_device_info_with_identifier(
hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_update(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_update(hass, mqtt_mock_entry_no_yaml_config):
"""Test device registry update.""" """Test device registry update."""
await help_test_entity_device_info_update( await help_test_entity_device_info_update(
hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_remove(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_remove(hass, mqtt_mock_entry_no_yaml_config):
"""Test device registry remove.""" """Test device registry remove."""
await help_test_entity_device_info_remove( await help_test_entity_device_info_remove(
hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_config): async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_config):
"""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_LEGACY hass, mqtt_mock_entry_with_yaml_config, siren.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT discovery update when entity_id is updated.""" """Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update( await help_test_entity_id_update_discovery_update(
hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG
) )
@ -889,7 +891,7 @@ async def test_entity_debug_info_message(hass, mqtt_mock_entry_no_yaml_config):
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
siren.DOMAIN, siren.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
siren.SERVICE_TURN_ON, siren.SERVICE_TURN_ON,
command_payload='{"state":"ON"}', command_payload='{"state":"ON"}',
) )
@ -926,8 +928,8 @@ async def test_publishing_with_custom_encoding(
): ):
"""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
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[domain]) config = copy.deepcopy(DEFAULT_CONFIG)
config[siren.ATTR_AVAILABLE_TONES] = ["siren", "xylophone"] config[mqtt.DOMAIN][domain][siren.ATTR_AVAILABLE_TONES] = ["siren", "xylophone"]
await help_test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding(
hass, hass,
@ -946,12 +948,14 @@ async def test_publishing_with_custom_encoding(
async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path): async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path):
"""Test reloading the MQTT platform.""" """Test reloading the MQTT platform."""
domain = siren.DOMAIN domain = siren.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_reloadable( await help_test_reloadable(
hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config
) )
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path): async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup.""" """Test reloading the MQTT platform with late entry setup."""
domain = siren.DOMAIN domain = siren.DOMAIN
@ -980,7 +984,7 @@ async def test_encoding_subscribable_topics(
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
siren.DOMAIN, siren.DOMAIN,
DEFAULT_CONFIG_LEGACY[siren.DOMAIN], DEFAULT_CONFIG[mqtt.DOMAIN][siren.DOMAIN],
topic, topic,
value, value,
attribute, attribute,
@ -991,17 +995,14 @@ async def test_encoding_subscribable_topics(
async def test_setup_manual_entity_from_yaml(hass): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = siren.DOMAIN platform = siren.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[platform]) await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
config["name"] = "test" assert hass.states.get(f"{platform}.test")
del config["platform"]
await help_test_setup_manual_entity_from_yaml(hass, platform, config)
assert hass.states.get(f"{platform}.test") is not None
async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path): async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path):
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = siren.DOMAIN domain = siren.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_unload_config_entry_with_platform( await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config
) )

View file

@ -61,7 +61,7 @@ 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, 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,
) )
@ -375,28 +375,28 @@ async def test_availability_when_connection_lost(
): ):
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_with_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2_LEGACY hass, mqtt_mock_entry_with_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
) )
async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config): async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_with_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2_LEGACY hass, mqtt_mock_entry_with_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
) )
async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_config): async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
await help_test_default_availability_payload( await help_test_default_availability_payload(
hass, mqtt_mock_entry_with_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2_LEGACY hass, mqtt_mock_entry_with_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
) )
async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_config): async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability by custom payload with defined topic.""" """Test availability by custom payload with defined topic."""
await help_test_custom_availability_payload( await help_test_custom_availability_payload(
hass, mqtt_mock_entry_with_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2_LEGACY hass, mqtt_mock_entry_with_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
) )
@ -405,7 +405,7 @@ async def test_setting_attribute_via_mqtt_json_message(
): ):
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message( await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_with_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2_LEGACY hass, mqtt_mock_entry_with_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
) )
@ -417,7 +417,7 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
vacuum.DOMAIN, vacuum.DOMAIN,
DEFAULT_CONFIG_2_LEGACY, DEFAULT_CONFIG_2,
MQTT_VACUUM_ATTRIBUTES_BLOCKED, MQTT_VACUUM_ATTRIBUTES_BLOCKED,
) )
@ -425,7 +425,7 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_config): async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_config):
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template( await help_test_setting_attribute_with_template(
hass, mqtt_mock_entry_with_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2_LEGACY hass, mqtt_mock_entry_with_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
) )
@ -438,7 +438,7 @@ async def test_update_with_json_attrs_not_dict(
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
vacuum.DOMAIN, vacuum.DOMAIN,
DEFAULT_CONFIG_2_LEGACY, DEFAULT_CONFIG_2,
) )
@ -446,12 +446,12 @@ async def test_update_with_json_attrs_bad_json(
hass, mqtt_mock_entry_with_yaml_config, caplog hass, mqtt_mock_entry_with_yaml_config, caplog
): ):
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_JSON( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
vacuum.DOMAIN, vacuum.DOMAIN,
DEFAULT_CONFIG_2_LEGACY, DEFAULT_CONFIG_2,
) )
@ -462,29 +462,29 @@ async def test_discovery_update_attr(hass, mqtt_mock_entry_no_yaml_config, caplo
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
caplog, caplog,
vacuum.DOMAIN, vacuum.DOMAIN,
DEFAULT_CONFIG_2_LEGACY, DEFAULT_CONFIG_2,
) )
async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config): async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config):
"""Test unique id option only creates one vacuum per unique_id.""" """Test unique id option only creates one vacuum per unique_id."""
config = { config = {
vacuum.DOMAIN: [ mqtt.DOMAIN: {
{ vacuum.DOMAIN: [
"platform": "mqtt", {
"schema": "state", "schema": "state",
"name": "Test 1", "name": "Test 1",
"command_topic": "command-topic", "command_topic": "command-topic",
"unique_id": "TOTALLY_UNIQUE", "unique_id": "TOTALLY_UNIQUE",
}, },
{ {
"platform": "mqtt", "schema": "state",
"schema": "state", "name": "Test 2",
"name": "Test 2", "command_topic": "command-topic",
"command_topic": "command-topic", "unique_id": "TOTALLY_UNIQUE",
"unique_id": "TOTALLY_UNIQUE", },
}, ]
] }
} }
await help_test_unique_id( await help_test_unique_id(
hass, mqtt_mock_entry_with_yaml_config, vacuum.DOMAIN, config hass, mqtt_mock_entry_with_yaml_config, vacuum.DOMAIN, config
@ -539,42 +539,42 @@ async def test_discovery_broken(hass, mqtt_mock_entry_no_yaml_config, caplog):
async def test_entity_device_info_with_connection(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_with_connection(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT vacuum device registry integration.""" """Test MQTT vacuum device registry integration."""
await help_test_entity_device_info_with_connection( await help_test_entity_device_info_with_connection(
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2_LEGACY hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
) )
async def test_entity_device_info_with_identifier(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_with_identifier(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT vacuum device registry integration.""" """Test MQTT vacuum device registry integration."""
await help_test_entity_device_info_with_identifier( await help_test_entity_device_info_with_identifier(
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2_LEGACY hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
) )
async def test_entity_device_info_update(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_update(hass, mqtt_mock_entry_no_yaml_config):
"""Test device registry update.""" """Test device registry update."""
await help_test_entity_device_info_update( await help_test_entity_device_info_update(
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2_LEGACY hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
) )
async def test_entity_device_info_remove(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_remove(hass, mqtt_mock_entry_no_yaml_config):
"""Test device registry remove.""" """Test device registry remove."""
await help_test_entity_device_info_remove( await help_test_entity_device_info_remove(
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2_LEGACY hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
) )
async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_config): async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_config):
"""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_LEGACY hass, mqtt_mock_entry_with_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
) )
async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT discovery update when entity_id is updated.""" """Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update( await help_test_entity_id_update_discovery_update(
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2_LEGACY hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
) )
@ -584,7 +584,7 @@ async def test_entity_debug_info_message(hass, mqtt_mock_entry_no_yaml_config):
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
vacuum.DOMAIN, vacuum.DOMAIN,
DEFAULT_CONFIG_2_LEGACY, DEFAULT_CONFIG_2,
vacuum.SERVICE_START, vacuum.SERVICE_START,
command_payload="start", command_payload="start",
state_payload="{}", state_payload="{}",
@ -643,8 +643,8 @@ async def test_publishing_with_custom_encoding(
): ):
"""Test publishing MQTT payload with different encoding.""" """Test publishing MQTT payload with different encoding."""
domain = vacuum.DOMAIN domain = vacuum.DOMAIN
config = deepcopy(DEFAULT_CONFIG_LEGACY[domain]) config = deepcopy(DEFAULT_CONFIG)
config["supported_features"] = [ config[mqtt.DOMAIN][domain]["supported_features"] = [
"battery", "battery",
"clean_spot", "clean_spot",
"fan_speed", "fan_speed",
@ -674,12 +674,14 @@ async def test_publishing_with_custom_encoding(
async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path): async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path):
"""Test reloading the MQTT platform.""" """Test reloading the MQTT platform."""
domain = vacuum.DOMAIN domain = vacuum.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_reloadable( await help_test_reloadable(
hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config
) )
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path): async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup.""" """Test reloading the MQTT platform with late entry setup."""
domain = vacuum.DOMAIN domain = vacuum.DOMAIN
@ -719,7 +721,7 @@ async def test_encoding_subscribable_topics(
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
vacuum.DOMAIN, vacuum.DOMAIN,
DEFAULT_CONFIG_LEGACY[vacuum.DOMAIN], DEFAULT_CONFIG[mqtt.DOMAIN][vacuum.DOMAIN],
topic, topic,
value, value,
attribute, attribute,
@ -731,11 +733,8 @@ async def test_encoding_subscribable_topics(
async def test_setup_manual_entity_from_yaml(hass): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = vacuum.DOMAIN platform = vacuum.DOMAIN
config = deepcopy(DEFAULT_CONFIG_LEGACY[platform]) await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
config["name"] = "test" assert hass.states.get(f"{platform}.mqtttest")
del config["platform"]
await help_test_setup_manual_entity_from_yaml(hass, platform, config)
assert hass.states.get(f"{platform}.test") is not None
# Test deprecated YAML configuration under the platform key # Test deprecated YAML configuration under the platform key

View file

@ -43,7 +43,7 @@ from .test_common import (
help_test_setup_manual_entity_from_yaml, 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,
help_test_update_with_json_attrs_not_dict, help_test_update_with_json_attrs_not_dict,
) )
@ -227,27 +227,28 @@ async def test_availability_when_connection_lost(
): ):
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_with_yaml_config, switch.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, switch.DOMAIN, DEFAULT_CONFIG
) )
async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config): async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_with_yaml_config, switch.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, switch.DOMAIN, DEFAULT_CONFIG
) )
async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_config): async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
config = { config = {
switch.DOMAIN: { mqtt.DOMAIN: {
"platform": "mqtt", switch.DOMAIN: {
"name": "test", "name": "test",
"state_topic": "state-topic", "state_topic": "state-topic",
"command_topic": "command-topic", "command_topic": "command-topic",
"payload_on": 1, "payload_on": 1,
"payload_off": 0, "payload_off": 0,
}
} }
} }
@ -265,13 +266,14 @@ async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_conf
async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_config): async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability by custom payload with defined topic.""" """Test availability by custom payload with defined topic."""
config = { config = {
switch.DOMAIN: { mqtt.DOMAIN: {
"platform": "mqtt", switch.DOMAIN: {
"name": "test", "name": "test",
"state_topic": "state-topic", "state_topic": "state-topic",
"command_topic": "command-topic", "command_topic": "command-topic",
"payload_on": 1, "payload_on": 1,
"payload_off": 0, "payload_off": 0,
}
} }
} }
@ -328,7 +330,7 @@ async def test_setting_attribute_via_mqtt_json_message(
): ):
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message( await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_with_yaml_config, switch.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, switch.DOMAIN, DEFAULT_CONFIG
) )
@ -337,14 +339,14 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
): ):
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_blocked_attribute_via_mqtt_json_message( await help_test_setting_blocked_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG_LEGACY, {} hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG, {}
) )
async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_config): async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_config):
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template( await help_test_setting_attribute_with_template(
hass, mqtt_mock_entry_with_yaml_config, switch.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_with_yaml_config, switch.DOMAIN, DEFAULT_CONFIG
) )
@ -357,20 +359,20 @@ async def test_update_with_json_attrs_not_dict(
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
switch.DOMAIN, switch.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
async def test_update_with_json_attrs_bad_JSON( async def test_update_with_json_attrs_bad_json(
hass, mqtt_mock_entry_with_yaml_config, caplog hass, mqtt_mock_entry_with_yaml_config, caplog
): ):
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_JSON( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
switch.DOMAIN, switch.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
@ -381,29 +383,29 @@ async def test_discovery_update_attr(hass, mqtt_mock_entry_no_yaml_config, caplo
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
caplog, caplog,
switch.DOMAIN, switch.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
) )
async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config): async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config):
"""Test unique id option only creates one switch per unique_id.""" """Test unique id option only creates one switch per unique_id."""
config = { config = {
switch.DOMAIN: [ mqtt.DOMAIN: {
{ switch.DOMAIN: [
"platform": "mqtt", {
"name": "Test 1", "name": "Test 1",
"state_topic": "test-topic", "state_topic": "test-topic",
"command_topic": "command-topic", "command_topic": "command-topic",
"unique_id": "TOTALLY_UNIQUE", "unique_id": "TOTALLY_UNIQUE",
}, },
{ {
"platform": "mqtt", "name": "Test 2",
"name": "Test 2", "state_topic": "test-topic",
"state_topic": "test-topic", "command_topic": "command-topic",
"command_topic": "command-topic", "unique_id": "TOTALLY_UNIQUE",
"unique_id": "TOTALLY_UNIQUE", },
}, ]
] }
} }
await help_test_unique_id( await help_test_unique_id(
hass, mqtt_mock_entry_with_yaml_config, switch.DOMAIN, config hass, mqtt_mock_entry_with_yaml_config, switch.DOMAIN, config
@ -426,8 +428,8 @@ async def test_discovery_update_switch_topic_template(
hass, mqtt_mock_entry_no_yaml_config, caplog hass, mqtt_mock_entry_no_yaml_config, caplog
): ):
"""Test update of discovered switch.""" """Test update of discovered switch."""
config1 = copy.deepcopy(DEFAULT_CONFIG_LEGACY[switch.DOMAIN]) config1 = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][switch.DOMAIN])
config2 = copy.deepcopy(DEFAULT_CONFIG_LEGACY[switch.DOMAIN]) config2 = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][switch.DOMAIN])
config1["name"] = "Beer" config1["name"] = "Beer"
config2["name"] = "Milk" config2["name"] = "Milk"
config1["state_topic"] = "switch/state1" config1["state_topic"] = "switch/state1"
@ -463,8 +465,8 @@ async def test_discovery_update_switch_template(
hass, mqtt_mock_entry_no_yaml_config, caplog hass, mqtt_mock_entry_no_yaml_config, caplog
): ):
"""Test update of discovered switch.""" """Test update of discovered switch."""
config1 = copy.deepcopy(DEFAULT_CONFIG_LEGACY[switch.DOMAIN]) config1 = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][switch.DOMAIN])
config2 = copy.deepcopy(DEFAULT_CONFIG_LEGACY[switch.DOMAIN]) config2 = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][switch.DOMAIN])
config1["name"] = "Beer" config1["name"] = "Beer"
config2["name"] = "Milk" config2["name"] = "Milk"
config1["state_topic"] = "switch/state1" config1["state_topic"] = "switch/state1"
@ -534,42 +536,42 @@ async def test_discovery_broken(hass, mqtt_mock_entry_no_yaml_config, caplog):
async def test_entity_device_info_with_connection(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_with_connection(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT switch device registry integration.""" """Test MQTT switch device registry integration."""
await help_test_entity_device_info_with_connection( await help_test_entity_device_info_with_connection(
hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_with_identifier(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_with_identifier(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT switch device registry integration.""" """Test MQTT switch device registry integration."""
await help_test_entity_device_info_with_identifier( await help_test_entity_device_info_with_identifier(
hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_update(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_update(hass, mqtt_mock_entry_no_yaml_config):
"""Test device registry update.""" """Test device registry update."""
await help_test_entity_device_info_update( await help_test_entity_device_info_update(
hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_remove(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_device_info_remove(hass, mqtt_mock_entry_no_yaml_config):
"""Test device registry remove.""" """Test device registry remove."""
await help_test_entity_device_info_remove( await help_test_entity_device_info_remove(
hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_config): async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_config):
"""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_LEGACY hass, mqtt_mock_entry_with_yaml_config, switch.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_config): async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT discovery update when entity_id is updated.""" """Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update( await help_test_entity_id_update_discovery_update(
hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG_LEGACY hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG
) )
@ -579,7 +581,7 @@ async def test_entity_debug_info_message(hass, mqtt_mock_entry_no_yaml_config):
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry_no_yaml_config,
switch.DOMAIN, switch.DOMAIN,
DEFAULT_CONFIG_LEGACY, DEFAULT_CONFIG,
switch.SERVICE_TURN_ON, switch.SERVICE_TURN_ON,
) )
@ -615,7 +617,7 @@ async def test_publishing_with_custom_encoding(
): ):
"""Test publishing MQTT payload with different encoding.""" """Test publishing MQTT payload with different encoding."""
domain = switch.DOMAIN domain = switch.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding(
hass, hass,
@ -634,12 +636,14 @@ async def test_publishing_with_custom_encoding(
async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path): async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path):
"""Test reloading the MQTT platform.""" """Test reloading the MQTT platform."""
domain = switch.DOMAIN domain = switch.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_reloadable( await help_test_reloadable(
hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config
) )
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path): async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup.""" """Test reloading the MQTT platform with late entry setup."""
domain = switch.DOMAIN domain = switch.DOMAIN
@ -668,7 +672,7 @@ async def test_encoding_subscribable_topics(
mqtt_mock_entry_with_yaml_config, mqtt_mock_entry_with_yaml_config,
caplog, caplog,
switch.DOMAIN, switch.DOMAIN,
DEFAULT_CONFIG_LEGACY[switch.DOMAIN], DEFAULT_CONFIG[mqtt.DOMAIN][switch.DOMAIN],
topic, topic,
value, value,
attribute, attribute,
@ -679,17 +683,14 @@ async def test_encoding_subscribable_topics(
async def test_setup_manual_entity_from_yaml(hass): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = switch.DOMAIN platform = switch.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[platform]) await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
config["name"] = "test" assert hass.states.get(f"{platform}.test")
del config["platform"]
await help_test_setup_manual_entity_from_yaml(hass, platform, config)
assert hass.states.get(f"{platform}.test") is not None
async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path): async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path):
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = switch.DOMAIN domain = switch.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain] config = DEFAULT_CONFIG
await help_test_unload_config_entry_with_platform( await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config
) )