mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 00:37:53 +00:00
Cleanup mqtt platform tests part 1 (#120470)
This commit is contained in:
parent
5983344746
commit
038f2ce79f
@ -1167,10 +1167,7 @@ async def test_entity_device_info_remove(
|
||||
) -> None:
|
||||
"""Test device registry remove."""
|
||||
await help_test_entity_device_info_remove(
|
||||
hass,
|
||||
mqtt_mock_entry,
|
||||
alarm_control_panel.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
hass, mqtt_mock_entry, alarm_control_panel.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
@ -1188,10 +1185,7 @@ async def test_entity_id_update_discovery_update(
|
||||
) -> None:
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
await help_test_entity_id_update_discovery_update(
|
||||
hass,
|
||||
mqtt_mock_entry,
|
||||
alarm_control_panel.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
hass, mqtt_mock_entry, alarm_control_panel.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
|
@ -977,10 +977,7 @@ async def test_entity_device_info_with_connection(
|
||||
) -> None:
|
||||
"""Test MQTT binary sensor device registry integration."""
|
||||
await help_test_entity_device_info_with_connection(
|
||||
hass,
|
||||
mqtt_mock_entry,
|
||||
binary_sensor.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
hass, mqtt_mock_entry, binary_sensor.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
@ -989,10 +986,7 @@ async def test_entity_device_info_with_identifier(
|
||||
) -> None:
|
||||
"""Test MQTT binary sensor device registry integration."""
|
||||
await help_test_entity_device_info_with_identifier(
|
||||
hass,
|
||||
mqtt_mock_entry,
|
||||
binary_sensor.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
hass, mqtt_mock_entry, binary_sensor.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
@ -1001,10 +995,7 @@ async def test_entity_device_info_update(
|
||||
) -> None:
|
||||
"""Test device registry update."""
|
||||
await help_test_entity_device_info_update(
|
||||
hass,
|
||||
mqtt_mock_entry,
|
||||
binary_sensor.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
hass, mqtt_mock_entry, binary_sensor.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
@ -1013,10 +1004,7 @@ async def test_entity_device_info_remove(
|
||||
) -> None:
|
||||
"""Test device registry remove."""
|
||||
await help_test_entity_device_info_remove(
|
||||
hass,
|
||||
mqtt_mock_entry,
|
||||
binary_sensor.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
hass, mqtt_mock_entry, binary_sensor.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
@ -1034,10 +1022,7 @@ async def test_entity_id_update_discovery_update(
|
||||
) -> None:
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
await help_test_entity_id_update_discovery_update(
|
||||
hass,
|
||||
mqtt_mock_entry,
|
||||
binary_sensor.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
hass, mqtt_mock_entry, binary_sensor.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
@ -1046,11 +1031,7 @@ async def test_entity_debug_info_message(
|
||||
) -> None:
|
||||
"""Test MQTT debug info."""
|
||||
await help_test_entity_debug_info_message(
|
||||
hass,
|
||||
mqtt_mock_entry,
|
||||
binary_sensor.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
None,
|
||||
hass, mqtt_mock_entry, binary_sensor.DOMAIN, DEFAULT_CONFIG, None
|
||||
)
|
||||
|
||||
|
||||
@ -1104,10 +1085,10 @@ async def test_cleanup_triggers_and_restoring_state(
|
||||
tmp_path: Path,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
hass_config: ConfigType,
|
||||
payload1,
|
||||
state1,
|
||||
payload2,
|
||||
state2,
|
||||
payload1: str,
|
||||
state1: str,
|
||||
payload2: str,
|
||||
state2: str,
|
||||
) -> None:
|
||||
"""Test cleanup old triggers at reloading and restoring the state."""
|
||||
freezer.move_to("2022-02-02 12:01:00+01:00")
|
||||
@ -1196,8 +1177,7 @@ async def test_setup_manual_entity_from_yaml(
|
||||
|
||||
|
||||
async def test_unload_entry(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test unloading the config entry."""
|
||||
domain = binary_sensor.DOMAIN
|
||||
|
@ -159,13 +159,7 @@ async def test_default_availability_payload(
|
||||
}
|
||||
}
|
||||
await help_test_default_availability_payload(
|
||||
hass,
|
||||
mqtt_mock_entry,
|
||||
button.DOMAIN,
|
||||
config,
|
||||
True,
|
||||
"state-topic",
|
||||
"1",
|
||||
hass, mqtt_mock_entry, button.DOMAIN, config, True, "state-topic", "1"
|
||||
)
|
||||
|
||||
|
||||
@ -184,13 +178,7 @@ async def test_custom_availability_payload(
|
||||
}
|
||||
|
||||
await help_test_custom_availability_payload(
|
||||
hass,
|
||||
mqtt_mock_entry,
|
||||
button.DOMAIN,
|
||||
config,
|
||||
True,
|
||||
"state-topic",
|
||||
"1",
|
||||
hass, mqtt_mock_entry, button.DOMAIN, config, True, "state-topic", "1"
|
||||
)
|
||||
|
||||
|
||||
|
@ -222,11 +222,7 @@ async def test_update_with_json_attrs_not_dict(
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_not_dict(
|
||||
hass,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
camera.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
hass, mqtt_mock_entry, caplog, camera.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
@ -237,11 +233,7 @@ async def test_update_with_json_attrs_bad_json(
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_bad_json(
|
||||
hass,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
camera.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
hass, mqtt_mock_entry, caplog, camera.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
@ -368,11 +360,7 @@ async def test_entity_id_update_subscriptions(
|
||||
) -> None:
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
await help_test_entity_id_update_subscriptions(
|
||||
hass,
|
||||
mqtt_mock_entry,
|
||||
camera.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
["test_topic"],
|
||||
hass, mqtt_mock_entry, camera.DOMAIN, DEFAULT_CONFIG, ["test_topic"]
|
||||
)
|
||||
|
||||
|
||||
|
@ -191,9 +191,7 @@ async def test_get_hvac_modes(
|
||||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_set_operation_bad_attr_and_state(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setting operation mode without required attribute.
|
||||
|
||||
@ -454,9 +452,7 @@ async def test_turn_on_and_off_without_power_command(
|
||||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_set_fan_mode_bad_attr(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setting fan mode without required attribute."""
|
||||
await mqtt_mock_entry()
|
||||
@ -551,9 +547,7 @@ async def test_set_fan_mode(
|
||||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_set_swing_mode_bad_attr(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setting swing mode without required attribute."""
|
||||
await mqtt_mock_entry()
|
||||
@ -1046,9 +1040,7 @@ async def test_handle_action_received(
|
||||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_set_preset_mode_optimistic(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setting of the preset mode."""
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
@ -1104,9 +1096,7 @@ async def test_set_preset_mode_optimistic(
|
||||
],
|
||||
)
|
||||
async def test_set_preset_mode_explicit_optimistic(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setting of the preset mode."""
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
@ -1523,9 +1513,7 @@ async def test_get_with_templates(
|
||||
],
|
||||
)
|
||||
async def test_set_and_templates(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setting various attributes with templates."""
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
@ -2074,11 +2062,7 @@ async def test_entity_id_update_subscriptions(
|
||||
}
|
||||
}
|
||||
await help_test_entity_id_update_subscriptions(
|
||||
hass,
|
||||
mqtt_mock_entry,
|
||||
climate.DOMAIN,
|
||||
config,
|
||||
["test-topic", "avty-topic"],
|
||||
hass, mqtt_mock_entry, climate.DOMAIN, config, ["test-topic", "avty-topic"]
|
||||
)
|
||||
|
||||
|
||||
@ -2170,20 +2154,8 @@ async def test_precision_whole(
|
||||
@pytest.mark.parametrize(
|
||||
("service", "topic", "parameters", "payload", "template"),
|
||||
[
|
||||
(
|
||||
climate.SERVICE_TURN_ON,
|
||||
"power_command_topic",
|
||||
{},
|
||||
"ON",
|
||||
None,
|
||||
),
|
||||
(
|
||||
climate.SERVICE_TURN_OFF,
|
||||
"power_command_topic",
|
||||
{},
|
||||
"OFF",
|
||||
None,
|
||||
),
|
||||
(climate.SERVICE_TURN_ON, "power_command_topic", {}, "ON", None),
|
||||
(climate.SERVICE_TURN_OFF, "power_command_topic", {}, "OFF", None),
|
||||
(
|
||||
climate.SERVICE_SET_HVAC_MODE,
|
||||
"mode_command_topic",
|
||||
@ -2346,9 +2318,7 @@ async def test_publishing_with_custom_encoding(
|
||||
],
|
||||
)
|
||||
async def test_humidity_configuration_validity(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
valid: bool,
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator, valid: bool
|
||||
) -> None:
|
||||
"""Test the validity of humidity configurations."""
|
||||
assert await mqtt_mock_entry()
|
||||
@ -2357,8 +2327,7 @@ async def test_humidity_configuration_validity(
|
||||
|
||||
|
||||
async def test_reloadable(
|
||||
hass: HomeAssistant,
|
||||
mqtt_client_mock: MqttMockPahoClient,
|
||||
hass: HomeAssistant, mqtt_client_mock: MqttMockPahoClient
|
||||
) -> None:
|
||||
"""Test reloading the MQTT platform."""
|
||||
domain = climate.DOMAIN
|
||||
@ -2381,8 +2350,7 @@ async def test_setup_manual_entity_from_yaml(
|
||||
|
||||
|
||||
async def test_unload_entry(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test unloading the config entry."""
|
||||
domain = climate.DOMAIN
|
||||
|
@ -187,11 +187,11 @@ def mock_process_uploaded_file(
|
||||
yield mock_upload
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mqtt_client_mock")
|
||||
async def test_user_connection_works(
|
||||
hass: HomeAssistant,
|
||||
mock_try_connection: MagicMock,
|
||||
mock_finish_setup: MagicMock,
|
||||
mqtt_client_mock: MqttMockPahoClient,
|
||||
) -> None:
|
||||
"""Test we can finish a config flow."""
|
||||
mock_try_connection.return_value = True
|
||||
@ -217,11 +217,11 @@ async def test_user_connection_works(
|
||||
assert len(mock_finish_setup.mock_calls) == 1
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mqtt_client_mock")
|
||||
async def test_user_v5_connection_works(
|
||||
hass: HomeAssistant,
|
||||
mock_try_connection: MagicMock,
|
||||
mock_finish_setup: MagicMock,
|
||||
mqtt_client_mock: MqttMockPahoClient,
|
||||
) -> None:
|
||||
"""Test we can finish a config flow."""
|
||||
mock_try_connection.return_value = True
|
||||
@ -664,11 +664,11 @@ async def test_bad_certificate(
|
||||
("100", False),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("mock_reload_after_entry_update")
|
||||
async def test_keepalive_validation(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
mock_try_connection: MagicMock,
|
||||
mock_reload_after_entry_update: MagicMock,
|
||||
input_value: str,
|
||||
error: bool,
|
||||
) -> None:
|
||||
@ -872,11 +872,11 @@ def get_suggested(schema: vol.Schema, key: str) -> Any:
|
||||
return schema_key.description["suggested_value"]
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_reload_after_entry_update")
|
||||
async def test_option_flow_default_suggested_values(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
mock_try_connection_success: MqttMockPahoClient,
|
||||
mock_reload_after_entry_update: MagicMock,
|
||||
) -> None:
|
||||
"""Test config flow options has default/suggested values."""
|
||||
await mqtt_mock_entry()
|
||||
@ -1030,11 +1030,11 @@ async def test_option_flow_default_suggested_values(
|
||||
@pytest.mark.parametrize(
|
||||
("advanced_options", "step_id"), [(False, "options"), (True, "broker")]
|
||||
)
|
||||
@pytest.mark.usefixtures("mock_reload_after_entry_update")
|
||||
async def test_skipping_advanced_options(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
mock_try_connection: MagicMock,
|
||||
mock_reload_after_entry_update: MagicMock,
|
||||
advanced_options: bool,
|
||||
step_id: str,
|
||||
) -> None:
|
||||
@ -1102,11 +1102,11 @@ async def test_skipping_advanced_options(
|
||||
),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("mock_reload_after_entry_update")
|
||||
async def test_step_reauth(
|
||||
hass: HomeAssistant,
|
||||
mqtt_client_mock: MqttMockPahoClient,
|
||||
mock_try_connection: MagicMock,
|
||||
mock_reload_after_entry_update: MagicMock,
|
||||
test_input: dict[str, Any],
|
||||
user_input: dict[str, Any],
|
||||
new_password: str,
|
||||
@ -1284,12 +1284,9 @@ async def test_options_bad_will_message_fails(
|
||||
@pytest.mark.parametrize(
|
||||
"hass_config", [{"mqtt": {"sensor": [{"state_topic": "some-topic"}]}}]
|
||||
)
|
||||
@pytest.mark.usefixtures("mock_ssl_context", "mock_process_uploaded_file")
|
||||
async def test_try_connection_with_advanced_parameters(
|
||||
hass: HomeAssistant,
|
||||
mock_try_connection_success: MqttMockPahoClient,
|
||||
tmp_path: Path,
|
||||
mock_ssl_context: dict[str, MagicMock],
|
||||
mock_process_uploaded_file: MagicMock,
|
||||
hass: HomeAssistant, mock_try_connection_success: MqttMockPahoClient
|
||||
) -> None:
|
||||
"""Test config flow with advanced parameters from config."""
|
||||
config_entry = MockConfigEntry(domain=mqtt.DOMAIN)
|
||||
@ -1402,10 +1399,10 @@ async def test_try_connection_with_advanced_parameters(
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_ssl_context")
|
||||
async def test_setup_with_advanced_settings(
|
||||
hass: HomeAssistant,
|
||||
mock_try_connection: MagicMock,
|
||||
mock_ssl_context: dict[str, MagicMock],
|
||||
mock_process_uploaded_file: MagicMock,
|
||||
) -> None:
|
||||
"""Test config flow setup with advanced parameters."""
|
||||
@ -1564,11 +1561,9 @@ async def test_setup_with_advanced_settings(
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.usesfixtures("mock_ssl_context", "mock_process_uploaded_file")
|
||||
async def test_change_websockets_transport_to_tcp(
|
||||
hass: HomeAssistant,
|
||||
mock_try_connection,
|
||||
mock_ssl_context: dict[str, MagicMock],
|
||||
mock_process_uploaded_file: MagicMock,
|
||||
hass: HomeAssistant, mock_try_connection: MagicMock
|
||||
) -> None:
|
||||
"""Test option flow setup with websockets transport settings."""
|
||||
config_entry = MockConfigEntry(domain=mqtt.DOMAIN)
|
||||
|
Loading…
x
Reference in New Issue
Block a user