Update MQTT tests to use the config entry setup (#72373)

* New testframework and tests for fan platform

* Merge test_common_new to test_common

* Add alarm_control_panel

* Add binary_sensor

* Add button

* Add camera

* Add climate

* Add config_flow

* Add cover

* Add device_tracker_disovery

* Add device_trigger

* Add diagnostics

* Add discovery

* Add humidifier

* Add init

* Add lecacy_vacuum

* Add light_json

* Add light_template

* Add light

* Add lock

* Add number

* Add scene

* Add select

* Add sensor

* Add siren

* Add state_vacuum

* Add subscription

* Add switch

* Add tag

* Add trigger

* Add missed tests

* Add another missed test

* Add device_tracker

* Remove commented out code

* Correct tests according comments

* Improve mqtt_mock_entry and recover tests

* Split fixtures with and without yaml setup

* Update fixtures manual_mqtt

* Update fixtures mqtt_json

* Fix test tasmota

* Update fixture mqtt_room

* Revert fixture changes, improve test

* re-add test
This commit is contained in:
Jan Bouwhuis
2022-06-02 14:24:46 +02:00
committed by GitHub
parent 756988fe20
commit 52561ce076
36 changed files with 3612 additions and 1692 deletions

View File

@ -162,7 +162,7 @@ class JsonValidator:
return json.loads(self.jsondata) == json.loads(other)
async def test_fail_setup_if_no_command_topic(hass, mqtt_mock):
async def test_fail_setup_if_no_command_topic(hass, mqtt_mock_entry_no_yaml_config):
"""Test if setup fails with no command topic."""
assert await async_setup_component(
hass,
@ -170,11 +170,14 @@ async def test_fail_setup_if_no_command_topic(hass, mqtt_mock):
{light.DOMAIN: {"platform": "mqtt", "schema": "json", "name": "test"}},
)
await hass.async_block_till_done()
await mqtt_mock_entry_no_yaml_config()
assert hass.states.get("light.test") is None
@pytest.mark.parametrize("deprecated", ("color_temp", "hs", "rgb", "white_value", "xy"))
async def test_fail_setup_if_color_mode_deprecated(hass, mqtt_mock, deprecated):
async def test_fail_setup_if_color_mode_deprecated(
hass, mqtt_mock_entry_no_yaml_config, deprecated
):
"""Test if setup fails if color mode is combined with deprecated config keys."""
supported_color_modes = ["color_temp", "hs", "rgb", "rgbw", "rgbww", "xy"]
@ -196,6 +199,7 @@ async def test_fail_setup_if_color_mode_deprecated(hass, mqtt_mock, deprecated):
config,
)
await hass.async_block_till_done()
await mqtt_mock_entry_no_yaml_config()
assert hass.states.get("light.test") is None
@ -203,7 +207,7 @@ async def test_fail_setup_if_color_mode_deprecated(hass, mqtt_mock, deprecated):
"supported_color_modes", [["onoff", "rgb"], ["brightness", "rgb"], ["unknown"]]
)
async def test_fail_setup_if_color_modes_invalid(
hass, mqtt_mock, supported_color_modes
hass, mqtt_mock_entry_no_yaml_config, supported_color_modes
):
"""Test if setup fails if supported color modes is invalid."""
config = {
@ -223,10 +227,11 @@ async def test_fail_setup_if_color_modes_invalid(
config,
)
await hass.async_block_till_done()
await mqtt_mock_entry_no_yaml_config()
assert hass.states.get("light.test") is None
async def test_rgb_light(hass, mqtt_mock):
async def test_rgb_light(hass, mqtt_mock_entry_with_yaml_config):
"""Test RGB light flags brightness support."""
assert await async_setup_component(
hass,
@ -242,6 +247,7 @@ async def test_rgb_light(hass, mqtt_mock):
},
)
await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config()
state = hass.states.get("light.test")
expected_features = (
@ -253,7 +259,9 @@ async def test_rgb_light(hass, mqtt_mock):
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == expected_features
async def test_no_color_brightness_color_temp_white_val_if_no_topics(hass, mqtt_mock):
async def test_no_color_brightness_color_temp_white_val_if_no_topics(
hass, mqtt_mock_entry_with_yaml_config
):
"""Test for no RGB, brightness, color temp, effect, white val or XY."""
assert await async_setup_component(
hass,
@ -269,6 +277,7 @@ async def test_no_color_brightness_color_temp_white_val_if_no_topics(hass, mqtt_
},
)
await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config()
state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN
@ -305,7 +314,7 @@ async def test_no_color_brightness_color_temp_white_val_if_no_topics(hass, mqtt_
assert state.state == STATE_UNKNOWN
async def test_controlling_state_via_topic(hass, mqtt_mock):
async def test_controlling_state_via_topic(hass, mqtt_mock_entry_with_yaml_config):
"""Test the controlling of the state via topic."""
assert await async_setup_component(
hass,
@ -329,6 +338,7 @@ async def test_controlling_state_via_topic(hass, mqtt_mock):
},
)
await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config()
state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN
@ -434,7 +444,9 @@ async def test_controlling_state_via_topic(hass, mqtt_mock):
assert light_state.attributes.get("white_value") == 155
async def test_controlling_state_via_topic2(hass, mqtt_mock, caplog):
async def test_controlling_state_via_topic2(
hass, mqtt_mock_entry_with_yaml_config, caplog
):
"""Test the controlling of the state via topic for a light supporting color mode."""
supported_color_modes = ["color_temp", "hs", "rgb", "rgbw", "rgbww", "xy"]
@ -457,6 +469,7 @@ async def test_controlling_state_via_topic2(hass, mqtt_mock, caplog):
},
)
await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config()
state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN
@ -602,7 +615,9 @@ async def test_controlling_state_via_topic2(hass, mqtt_mock, caplog):
assert "Invalid or incomplete color value received" in caplog.text
async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
async def test_sending_mqtt_commands_and_optimistic(
hass, mqtt_mock_entry_with_yaml_config
):
"""Test the sending of command in optimistic mode."""
fake_state = ha.State(
"light.test",
@ -641,6 +656,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
},
)
await hass.async_block_till_done()
mqtt_mock = await mqtt_mock_entry_with_yaml_config()
state = hass.states.get("light.test")
assert state.state == STATE_ON
@ -745,7 +761,9 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
assert state.attributes["xy_color"] == (0.611, 0.375)
async def test_sending_mqtt_commands_and_optimistic2(hass, mqtt_mock):
async def test_sending_mqtt_commands_and_optimistic2(
hass, mqtt_mock_entry_with_yaml_config
):
"""Test the sending of command in optimistic mode for a light supporting color mode."""
supported_color_modes = ["color_temp", "hs", "rgb", "rgbw", "rgbww", "xy"]
fake_state = ha.State(
@ -783,6 +801,7 @@ async def test_sending_mqtt_commands_and_optimistic2(hass, mqtt_mock):
},
)
await hass.async_block_till_done()
mqtt_mock = await mqtt_mock_entry_with_yaml_config()
state = hass.states.get("light.test")
assert state.state == STATE_ON
@ -953,7 +972,7 @@ async def test_sending_mqtt_commands_and_optimistic2(hass, mqtt_mock):
mqtt_mock.async_publish.reset_mock()
async def test_sending_hs_color(hass, mqtt_mock):
async def test_sending_hs_color(hass, mqtt_mock_entry_with_yaml_config):
"""Test light.turn_on with hs color sends hs color parameters."""
assert await async_setup_component(
hass,
@ -971,6 +990,7 @@ async def test_sending_hs_color(hass, mqtt_mock):
},
)
await hass.async_block_till_done()
mqtt_mock = await mqtt_mock_entry_with_yaml_config()
state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN
@ -1018,7 +1038,7 @@ async def test_sending_hs_color(hass, mqtt_mock):
)
async def test_sending_rgb_color_no_brightness(hass, mqtt_mock):
async def test_sending_rgb_color_no_brightness(hass, mqtt_mock_entry_with_yaml_config):
"""Test light.turn_on with hs color sends rgb color parameters."""
assert await async_setup_component(
hass,
@ -1034,6 +1054,7 @@ async def test_sending_rgb_color_no_brightness(hass, mqtt_mock):
},
)
await hass.async_block_till_done()
mqtt_mock = await mqtt_mock_entry_with_yaml_config()
state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN
@ -1071,7 +1092,7 @@ async def test_sending_rgb_color_no_brightness(hass, mqtt_mock):
)
async def test_sending_rgb_color_no_brightness2(hass, mqtt_mock):
async def test_sending_rgb_color_no_brightness2(hass, mqtt_mock_entry_with_yaml_config):
"""Test light.turn_on with hs color sends rgb color parameters."""
supported_color_modes = ["rgb", "rgbw", "rgbww"]
assert await async_setup_component(
@ -1089,6 +1110,7 @@ async def test_sending_rgb_color_no_brightness2(hass, mqtt_mock):
},
)
await hass.async_block_till_done()
mqtt_mock = await mqtt_mock_entry_with_yaml_config()
state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN
@ -1148,7 +1170,9 @@ async def test_sending_rgb_color_no_brightness2(hass, mqtt_mock):
)
async def test_sending_rgb_color_with_brightness(hass, mqtt_mock):
async def test_sending_rgb_color_with_brightness(
hass, mqtt_mock_entry_with_yaml_config
):
"""Test light.turn_on with hs color sends rgb color parameters."""
assert await async_setup_component(
hass,
@ -1166,6 +1190,7 @@ async def test_sending_rgb_color_with_brightness(hass, mqtt_mock):
},
)
await hass.async_block_till_done()
mqtt_mock = await mqtt_mock_entry_with_yaml_config()
state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN
@ -1218,7 +1243,9 @@ async def test_sending_rgb_color_with_brightness(hass, mqtt_mock):
)
async def test_sending_rgb_color_with_scaled_brightness(hass, mqtt_mock):
async def test_sending_rgb_color_with_scaled_brightness(
hass, mqtt_mock_entry_with_yaml_config
):
"""Test light.turn_on with hs color sends rgb color parameters."""
assert await async_setup_component(
hass,
@ -1237,6 +1264,7 @@ async def test_sending_rgb_color_with_scaled_brightness(hass, mqtt_mock):
},
)
await hass.async_block_till_done()
mqtt_mock = await mqtt_mock_entry_with_yaml_config()
state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN
@ -1289,7 +1317,7 @@ async def test_sending_rgb_color_with_scaled_brightness(hass, mqtt_mock):
)
async def test_sending_xy_color(hass, mqtt_mock):
async def test_sending_xy_color(hass, mqtt_mock_entry_with_yaml_config):
"""Test light.turn_on with hs color sends xy color parameters."""
assert await async_setup_component(
hass,
@ -1307,6 +1335,7 @@ async def test_sending_xy_color(hass, mqtt_mock):
},
)
await hass.async_block_till_done()
mqtt_mock = await mqtt_mock_entry_with_yaml_config()
state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN
@ -1353,7 +1382,7 @@ async def test_sending_xy_color(hass, mqtt_mock):
)
async def test_effect(hass, mqtt_mock):
async def test_effect(hass, mqtt_mock_entry_with_yaml_config):
"""Test for effect being sent when included."""
assert await async_setup_component(
hass,
@ -1370,6 +1399,7 @@ async def test_effect(hass, mqtt_mock):
},
)
await hass.async_block_till_done()
mqtt_mock = await mqtt_mock_entry_with_yaml_config()
state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN
@ -1415,7 +1445,7 @@ async def test_effect(hass, mqtt_mock):
assert state.attributes.get("effect") == "colorloop"
async def test_flash_short_and_long(hass, mqtt_mock):
async def test_flash_short_and_long(hass, mqtt_mock_entry_with_yaml_config):
"""Test for flash length being sent when included."""
assert await async_setup_component(
hass,
@ -1433,6 +1463,7 @@ async def test_flash_short_and_long(hass, mqtt_mock):
},
)
await hass.async_block_till_done()
mqtt_mock = await mqtt_mock_entry_with_yaml_config()
state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN
@ -1476,7 +1507,7 @@ async def test_flash_short_and_long(hass, mqtt_mock):
assert state.state == STATE_OFF
async def test_transition(hass, mqtt_mock):
async def test_transition(hass, mqtt_mock_entry_with_yaml_config):
"""Test for transition time being sent when included."""
assert await async_setup_component(
hass,
@ -1492,6 +1523,7 @@ async def test_transition(hass, mqtt_mock):
},
)
await hass.async_block_till_done()
mqtt_mock = await mqtt_mock_entry_with_yaml_config()
state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN
@ -1522,7 +1554,7 @@ async def test_transition(hass, mqtt_mock):
assert state.state == STATE_OFF
async def test_brightness_scale(hass, mqtt_mock):
async def test_brightness_scale(hass, mqtt_mock_entry_with_yaml_config):
"""Test for brightness scaling."""
assert await async_setup_component(
hass,
@ -1540,6 +1572,7 @@ async def test_brightness_scale(hass, mqtt_mock):
},
)
await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config()
state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN
@ -1563,7 +1596,7 @@ async def test_brightness_scale(hass, mqtt_mock):
assert state.attributes.get("brightness") == 255
async def test_invalid_values(hass, mqtt_mock):
async def test_invalid_values(hass, mqtt_mock_entry_with_yaml_config):
"""Test that invalid color/brightness/white/etc. values are ignored."""
assert await async_setup_component(
hass,
@ -1584,6 +1617,7 @@ async def test_invalid_values(hass, mqtt_mock):
},
)
await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config()
state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN
@ -1700,77 +1734,95 @@ async def test_invalid_values(hass, mqtt_mock):
assert state.attributes.get("color_temp") == 100
async def test_availability_when_connection_lost(hass, mqtt_mock):
async def test_availability_when_connection_lost(
hass, mqtt_mock_entry_with_yaml_config
):
"""Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost(
hass, mqtt_mock, light.DOMAIN, DEFAULT_CONFIG
hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG
)
async def test_availability_without_topic(hass, mqtt_mock):
async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability without defined availability topic."""
await help_test_availability_without_topic(
hass, mqtt_mock, light.DOMAIN, DEFAULT_CONFIG
hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG
)
async def test_default_availability_payload(hass, mqtt_mock):
async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability by default payload with defined topic."""
await help_test_default_availability_payload(
hass, mqtt_mock, light.DOMAIN, DEFAULT_CONFIG
hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG
)
async def test_custom_availability_payload(hass, mqtt_mock):
async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_config):
"""Test availability by custom payload with defined topic."""
await help_test_custom_availability_payload(
hass, mqtt_mock, light.DOMAIN, DEFAULT_CONFIG
hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG
)
async def test_setting_attribute_via_mqtt_json_message(hass, mqtt_mock):
async def test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_with_yaml_config
):
"""Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock, light.DOMAIN, DEFAULT_CONFIG
hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG
)
async def test_setting_blocked_attribute_via_mqtt_json_message(hass, mqtt_mock):
async def test_setting_blocked_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_no_yaml_config
):
"""Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_blocked_attribute_via_mqtt_json_message(
hass, mqtt_mock, light.DOMAIN, DEFAULT_CONFIG, MQTT_LIGHT_ATTRIBUTES_BLOCKED
hass,
mqtt_mock_entry_no_yaml_config,
light.DOMAIN,
DEFAULT_CONFIG,
MQTT_LIGHT_ATTRIBUTES_BLOCKED,
)
async def test_setting_attribute_with_template(hass, mqtt_mock):
async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_config):
"""Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template(
hass, mqtt_mock, light.DOMAIN, DEFAULT_CONFIG
hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG
)
async def test_update_with_json_attrs_not_dict(hass, mqtt_mock, caplog):
async def test_update_with_json_attrs_not_dict(
hass, mqtt_mock_entry_with_yaml_config, caplog
):
"""Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_not_dict(
hass, mqtt_mock, caplog, light.DOMAIN, DEFAULT_CONFIG
hass, mqtt_mock_entry_with_yaml_config, caplog, light.DOMAIN, DEFAULT_CONFIG
)
async def test_update_with_json_attrs_bad_JSON(hass, mqtt_mock, caplog):
async def test_update_with_json_attrs_bad_JSON(
hass, mqtt_mock_entry_with_yaml_config, caplog
):
"""Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_JSON(
hass, mqtt_mock, caplog, light.DOMAIN, DEFAULT_CONFIG
hass, mqtt_mock_entry_with_yaml_config, caplog, light.DOMAIN, DEFAULT_CONFIG
)
async def test_discovery_update_attr(hass, mqtt_mock, caplog):
async def test_discovery_update_attr(hass, mqtt_mock_entry_no_yaml_config, caplog):
"""Test update of discovered MQTTAttributes."""
await help_test_discovery_update_attr(
hass, mqtt_mock, caplog, light.DOMAIN, DEFAULT_CONFIG
hass,
mqtt_mock_entry_no_yaml_config,
caplog,
light.DOMAIN,
DEFAULT_CONFIG,
)
async def test_unique_id(hass, mqtt_mock):
async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config):
"""Test unique id option only creates one light per unique_id."""
config = {
light.DOMAIN: [
@ -1792,16 +1844,24 @@ async def test_unique_id(hass, mqtt_mock):
},
]
}
await help_test_unique_id(hass, mqtt_mock, light.DOMAIN, config)
await help_test_unique_id(
hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, config
)
async def test_discovery_removal(hass, mqtt_mock, caplog):
async def test_discovery_removal(hass, mqtt_mock_entry_no_yaml_config, caplog):
"""Test removal of discovered mqtt_json lights."""
data = '{ "name": "test",' ' "schema": "json",' ' "command_topic": "test_topic" }'
await help_test_discovery_removal(hass, mqtt_mock, caplog, light.DOMAIN, data)
await help_test_discovery_removal(
hass,
mqtt_mock_entry_no_yaml_config,
caplog,
light.DOMAIN,
data,
)
async def test_discovery_update_light(hass, mqtt_mock, caplog):
async def test_discovery_update_light(hass, mqtt_mock_entry_no_yaml_config, caplog):
"""Test update of discovered light."""
config1 = {
"name": "Beer",
@ -1816,11 +1876,18 @@ async def test_discovery_update_light(hass, mqtt_mock, caplog):
"command_topic": "test_topic",
}
await help_test_discovery_update(
hass, mqtt_mock, caplog, light.DOMAIN, config1, config2
hass,
mqtt_mock_entry_no_yaml_config,
caplog,
light.DOMAIN,
config1,
config2,
)
async def test_discovery_update_unchanged_light(hass, mqtt_mock, caplog):
async def test_discovery_update_unchanged_light(
hass, mqtt_mock_entry_no_yaml_config, caplog
):
"""Test update of discovered light."""
data1 = (
'{ "name": "Beer",'
@ -1832,12 +1899,17 @@ async def test_discovery_update_unchanged_light(hass, mqtt_mock, caplog):
"homeassistant.components.mqtt.light.schema_json.MqttLightJson.discovery_update"
) as discovery_update:
await help_test_discovery_update_unchanged(
hass, mqtt_mock, caplog, light.DOMAIN, data1, discovery_update
hass,
mqtt_mock_entry_no_yaml_config,
caplog,
light.DOMAIN,
data1,
discovery_update,
)
@pytest.mark.no_fail_on_log_exception
async def test_discovery_broken(hass, mqtt_mock, caplog):
async def test_discovery_broken(hass, mqtt_mock_entry_no_yaml_config, caplog):
"""Test handling of bad discovery message."""
data1 = '{ "name": "Beer" }'
data2 = (
@ -1847,57 +1919,80 @@ async def test_discovery_broken(hass, mqtt_mock, caplog):
' "command_topic": "test_topic" }'
)
await help_test_discovery_broken(
hass, mqtt_mock, caplog, light.DOMAIN, data1, data2
hass,
mqtt_mock_entry_no_yaml_config,
caplog,
light.DOMAIN,
data1,
data2,
)
async def test_entity_device_info_with_connection(hass, mqtt_mock):
async def test_entity_device_info_with_connection(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT light device registry integration."""
await help_test_entity_device_info_with_connection(
hass, mqtt_mock, light.DOMAIN, DEFAULT_CONFIG
hass,
mqtt_mock_entry_no_yaml_config,
light.DOMAIN,
DEFAULT_CONFIG,
)
async def test_entity_device_info_with_identifier(hass, mqtt_mock):
async def test_entity_device_info_with_identifier(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT light device registry integration."""
await help_test_entity_device_info_with_identifier(
hass, mqtt_mock, light.DOMAIN, DEFAULT_CONFIG
hass,
mqtt_mock_entry_no_yaml_config,
light.DOMAIN,
DEFAULT_CONFIG,
)
async def test_entity_device_info_update(hass, mqtt_mock):
async def test_entity_device_info_update(hass, mqtt_mock_entry_no_yaml_config):
"""Test device registry update."""
await help_test_entity_device_info_update(
hass, mqtt_mock, light.DOMAIN, DEFAULT_CONFIG
hass,
mqtt_mock_entry_no_yaml_config,
light.DOMAIN,
DEFAULT_CONFIG,
)
async def test_entity_device_info_remove(hass, mqtt_mock):
async def test_entity_device_info_remove(hass, mqtt_mock_entry_no_yaml_config):
"""Test device registry remove."""
await help_test_entity_device_info_remove(
hass, mqtt_mock, light.DOMAIN, DEFAULT_CONFIG
hass,
mqtt_mock_entry_no_yaml_config,
light.DOMAIN,
DEFAULT_CONFIG,
)
async def test_entity_id_update_subscriptions(hass, mqtt_mock):
async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_config):
"""Test MQTT subscriptions are managed when entity_id is updated."""
await help_test_entity_id_update_subscriptions(
hass, mqtt_mock, light.DOMAIN, DEFAULT_CONFIG
hass,
mqtt_mock_entry_with_yaml_config,
light.DOMAIN,
DEFAULT_CONFIG,
)
async def test_entity_id_update_discovery_update(hass, mqtt_mock):
async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update(
hass, mqtt_mock, light.DOMAIN, DEFAULT_CONFIG
hass,
mqtt_mock_entry_no_yaml_config,
light.DOMAIN,
DEFAULT_CONFIG,
)
async def test_entity_debug_info_message(hass, mqtt_mock):
async def test_entity_debug_info_message(hass, mqtt_mock_entry_no_yaml_config):
"""Test MQTT debug info."""
await help_test_entity_debug_info_message(
hass,
mqtt_mock,
mqtt_mock_entry_no_yaml_config,
light.DOMAIN,
DEFAULT_CONFIG,
light.SERVICE_TURN_ON,
@ -1906,7 +2001,7 @@ async def test_entity_debug_info_message(hass, mqtt_mock):
)
async def test_max_mireds(hass, mqtt_mock):
async def test_max_mireds(hass, mqtt_mock_entry_with_yaml_config):
"""Test setting min_mireds and max_mireds."""
config = {
light.DOMAIN: {
@ -1921,6 +2016,7 @@ async def test_max_mireds(hass, mqtt_mock):
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config()
state = hass.states.get("light.test")
assert state.attributes.get("min_mireds") == 153
@ -1952,7 +2048,7 @@ async def test_max_mireds(hass, mqtt_mock):
)
async def test_publishing_with_custom_encoding(
hass,
mqtt_mock,
mqtt_mock_entry_with_yaml_config,
caplog,
service,
topic,
@ -1972,7 +2068,7 @@ async def test_publishing_with_custom_encoding(
await help_test_publishing_with_custom_encoding(
hass,
mqtt_mock,
mqtt_mock_entry_with_yaml_config,
caplog,
domain,
config,
@ -1986,11 +2082,13 @@ async def test_publishing_with_custom_encoding(
)
async def test_reloadable(hass, mqtt_mock, caplog, tmp_path):
async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path):
"""Test reloading the MQTT platform."""
domain = light.DOMAIN
config = DEFAULT_CONFIG[domain]
await help_test_reloadable(hass, mqtt_mock, caplog, tmp_path, domain, config)
await help_test_reloadable(
hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config
)
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
@ -2013,7 +2111,14 @@ async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
],
)
async def test_encoding_subscribable_topics(
hass, mqtt_mock, caplog, topic, value, attribute, attribute_value, init_payload
hass,
mqtt_mock_entry_with_yaml_config,
caplog,
topic,
value,
attribute,
attribute_value,
init_payload,
):
"""Test handling of incoming encoded payload."""
config = copy.deepcopy(DEFAULT_CONFIG[light.DOMAIN])
@ -2028,7 +2133,7 @@ async def test_encoding_subscribable_topics(
]
await help_test_encoding_subscribable_topics(
hass,
mqtt_mock,
mqtt_mock_entry_with_yaml_config,
caplog,
light.DOMAIN,
config,