diff --git a/pylint/plugins/hass_enforce_type_hints.py b/pylint/plugins/hass_enforce_type_hints.py index b917ba2f3c7..a3cdb139131 100644 --- a/pylint/plugins/hass_enforce_type_hints.py +++ b/pylint/plugins/hass_enforce_type_hints.py @@ -135,8 +135,7 @@ _TEST_FIXTURES: dict[str, list[str] | str] = { "mock_zeroconf": "None", "mqtt_client_mock": "MqttMockPahoClient", "mqtt_mock": "MqttMockHAClient", - "mqtt_mock_entry_no_yaml_config": "MqttMockHAClientGenerator", - "mqtt_mock_entry_with_yaml_config": "MqttMockHAClientGenerator", + "mqtt_mock_entry": "MqttMockHAClientGenerator", "recorder_db_url": "str", "recorder_mock": "Recorder", "requests_mock": "requests_mock.Mocker", diff --git a/tests/components/mqtt/test_alarm_control_panel.py b/tests/components/mqtt/test_alarm_control_panel.py index 79c06d7a5f3..a30a15d5098 100644 --- a/tests/components/mqtt/test_alarm_control_panel.py +++ b/tests/components/mqtt/test_alarm_control_panel.py @@ -178,10 +178,10 @@ async def test_fail_setup_without_state_or_command_topic( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_update_state_via_state_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test updating with via state topic.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() await hass.async_block_till_done() entity_id = "alarm_control_panel.test" @@ -206,10 +206,10 @@ async def test_update_state_via_state_topic( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_ignore_update_state_if_unknown_via_state_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test ignoring updates via state topic.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() entity_id = "alarm_control_panel.test" @@ -233,12 +233,12 @@ async def test_ignore_update_state_if_unknown_via_state_topic( ) async def test_publish_mqtt_no_code( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, service, payload, ) -> None: """Test publishing of MQTT messages when no code is configured.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() await hass.services.async_call( alarm_control_panel.DOMAIN, @@ -264,12 +264,12 @@ async def test_publish_mqtt_no_code( ) async def test_publish_mqtt_with_code( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, service, payload, ) -> None: """Test publishing of MQTT messages when code is configured.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() call_count = mqtt_mock.async_publish.call_count # No code provided, should not publish @@ -318,12 +318,12 @@ async def test_publish_mqtt_with_code( ) async def test_publish_mqtt_with_remote_code( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, service, payload, ) -> None: """Test publishing of MQTT messages when remode code is configured.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() call_count = mqtt_mock.async_publish.call_count # No code provided, should not publish @@ -363,12 +363,12 @@ async def test_publish_mqtt_with_remote_code( ) async def test_publish_mqtt_with_remote_code_text( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, service: str, payload: str, ) -> None: """Test publishing of MQTT messages when remote text code is configured.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() call_count = mqtt_mock.async_publish.call_count # No code provided, should not publish @@ -460,7 +460,7 @@ async def test_publish_mqtt_with_remote_code_text( ) async def test_publish_mqtt_with_code_required_false( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, service: str, payload: str, ) -> None: @@ -469,7 +469,7 @@ async def test_publish_mqtt_with_code_required_false( code_arm_required = False / code_disarm_required = False / code_trigger_required = False """ - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() # No code provided, should publish await hass.services.async_call( @@ -518,13 +518,13 @@ async def test_publish_mqtt_with_code_required_false( ], ) async def test_disarm_publishes_mqtt_with_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test publishing of MQTT messages while disarmed. When command_template set to output json """ - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() await common.async_alarm_disarm(hass, "0123") mqtt_mock.async_publish.assert_called_once_with( @@ -553,10 +553,10 @@ async def test_disarm_publishes_mqtt_with_template( ], ) async def test_update_state_via_state_topic_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test updating with template_value via state topic.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("alarm_control_panel.test") assert state.state == STATE_UNKNOWN @@ -576,10 +576,10 @@ async def test_update_state_via_state_topic_template( ], ) async def test_attributes_code_number( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test attributes which are not supported by the vacuum.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("alarm_control_panel.test") assert ( @@ -599,10 +599,10 @@ async def test_attributes_code_number( ], ) async def test_attributes_remote_code_number( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test attributes which are not supported by the vacuum.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("alarm_control_panel.test") assert ( @@ -620,10 +620,10 @@ async def test_attributes_remote_code_number( ], ) async def test_attributes_code_text( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test attributes which are not supported by the vacuum.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("alarm_control_panel.test") assert ( @@ -634,70 +634,70 @@ async def test_attributes_code_text( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_CODE]) async def test_availability_when_connection_lost( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability after MQTT disconnection.""" await help_test_availability_when_connection_lost( - hass, mqtt_mock_entry_no_yaml_config, alarm_control_panel.DOMAIN + hass, mqtt_mock_entry, alarm_control_panel.DOMAIN ) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_CODE]) async def test_availability_without_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability without defined availability topic.""" await help_test_availability_without_topic( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, alarm_control_panel.DOMAIN, DEFAULT_CONFIG_CODE, ) async def test_default_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by default payload with defined topic.""" await help_test_default_availability_payload( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, alarm_control_panel.DOMAIN, DEFAULT_CONFIG_CODE, ) async def test_custom_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by custom payload with defined topic.""" await help_test_custom_availability_payload( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, alarm_control_panel.DOMAIN, DEFAULT_CONFIG, ) async def test_setting_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_via_mqtt_json_message( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, alarm_control_panel.DOMAIN, DEFAULT_CONFIG, ) async def test_setting_blocked_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_blocked_attribute_via_mqtt_json_message( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, alarm_control_panel.DOMAIN, DEFAULT_CONFIG, MQTT_ALARM_ATTRIBUTES_BLOCKED, @@ -705,12 +705,12 @@ async def test_setting_blocked_attribute_via_mqtt_json_message( async def test_setting_attribute_with_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_with_template( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, alarm_control_panel.DOMAIN, DEFAULT_CONFIG, ) @@ -718,13 +718,13 @@ async def test_setting_attribute_with_template( async def test_update_with_json_attrs_not_dict( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_not_dict( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, alarm_control_panel.DOMAIN, DEFAULT_CONFIG, @@ -733,13 +733,13 @@ async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_bad_json( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_bad_json( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, alarm_control_panel.DOMAIN, DEFAULT_CONFIG, @@ -748,13 +748,13 @@ async def test_update_with_json_attrs_bad_json( async def test_discovery_update_attr( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered MQTTAttributes.""" await help_test_discovery_update_attr( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, alarm_control_panel.DOMAIN, DEFAULT_CONFIG, @@ -785,29 +785,27 @@ async def test_discovery_update_attr( ], ) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one alarm per unique_id.""" - await help_test_unique_id( - hass, mqtt_mock_entry_no_yaml_config, alarm_control_panel.DOMAIN - ) + await help_test_unique_id(hass, mqtt_mock_entry, alarm_control_panel.DOMAIN) async def test_discovery_removal_alarm( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test removal of discovered alarm_control_panel.""" data = json.dumps(DEFAULT_CONFIG[mqtt.DOMAIN][alarm_control_panel.DOMAIN]) await help_test_discovery_removal( - hass, mqtt_mock_entry_no_yaml_config, caplog, alarm_control_panel.DOMAIN, data + hass, mqtt_mock_entry, caplog, alarm_control_panel.DOMAIN, data ) async def test_discovery_update_alarm_topic_and_template( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered alarm_control_panel.""" @@ -832,7 +830,7 @@ async def test_discovery_update_alarm_topic_and_template( await help_test_discovery_update( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, alarm_control_panel.DOMAIN, config1, @@ -844,7 +842,7 @@ async def test_discovery_update_alarm_topic_and_template( async def test_discovery_update_alarm_template( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered alarm_control_panel.""" @@ -867,7 +865,7 @@ async def test_discovery_update_alarm_template( await help_test_discovery_update( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, alarm_control_panel.DOMAIN, config1, @@ -879,7 +877,7 @@ async def test_discovery_update_alarm_template( async def test_discovery_update_unchanged_alarm( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered alarm_control_panel.""" @@ -892,7 +890,7 @@ async def test_discovery_update_unchanged_alarm( ) as discovery_update: await help_test_discovery_update_unchanged( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, alarm_control_panel.DOMAIN, data1, @@ -903,7 +901,7 @@ async def test_discovery_update_unchanged_alarm( @pytest.mark.no_fail_on_log_exception async def test_discovery_broken( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test handling of bad discovery message.""" @@ -915,7 +913,7 @@ async def test_discovery_broken( ) await help_test_discovery_broken( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, alarm_control_panel.DOMAIN, data1, @@ -932,14 +930,14 @@ async def test_discovery_broken( ) async def test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, topic: str, value: str, ) -> None: """Test handling of incoming encoded payload.""" await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, alarm_control_panel.DOMAIN, DEFAULT_CONFIG[mqtt.DOMAIN][alarm_control_panel.DOMAIN], topic, @@ -948,81 +946,81 @@ async def test_encoding_subscribable_topics( async def test_entity_device_info_with_connection( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT alarm control panel device registry integration.""" await help_test_entity_device_info_with_connection( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, alarm_control_panel.DOMAIN, DEFAULT_CONFIG, ) async def test_entity_device_info_with_identifier( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT alarm control panel device registry integration.""" await help_test_entity_device_info_with_identifier( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, alarm_control_panel.DOMAIN, DEFAULT_CONFIG, ) async def test_entity_device_info_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry update.""" await help_test_entity_device_info_update( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, alarm_control_panel.DOMAIN, DEFAULT_CONFIG, ) async def test_entity_device_info_remove( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry remove.""" await help_test_entity_device_info_remove( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, alarm_control_panel.DOMAIN, DEFAULT_CONFIG, ) async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" await help_test_entity_id_update_subscriptions( - hass, mqtt_mock_entry_no_yaml_config, alarm_control_panel.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, alarm_control_panel.DOMAIN, DEFAULT_CONFIG ) async def test_entity_id_update_discovery_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT discovery update when entity_id is updated.""" await help_test_entity_id_update_discovery_update( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, alarm_control_panel.DOMAIN, DEFAULT_CONFIG, ) async def test_entity_debug_info_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT debug info.""" await help_test_entity_debug_info_message( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, alarm_control_panel.DOMAIN, DEFAULT_CONFIG, alarm_control_panel.SERVICE_ALARM_DISARM, @@ -1055,7 +1053,7 @@ async def test_entity_debug_info_message( ) async def test_publishing_with_custom_encoding( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, service: str, topic: str, @@ -1071,7 +1069,7 @@ async def test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, domain, config, @@ -1097,21 +1095,21 @@ async def test_reloadable( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_setup_manual_entity_from_yaml( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setup manual configured MQTT entity.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() platform = alarm_control_panel.DOMAIN assert hass.states.get(f"{platform}.test") async def test_unload_entry( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test unloading the config entry.""" domain = alarm_control_panel.DOMAIN config = DEFAULT_CONFIG await help_test_unload_config_entry_with_platform( - hass, mqtt_mock_entry_no_yaml_config, domain, config + hass, mqtt_mock_entry, domain, config ) diff --git a/tests/components/mqtt/test_binary_sensor.py b/tests/components/mqtt/test_binary_sensor.py index 0d3cd695490..0b374df07f4 100644 --- a/tests/components/mqtt/test_binary_sensor.py +++ b/tests/components/mqtt/test_binary_sensor.py @@ -93,11 +93,11 @@ def binary_sensor_platform_only(): ) async def test_setting_sensor_value_expires_availability_topic( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test the expiration of the value.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("binary_sensor.test") assert state.state == STATE_UNAVAILABLE @@ -128,11 +128,11 @@ async def test_setting_sensor_value_expires_availability_topic( ) async def test_setting_sensor_value_expires( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test the expiration of the value.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() # State should be unavailable since expire_after is defined and > 0 state = hass.states.get("binary_sensor.test") @@ -194,11 +194,11 @@ async def expires_helper(hass: HomeAssistant) -> None: async def test_expiration_on_discovery_and_discovery_update_of_binary_sensor( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test that binary_sensor with expire_after set behaves correctly on discovery and discovery update.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() config = { "name": "Test", "state_topic": "test-topic", @@ -291,10 +291,10 @@ async def test_expiration_on_discovery_and_discovery_update_of_binary_sensor( ], ) async def test_setting_sensor_value_via_mqtt_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of the value via MQTT.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("binary_sensor.test") @@ -330,11 +330,11 @@ async def test_setting_sensor_value_via_mqtt_message( ) async def test_invalid_sensor_value_via_mqtt_message( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test the setting of the value via MQTT.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("binary_sensor.test") @@ -375,10 +375,10 @@ async def test_invalid_sensor_value_via_mqtt_message( ], ) async def test_setting_sensor_value_via_mqtt_message_and_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of the value via MQTT.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("binary_sensor.test") assert state.state == STATE_UNKNOWN @@ -410,11 +410,11 @@ async def test_setting_sensor_value_via_mqtt_message_and_template( ) async def test_setting_sensor_value_via_mqtt_message_and_template2( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test the setting of the value via MQTT.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("binary_sensor.test") assert state.state == STATE_UNKNOWN @@ -452,11 +452,11 @@ async def test_setting_sensor_value_via_mqtt_message_and_template2( ) async def test_setting_sensor_value_via_mqtt_message_and_template_and_raw_state_encoding( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test processing a raw value via MQTT.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("binary_sensor.test") assert state.state == STATE_UNKNOWN @@ -487,10 +487,10 @@ async def test_setting_sensor_value_via_mqtt_message_and_template_and_raw_state_ ], ) async def test_setting_sensor_value_via_mqtt_message_empty_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of the value via MQTT.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("binary_sensor.test") assert state.state == STATE_UNKNOWN @@ -519,10 +519,10 @@ async def test_setting_sensor_value_via_mqtt_message_empty_template( ], ) async def test_valid_device_class( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of a valid sensor class.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("binary_sensor.test") assert state.attributes.get("device_class") == "motion" @@ -545,49 +545,49 @@ async def test_valid_device_class( async def test_invalid_device_class( hass: HomeAssistant, caplog: pytest.LogCaptureFixture, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test the setting of an invalid sensor class.""" with pytest.raises(AssertionError): - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() assert "Invalid config for [mqtt]: expected BinarySensorDeviceClass" in caplog.text @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_when_connection_lost( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability after MQTT disconnection.""" await help_test_availability_when_connection_lost( - hass, mqtt_mock_entry_no_yaml_config, binary_sensor.DOMAIN + hass, mqtt_mock_entry, binary_sensor.DOMAIN ) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_without_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability without defined availability topic.""" await help_test_availability_without_topic( - hass, mqtt_mock_entry_no_yaml_config, binary_sensor.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, binary_sensor.DOMAIN, DEFAULT_CONFIG ) async def test_default_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by default payload with defined topic.""" await help_test_default_availability_payload( - hass, mqtt_mock_entry_no_yaml_config, binary_sensor.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, binary_sensor.DOMAIN, DEFAULT_CONFIG ) async def test_custom_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by custom payload with defined topic.""" await help_test_custom_availability_payload( - hass, mqtt_mock_entry_no_yaml_config, binary_sensor.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, binary_sensor.DOMAIN, DEFAULT_CONFIG ) @@ -607,10 +607,10 @@ async def test_custom_availability_payload( ], ) async def test_force_update_disabled( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test force update option.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() events = [] @@ -647,10 +647,10 @@ async def test_force_update_disabled( ], ) async def test_force_update_enabled( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test force update option.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() events = [] @@ -688,10 +688,10 @@ async def test_force_update_enabled( ], ) async def test_off_delay( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test off_delay option.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() events = [] @@ -722,21 +722,21 @@ async def test_off_delay( async def test_setting_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_via_mqtt_json_message( - hass, mqtt_mock_entry_no_yaml_config, binary_sensor.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, binary_sensor.DOMAIN, DEFAULT_CONFIG ) async def test_setting_attribute_with_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_with_template( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, binary_sensor.DOMAIN, DEFAULT_CONFIG, ) @@ -744,13 +744,13 @@ async def test_setting_attribute_with_template( async def test_update_with_json_attrs_not_dict( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_not_dict( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, binary_sensor.DOMAIN, DEFAULT_CONFIG, @@ -759,13 +759,13 @@ async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_bad_json( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_bad_json( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, binary_sensor.DOMAIN, DEFAULT_CONFIG, @@ -774,13 +774,13 @@ async def test_update_with_json_attrs_bad_json( async def test_discovery_update_attr( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered MQTTAttributes.""" await help_test_discovery_update_attr( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, binary_sensor.DOMAIN, DEFAULT_CONFIG, @@ -809,29 +809,27 @@ async def test_discovery_update_attr( ], ) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one sensor per unique_id.""" - await help_test_unique_id( - hass, mqtt_mock_entry_no_yaml_config, binary_sensor.DOMAIN - ) + await help_test_unique_id(hass, mqtt_mock_entry, binary_sensor.DOMAIN) async def test_discovery_removal_binary_sensor( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test removal of discovered binary_sensor.""" data = json.dumps(DEFAULT_CONFIG[mqtt.DOMAIN][binary_sensor.DOMAIN]) await help_test_discovery_removal( - hass, mqtt_mock_entry_no_yaml_config, caplog, binary_sensor.DOMAIN, data + hass, mqtt_mock_entry, caplog, binary_sensor.DOMAIN, data ) async def test_discovery_update_binary_sensor_topic_template( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered binary_sensor.""" @@ -858,7 +856,7 @@ async def test_discovery_update_binary_sensor_topic_template( await help_test_discovery_update( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, binary_sensor.DOMAIN, config1, @@ -870,7 +868,7 @@ async def test_discovery_update_binary_sensor_topic_template( async def test_discovery_update_binary_sensor_template( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered binary_sensor.""" @@ -895,7 +893,7 @@ async def test_discovery_update_binary_sensor_template( await help_test_discovery_update( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, binary_sensor.DOMAIN, config1, @@ -920,7 +918,7 @@ async def test_discovery_update_binary_sensor_template( ) async def test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, topic: str, value: str, attribute: str | None, @@ -929,7 +927,7 @@ async def test_encoding_subscribable_topics( """Test handling of incoming encoded payload.""" await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, binary_sensor.DOMAIN, DEFAULT_CONFIG[mqtt.DOMAIN][binary_sensor.DOMAIN], topic, @@ -941,7 +939,7 @@ async def test_encoding_subscribable_topics( async def test_discovery_update_unchanged_binary_sensor( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered binary_sensor.""" @@ -954,7 +952,7 @@ async def test_discovery_update_unchanged_binary_sensor( ) as discovery_update: await help_test_discovery_update_unchanged( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, binary_sensor.DOMAIN, data1, @@ -965,7 +963,7 @@ async def test_discovery_update_unchanged_binary_sensor( @pytest.mark.no_fail_on_log_exception async def test_discovery_broken( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test handling of bad discovery message.""" @@ -973,7 +971,7 @@ async def test_discovery_broken( data2 = '{ "name": "Milk",' ' "state_topic": "test_topic" }' await help_test_discovery_broken( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, binary_sensor.DOMAIN, data1, @@ -982,81 +980,81 @@ async def test_discovery_broken( async def test_entity_device_info_with_connection( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT binary sensor device registry integration.""" await help_test_entity_device_info_with_connection( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, binary_sensor.DOMAIN, DEFAULT_CONFIG, ) async def test_entity_device_info_with_identifier( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT binary sensor device registry integration.""" await help_test_entity_device_info_with_identifier( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, binary_sensor.DOMAIN, DEFAULT_CONFIG, ) async def test_entity_device_info_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry update.""" await help_test_entity_device_info_update( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, binary_sensor.DOMAIN, DEFAULT_CONFIG, ) async def test_entity_device_info_remove( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry remove.""" await help_test_entity_device_info_remove( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, binary_sensor.DOMAIN, DEFAULT_CONFIG, ) async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" await help_test_entity_id_update_subscriptions( - hass, mqtt_mock_entry_no_yaml_config, binary_sensor.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, binary_sensor.DOMAIN, DEFAULT_CONFIG ) async def test_entity_id_update_discovery_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT discovery update when entity_id is updated.""" await help_test_entity_id_update_discovery_update( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, binary_sensor.DOMAIN, DEFAULT_CONFIG, ) async def test_entity_debug_info_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT debug info.""" await help_test_entity_debug_info_message( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, binary_sensor.DOMAIN, DEFAULT_CONFIG, None, @@ -1108,7 +1106,7 @@ async def test_reloadable( ) async def test_cleanup_triggers_and_restoring_state( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, tmp_path: Path, freezer: FrozenDateTimeFactory, @@ -1121,7 +1119,7 @@ async def test_cleanup_triggers_and_restoring_state( """Test cleanup old triggers at reloading and restoring the state.""" freezer.move_to("2022-02-02 12:01:00+01:00") - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, "test-topic1", payload1) state = hass.states.get("binary_sensor.test1") @@ -1164,7 +1162,7 @@ async def test_cleanup_triggers_and_restoring_state( ) async def test_skip_restoring_state_with_over_due_expire_trigger( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, freezer: FrozenDateTimeFactory, ) -> None: """Test restoring a state with over due expire timer.""" @@ -1183,28 +1181,28 @@ async def test_skip_restoring_state_with_over_due_expire_trigger( ) mock_restore_cache(hass, (fake_state,)) - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("binary_sensor.test3") assert state.state == STATE_UNAVAILABLE @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_setup_manual_entity_from_yaml( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setup manual configured MQTT entity.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() platform = binary_sensor.DOMAIN assert hass.states.get(f"{platform}.test") async def test_unload_entry( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test unloading the config entry.""" domain = binary_sensor.DOMAIN config = DEFAULT_CONFIG await help_test_unload_config_entry_with_platform( - hass, mqtt_mock_entry_no_yaml_config, domain, config + hass, mqtt_mock_entry, domain, config ) diff --git a/tests/components/mqtt/test_button.py b/tests/components/mqtt/test_button.py index 37636ff4bfd..9a21fed727b 100644 --- a/tests/components/mqtt/test_button.py +++ b/tests/components/mqtt/test_button.py @@ -73,10 +73,10 @@ def button_platform_only(): ], ) async def test_sending_mqtt_commands( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the sending MQTT commands.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("button.test_button") assert state.state == STATE_UNKNOWN @@ -113,10 +113,10 @@ async def test_sending_mqtt_commands( ], ) async def test_command_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the sending of MQTT commands through a command template.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("button.test") assert state.state == STATE_UNKNOWN @@ -137,26 +137,26 @@ async def test_command_template( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_when_connection_lost( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability after MQTT disconnection.""" await help_test_availability_when_connection_lost( - hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN + hass, mqtt_mock_entry, button.DOMAIN ) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_without_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability without defined availability topic.""" await help_test_availability_without_topic( - hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, button.DOMAIN, DEFAULT_CONFIG ) async def test_default_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by default payload with defined topic.""" config = { @@ -170,7 +170,7 @@ async def test_default_availability_payload( } await help_test_default_availability_payload( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, button.DOMAIN, config, True, @@ -180,7 +180,7 @@ async def test_default_availability_payload( async def test_custom_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by custom payload with defined topic.""" config = { @@ -195,7 +195,7 @@ async def test_custom_availability_payload( await help_test_custom_availability_payload( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, button.DOMAIN, config, True, @@ -205,41 +205,41 @@ async def test_custom_availability_payload( async def test_setting_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_via_mqtt_json_message( - hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, button.DOMAIN, DEFAULT_CONFIG ) async def test_setting_blocked_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_blocked_attribute_via_mqtt_json_message( - hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG, None + hass, mqtt_mock_entry, button.DOMAIN, DEFAULT_CONFIG, None ) async def test_setting_attribute_with_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_with_template( - hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, button.DOMAIN, DEFAULT_CONFIG ) async def test_update_with_json_attrs_not_dict( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_not_dict( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, button.DOMAIN, DEFAULT_CONFIG, @@ -248,13 +248,13 @@ async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_bad_json( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_bad_json( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, button.DOMAIN, DEFAULT_CONFIG, @@ -263,13 +263,13 @@ async def test_update_with_json_attrs_bad_json( async def test_discovery_update_attr( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered MQTTAttributes.""" await help_test_discovery_update_attr( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, button.DOMAIN, DEFAULT_CONFIG, @@ -298,27 +298,27 @@ async def test_discovery_update_attr( ], ) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one button per unique_id.""" - await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN) + await help_test_unique_id(hass, mqtt_mock_entry, button.DOMAIN) async def test_discovery_removal_button( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test removal of discovered button.""" data = '{ "name": "test", "command_topic": "test_topic" }' await help_test_discovery_removal( - hass, mqtt_mock_entry_no_yaml_config, caplog, button.DOMAIN, data + hass, mqtt_mock_entry, caplog, button.DOMAIN, data ) async def test_discovery_update_button( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered button.""" @@ -329,7 +329,7 @@ async def test_discovery_update_button( await help_test_discovery_update( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, button.DOMAIN, config1, @@ -339,7 +339,7 @@ async def test_discovery_update_button( async def test_discovery_update_unchanged_button( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered button.""" @@ -353,7 +353,7 @@ async def test_discovery_update_unchanged_button( ) as discovery_update: await help_test_discovery_update_unchanged( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, button.DOMAIN, data1, @@ -364,69 +364,69 @@ async def test_discovery_update_unchanged_button( @pytest.mark.no_fail_on_log_exception async def test_discovery_broken( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test handling of bad discovery message.""" data1 = '{ "name": "Beer" }' data2 = '{ "name": "Milk", "command_topic": "test_topic" }' await help_test_discovery_broken( - hass, mqtt_mock_entry_no_yaml_config, caplog, button.DOMAIN, data1, data2 + hass, mqtt_mock_entry, caplog, button.DOMAIN, data1, data2 ) async def test_entity_device_info_with_connection( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT button device registry integration.""" await help_test_entity_device_info_with_connection( - hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, button.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_with_identifier( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT button device registry integration.""" await help_test_entity_device_info_with_identifier( - hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, button.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry update.""" await help_test_entity_device_info_update( - hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, button.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_remove( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry remove.""" await help_test_entity_device_info_remove( - hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, button.DOMAIN, DEFAULT_CONFIG ) async def test_entity_id_update_discovery_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT discovery update when entity_id is updated.""" await help_test_entity_id_update_discovery_update( - hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, button.DOMAIN, DEFAULT_CONFIG ) async def test_entity_debug_info_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT debug info.""" await help_test_entity_debug_info_message( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, button.DOMAIN, DEFAULT_CONFIG, button.SERVICE_PRESS, @@ -450,11 +450,11 @@ async def test_entity_debug_info_message( ], ) async def test_invalid_device_class( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device_class option with invalid value.""" with pytest.raises(AssertionError): - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() @pytest.mark.parametrize( @@ -483,10 +483,10 @@ async def test_invalid_device_class( ], ) async def test_valid_device_class( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device_class option with valid values.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("button.test_1") assert state.attributes["device_class"] == button.ButtonDeviceClass.UPDATE @@ -504,7 +504,7 @@ async def test_valid_device_class( ) async def test_publishing_with_custom_encoding( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, service: str, topic: str, @@ -518,7 +518,7 @@ async def test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, domain, config, @@ -542,21 +542,21 @@ async def test_reloadable( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_setup_manual_entity_from_yaml( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setup manual configured MQTT entity.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() platform = button.DOMAIN assert hass.states.get(f"{platform}.test") async def test_unload_entry( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test unloading the config entry.""" domain = button.DOMAIN config = DEFAULT_CONFIG await help_test_unload_config_entry_with_platform( - hass, mqtt_mock_entry_no_yaml_config, domain, config + hass, mqtt_mock_entry, domain, config ) diff --git a/tests/components/mqtt/test_camera.py b/tests/components/mqtt/test_camera.py index 27d575ce4e8..8bb21f5eb51 100644 --- a/tests/components/mqtt/test_camera.py +++ b/tests/components/mqtt/test_camera.py @@ -62,11 +62,11 @@ def camera_platform_only(): async def test_run_camera_setup( hass: HomeAssistant, hass_client_no_auth: ClientSessionGenerator, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test that it fetches the given payload.""" topic = "test/camera" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() url = hass.states.get("camera.test_camera").attributes["entity_picture"] @@ -96,11 +96,11 @@ async def test_run_camera_setup( async def test_run_camera_b64_encoded( hass: HomeAssistant, hass_client_no_auth: ClientSessionGenerator, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test that it fetches the given encoded payload.""" topic = "test/camera" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() url = hass.states.get("camera.test_camera").attributes["entity_picture"] @@ -132,12 +132,12 @@ async def test_run_camera_b64_encoded( async def test_camera_b64_encoded_with_availability( hass: HomeAssistant, hass_client_no_auth: ClientSessionGenerator, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test availability works if b64 encoding is turned on.""" topic = "test/camera" topic_availability = "test/camera_availability" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() # Make sure we are available async_fire_mqtt_message(hass, topic_availability, "online") @@ -155,58 +155,58 @@ async def test_camera_b64_encoded_with_availability( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_when_connection_lost( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability after MQTT disconnection.""" await help_test_availability_when_connection_lost( - hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN + hass, mqtt_mock_entry, camera.DOMAIN ) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_without_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability without defined availability topic.""" await help_test_availability_without_topic( - hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, camera.DOMAIN, DEFAULT_CONFIG ) async def test_default_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by default payload with defined topic.""" await help_test_default_availability_payload( - hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, camera.DOMAIN, DEFAULT_CONFIG ) async def test_custom_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by custom payload with defined topic.""" await help_test_custom_availability_payload( - hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, camera.DOMAIN, DEFAULT_CONFIG ) async def test_setting_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_via_mqtt_json_message( - hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, camera.DOMAIN, DEFAULT_CONFIG ) async def test_setting_blocked_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_blocked_attribute_via_mqtt_json_message( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, camera.DOMAIN, DEFAULT_CONFIG, MQTT_CAMERA_ATTRIBUTES_BLOCKED, @@ -214,23 +214,23 @@ async def test_setting_blocked_attribute_via_mqtt_json_message( async def test_setting_attribute_with_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_with_template( - hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, camera.DOMAIN, DEFAULT_CONFIG ) async def test_update_with_json_attrs_not_dict( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_not_dict( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, camera.DOMAIN, DEFAULT_CONFIG, @@ -239,13 +239,13 @@ async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_bad_json( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_bad_json( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, camera.DOMAIN, DEFAULT_CONFIG, @@ -254,13 +254,13 @@ async def test_update_with_json_attrs_bad_json( async def test_discovery_update_attr( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered MQTTAttributes.""" await help_test_discovery_update_attr( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, camera.DOMAIN, DEFAULT_CONFIG, @@ -289,27 +289,27 @@ async def test_discovery_update_attr( ], ) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one camera per unique_id.""" - await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN) + await help_test_unique_id(hass, mqtt_mock_entry, camera.DOMAIN) async def test_discovery_removal_camera( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test removal of discovered camera.""" data = json.dumps(DEFAULT_CONFIG[mqtt.DOMAIN][camera.DOMAIN]) await help_test_discovery_removal( - hass, mqtt_mock_entry_no_yaml_config, caplog, camera.DOMAIN, data + hass, mqtt_mock_entry, caplog, camera.DOMAIN, data ) async def test_discovery_update_camera( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered camera.""" @@ -317,13 +317,13 @@ async def test_discovery_update_camera( config2 = {"name": "Milk", "topic": "test_topic"} await help_test_discovery_update( - hass, mqtt_mock_entry_no_yaml_config, caplog, camera.DOMAIN, config1, config2 + hass, mqtt_mock_entry, caplog, camera.DOMAIN, config1, config2 ) async def test_discovery_update_unchanged_camera( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered camera.""" @@ -333,7 +333,7 @@ async def test_discovery_update_unchanged_camera( ) as discovery_update: await help_test_discovery_update_unchanged( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, camera.DOMAIN, data1, @@ -344,7 +344,7 @@ async def test_discovery_update_unchanged_camera( @pytest.mark.no_fail_on_log_exception async def test_discovery_broken( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test handling of bad discovery message.""" @@ -352,53 +352,53 @@ async def test_discovery_broken( data2 = '{ "name": "Milk", "topic": "test_topic"}' await help_test_discovery_broken( - hass, mqtt_mock_entry_no_yaml_config, caplog, camera.DOMAIN, data1, data2 + hass, mqtt_mock_entry, caplog, camera.DOMAIN, data1, data2 ) async def test_entity_device_info_with_connection( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT camera device registry integration.""" await help_test_entity_device_info_with_connection( - hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, camera.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_with_identifier( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT camera device registry integration.""" await help_test_entity_device_info_with_identifier( - hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, camera.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry update.""" await help_test_entity_device_info_update( - hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, camera.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_remove( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry remove.""" await help_test_entity_device_info_remove( - hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, camera.DOMAIN, DEFAULT_CONFIG ) async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" await help_test_entity_id_update_subscriptions( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, camera.DOMAIN, DEFAULT_CONFIG, ["test_topic"], @@ -406,21 +406,21 @@ async def test_entity_id_update_subscriptions( async def test_entity_id_update_discovery_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT discovery update when entity_id is updated.""" await help_test_entity_id_update_discovery_update( - hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, camera.DOMAIN, DEFAULT_CONFIG ) async def test_entity_debug_info_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT debug info.""" await help_test_entity_debug_info_message( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, camera.DOMAIN, DEFAULT_CONFIG, None, @@ -441,21 +441,21 @@ async def test_reloadable( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_setup_manual_entity_from_yaml( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setup manual configured MQTT entity.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() platform = camera.DOMAIN assert hass.states.get(f"{platform}.test") async def test_unload_entry( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test unloading the config entry.""" domain = camera.DOMAIN config = DEFAULT_CONFIG await help_test_unload_config_entry_with_platform( - hass, mqtt_mock_entry_no_yaml_config, domain, config + hass, mqtt_mock_entry, domain, config ) diff --git a/tests/components/mqtt/test_climate.py b/tests/components/mqtt/test_climate.py index 36894ba2cdc..384f03a317c 100644 --- a/tests/components/mqtt/test_climate.py +++ b/tests/components/mqtt/test_climate.py @@ -104,10 +104,10 @@ def climate_platform_only(): @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_setup_params( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the initial parameters.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("temperature") == 21 @@ -133,11 +133,11 @@ async def test_setup_params( async def test_preset_none_in_preset_modes( hass: HomeAssistant, caplog: pytest.LogCaptureFixture, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test the preset mode payload reset configuration.""" with pytest.raises(AssertionError): - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() assert "Invalid config for [mqtt]: not a valid value" in caplog.text @@ -211,10 +211,10 @@ async def test_preset_modes_deprecation_guard( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_supported_features( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the supported_features.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get(ENTITY_CLIMATE) support = ( @@ -232,10 +232,10 @@ async def test_supported_features( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_get_hvac_modes( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test that the operation list returns the correct modes.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get(ENTITY_CLIMATE) modes = state.attributes.get("hvac_modes") @@ -252,14 +252,14 @@ 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_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test setting operation mode without required attribute. Also check the state. """ - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get(ENTITY_CLIMATE) assert state.state == "off" @@ -275,10 +275,10 @@ async def test_set_operation_bad_attr_and_state( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_set_operation( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setting of new operation mode.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get(ENTITY_CLIMATE) assert state.state == "off" @@ -298,11 +298,11 @@ async def test_set_operation( ], ) async def test_set_operation_pessimistic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setting operation mode in pessimistic mode.""" await hass.async_block_till_done() - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get(ENTITY_CLIMATE) assert state.state == "unknown" @@ -331,10 +331,10 @@ async def test_set_operation_pessimistic( ], ) async def test_set_operation_optimistic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setting operation mode in optimistic mode.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get(ENTITY_CLIMATE) assert state.state == "off" @@ -364,10 +364,10 @@ async def test_set_operation_optimistic( ], ) async def test_set_operation_with_power_command( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setting of new operation mode with power command enabled.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get(ENTITY_CLIMATE) assert state.state == "off" @@ -391,11 +391,11 @@ async def test_set_operation_with_power_command( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_set_fan_mode_bad_attr( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test setting fan mode without required attribute.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("fan_mode") == "low" @@ -417,10 +417,10 @@ async def test_set_fan_mode_bad_attr( ], ) async def test_set_fan_mode_pessimistic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setting of new fan mode in pessimistic mode.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("fan_mode") is None @@ -449,10 +449,10 @@ async def test_set_fan_mode_pessimistic( ], ) async def test_set_fan_mode_optimistic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setting of new fan mode in optimistic mode.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("fan_mode") == "low" @@ -472,10 +472,10 @@ async def test_set_fan_mode_optimistic( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_set_fan_mode( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setting of new fan mode.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("fan_mode") == "low" @@ -488,11 +488,11 @@ 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_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test setting swing mode without required attribute.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("swing_mode") == "off" @@ -514,10 +514,10 @@ async def test_set_swing_mode_bad_attr( ], ) async def test_set_swing_pessimistic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setting swing mode in pessimistic mode.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("swing_mode") is None @@ -546,10 +546,10 @@ async def test_set_swing_pessimistic( ], ) async def test_set_swing_optimistic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setting swing mode in optimistic mode.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("swing_mode") == "off" @@ -569,10 +569,10 @@ async def test_set_swing_optimistic( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_set_swing( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setting of new swing mode.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("swing_mode") == "off" @@ -584,10 +584,10 @@ async def test_set_swing( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_set_target_temperature( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setting the target temperature.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("temperature") == 21 @@ -622,10 +622,10 @@ async def test_set_target_temperature( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_set_target_humidity( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setting the target humidity.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("humidity") is None @@ -647,10 +647,10 @@ async def test_set_target_humidity( ], ) async def test_set_target_temperature_pessimistic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setting the target temperature.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("temperature") is None @@ -679,10 +679,10 @@ async def test_set_target_temperature_pessimistic( ], ) async def test_set_target_temperature_optimistic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setting the target temperature optimistic.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("temperature") == 21 @@ -702,10 +702,10 @@ async def test_set_target_temperature_optimistic( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_set_target_temperature_low_high( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setting the low/high target temperature.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() await common.async_set_temperature( hass, target_temp_low=20, target_temp_high=23, entity_id=ENTITY_CLIMATE @@ -733,10 +733,10 @@ async def test_set_target_temperature_low_high( ], ) async def test_set_target_temperature_low_highpessimistic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setting the low/high target temperature.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("target_temp_low") is None @@ -784,10 +784,10 @@ async def test_set_target_temperature_low_highpessimistic( ], ) async def test_set_target_temperature_low_high_optimistic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setting the low/high target temperature optimistic.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("target_temp_low") == 21 @@ -829,10 +829,10 @@ async def test_set_target_temperature_low_high_optimistic( ], ) async def test_set_target_humidity_optimistic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setting the target humidity optimistic.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("humidity") is None @@ -860,10 +860,10 @@ async def test_set_target_humidity_optimistic( ], ) async def test_set_target_humidity_pessimistic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setting the target humidity.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("humidity") is None @@ -891,10 +891,10 @@ async def test_set_target_humidity_pessimistic( ], ) async def test_receive_mqtt_temperature( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test getting the current temperature via MQTT.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, "current_temperature", "47") state = hass.states.get(ENTITY_CLIMATE) @@ -912,10 +912,10 @@ async def test_receive_mqtt_temperature( ], ) async def test_receive_mqtt_humidity( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test getting the current humidity via MQTT.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, "current_humidity", "35") state = hass.states.get(ENTITY_CLIMATE) @@ -933,10 +933,10 @@ async def test_receive_mqtt_humidity( ], ) async def test_handle_target_humidity_received( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setting the target humidity via MQTT.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("humidity") is None @@ -952,10 +952,10 @@ async def test_handle_target_humidity_received( [help_custom_config(climate.DOMAIN, DEFAULT_CONFIG, ({"action_topic": "action"},))], ) async def test_handle_action_received( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test getting the action received via MQTT.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() # Cycle through valid modes and also check for wrong input such as "None" (str(None)) async_fire_mqtt_message(hass, "action", "None") @@ -975,11 +975,11 @@ 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_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test setting of the preset mode.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("preset_mode") == "none" @@ -1032,11 +1032,11 @@ async def test_set_preset_mode_optimistic( ) async def test_set_preset_mode_explicit_optimistic( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test setting of the preset mode.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("preset_mode") == "none" @@ -1089,11 +1089,11 @@ async def test_set_preset_mode_explicit_optimistic( ) async def test_set_preset_mode_pessimistic( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test setting of the preset mode.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("preset_mode") == "none" @@ -1141,10 +1141,10 @@ async def test_set_preset_mode_pessimistic( ], ) async def test_set_aux_pessimistic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setting of the aux heating in pessimistic mode.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("aux_heat") == "off" @@ -1168,10 +1168,10 @@ async def test_set_aux_pessimistic( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_set_aux( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setting of the aux heating.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("aux_heat") == "off" @@ -1189,39 +1189,39 @@ async def test_set_aux( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_when_connection_lost( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability after MQTT disconnection.""" await help_test_availability_when_connection_lost( - hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN + hass, mqtt_mock_entry, climate.DOMAIN ) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_without_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability without defined availability topic.""" await help_test_availability_without_topic( - hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, climate.DOMAIN, DEFAULT_CONFIG ) async def test_default_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by default payload with defined topic.""" await help_test_default_availability_payload( - hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, climate.DOMAIN, DEFAULT_CONFIG ) async def test_custom_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by custom payload with defined topic.""" await help_test_custom_availability_payload( - hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, climate.DOMAIN, DEFAULT_CONFIG ) @@ -1244,11 +1244,11 @@ async def test_custom_availability_payload( ) async def test_get_target_temperature_low_high_with_templates( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test getting temperature high/low with templates.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get(ENTITY_CLIMATE) @@ -1351,11 +1351,11 @@ async def test_get_target_temperature_low_high_with_templates( ) async def test_get_with_templates( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test getting various attributes with templates.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() # Operation Mode state = hass.states.get(ENTITY_CLIMATE) @@ -1507,11 +1507,11 @@ async def test_get_with_templates( ) async def test_set_and_templates( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test setting various attributes with templates.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() # Fan Mode await common.async_set_fan_mode(hass, "high", ENTITY_CLIMATE) @@ -1589,10 +1589,10 @@ async def test_set_and_templates( [help_custom_config(climate.DOMAIN, DEFAULT_CONFIG, ({"min_temp": 26},))], ) async def test_min_temp_custom( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test a custom min temp.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get(ENTITY_CLIMATE) min_temp = state.attributes.get("min_temp") @@ -1606,10 +1606,10 @@ async def test_min_temp_custom( [help_custom_config(climate.DOMAIN, DEFAULT_CONFIG, ({"max_temp": 60},))], ) async def test_max_temp_custom( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test a custom max temp.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get(ENTITY_CLIMATE) max_temp = state.attributes.get("max_temp") @@ -1623,10 +1623,10 @@ async def test_max_temp_custom( [help_custom_config(climate.DOMAIN, DEFAULT_CONFIG, ({"min_humidity": 42},))], ) async def test_min_humidity_custom( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test a custom min humidity.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get(ENTITY_CLIMATE) min_humidity = state.attributes.get("min_humidity") @@ -1640,10 +1640,10 @@ async def test_min_humidity_custom( [help_custom_config(climate.DOMAIN, DEFAULT_CONFIG, ({"max_humidity": 58},))], ) async def test_max_humidity_custom( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test a custom max humidity.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get(ENTITY_CLIMATE) max_humidity = state.attributes.get("max_humidity") @@ -1657,10 +1657,10 @@ async def test_max_humidity_custom( [help_custom_config(climate.DOMAIN, DEFAULT_CONFIG, ({"temp_step": 0.01},))], ) async def test_temp_step_custom( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test a custom temp step.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get(ENTITY_CLIMATE) temp_step = state.attributes.get("target_temp_step") @@ -1685,10 +1685,10 @@ async def test_temp_step_custom( ], ) async def test_temperature_unit( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test that setting temperature unit converts temperature values.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, "current_temperature", "77") @@ -1697,21 +1697,21 @@ async def test_temperature_unit( async def test_setting_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_via_mqtt_json_message( - hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, climate.DOMAIN, DEFAULT_CONFIG ) async def test_setting_blocked_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_blocked_attribute_via_mqtt_json_message( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, climate.DOMAIN, DEFAULT_CONFIG, MQTT_CLIMATE_ATTRIBUTES_BLOCKED, @@ -1719,23 +1719,23 @@ async def test_setting_blocked_attribute_via_mqtt_json_message( async def test_setting_attribute_with_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_with_template( - hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, climate.DOMAIN, DEFAULT_CONFIG ) async def test_update_with_json_attrs_not_dict( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_not_dict( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, climate.DOMAIN, DEFAULT_CONFIG, @@ -1744,13 +1744,13 @@ async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_bad_json( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_bad_json( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, climate.DOMAIN, DEFAULT_CONFIG, @@ -1759,13 +1759,13 @@ async def test_update_with_json_attrs_bad_json( async def test_discovery_update_attr( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered MQTTAttributes.""" await help_test_discovery_update_attr( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, climate.DOMAIN, DEFAULT_CONFIG, @@ -1796,10 +1796,10 @@ async def test_discovery_update_attr( ], ) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one climate per unique_id.""" - await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN) + await help_test_unique_id(hass, mqtt_mock_entry, climate.DOMAIN) @pytest.mark.parametrize( @@ -1822,7 +1822,7 @@ async def test_unique_id( ) async def test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, topic: str, value: str, attribute: str | None, @@ -1832,7 +1832,7 @@ async def test_encoding_subscribable_topics( config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][climate.DOMAIN]) await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, climate.DOMAIN, config, topic, @@ -1844,32 +1844,32 @@ async def test_encoding_subscribable_topics( async def test_discovery_removal_climate( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test removal of discovered climate.""" data = json.dumps(DEFAULT_CONFIG[mqtt.DOMAIN][climate.DOMAIN]) await help_test_discovery_removal( - hass, mqtt_mock_entry_no_yaml_config, caplog, climate.DOMAIN, data + hass, mqtt_mock_entry, caplog, climate.DOMAIN, data ) async def test_discovery_update_climate( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered climate.""" config1 = {"name": "Beer"} config2 = {"name": "Milk"} await help_test_discovery_update( - hass, mqtt_mock_entry_no_yaml_config, caplog, climate.DOMAIN, config1, config2 + hass, mqtt_mock_entry, caplog, climate.DOMAIN, config1, config2 ) async def test_discovery_update_unchanged_climate( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered climate.""" @@ -1879,7 +1879,7 @@ async def test_discovery_update_unchanged_climate( ) as discovery_update: await help_test_discovery_update_unchanged( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, climate.DOMAIN, data1, @@ -1890,55 +1890,55 @@ async def test_discovery_update_unchanged_climate( @pytest.mark.no_fail_on_log_exception async def test_discovery_broken( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test handling of bad discovery message.""" data1 = '{ "name": "Beer", "power_command_topic": "test_topic#" }' data2 = '{ "name": "Milk", "power_command_topic": "test_topic" }' await help_test_discovery_broken( - hass, mqtt_mock_entry_no_yaml_config, caplog, climate.DOMAIN, data1, data2 + hass, mqtt_mock_entry, caplog, climate.DOMAIN, data1, data2 ) async def test_entity_device_info_with_connection( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT climate device registry integration.""" await help_test_entity_device_info_with_connection( - hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, climate.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_with_identifier( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT climate device registry integration.""" await help_test_entity_device_info_with_identifier( - hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, climate.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry update.""" await help_test_entity_device_info_update( - hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, climate.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_remove( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry remove.""" await help_test_entity_device_info_remove( - hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, climate.DOMAIN, DEFAULT_CONFIG ) async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" config = { @@ -1952,7 +1952,7 @@ async def test_entity_id_update_subscriptions( } await help_test_entity_id_update_subscriptions( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, climate.DOMAIN, config, ["test-topic", "avty-topic"], @@ -1960,16 +1960,16 @@ async def test_entity_id_update_subscriptions( async def test_entity_id_update_discovery_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT discovery update when entity_id is updated.""" await help_test_entity_id_update_discovery_update( - hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, climate.DOMAIN, DEFAULT_CONFIG ) async def test_entity_debug_info_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT debug info.""" config = { @@ -1983,7 +1983,7 @@ async def test_entity_debug_info_message( } await help_test_entity_debug_info_message( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, climate.DOMAIN, config, climate.SERVICE_TURN_ON, @@ -1995,10 +1995,10 @@ async def test_entity_debug_info_message( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_precision_default( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test that setting precision to tenths works as intended.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() await common.async_set_temperature( hass, temperature=23.67, entity_id=ENTITY_CLIMATE @@ -2013,10 +2013,10 @@ async def test_precision_default( [help_custom_config(climate.DOMAIN, DEFAULT_CONFIG, ({"precision": 0.5},))], ) async def test_precision_halves( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test that setting precision to halves works as intended.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() await common.async_set_temperature( hass, temperature=23.67, entity_id=ENTITY_CLIMATE @@ -2031,10 +2031,10 @@ async def test_precision_halves( [help_custom_config(climate.DOMAIN, DEFAULT_CONFIG, ({"precision": 1.0},))], ) async def test_precision_whole( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test that setting precision to whole works as intended.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() await common.async_set_temperature( hass, temperature=23.67, entity_id=ENTITY_CLIMATE @@ -2129,7 +2129,7 @@ async def test_precision_whole( ) async def test_publishing_with_custom_encoding( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, service: str, topic: str, @@ -2146,7 +2146,7 @@ async def test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, domain, config, @@ -2224,15 +2224,15 @@ async def test_publishing_with_custom_encoding( ) async def test_humidity_configuration_validity( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, valid: bool, ) -> None: """Test the validity of humidity configurations.""" if valid: - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() return with pytest.raises(AssertionError): - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async def test_reloadable( @@ -2247,21 +2247,21 @@ async def test_reloadable( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_setup_manual_entity_from_yaml( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setup manual configured MQTT entity.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() platform = climate.DOMAIN assert hass.states.get(f"{platform}.test") async def test_unload_entry( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test unloading the config entry.""" domain = climate.DOMAIN config = DEFAULT_CONFIG await help_test_unload_config_entry_with_platform( - hass, mqtt_mock_entry_no_yaml_config, domain, config + hass, mqtt_mock_entry, domain, config ) diff --git a/tests/components/mqtt/test_common.py b/tests/components/mqtt/test_common.py index 154f91974a1..620f1e95c23 100644 --- a/tests/components/mqtt/test_common.py +++ b/tests/components/mqtt/test_common.py @@ -145,11 +145,11 @@ def help_custom_config( async def help_test_availability_when_connection_lost( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, domain: str, ) -> None: """Test availability after MQTT disconnection.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() await hass.async_block_till_done() state = hass.states.get(f"{domain}.test") @@ -165,13 +165,13 @@ async def help_test_availability_when_connection_lost( async def help_test_availability_without_topic( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, domain: str, config: ConfigType, ) -> None: """Test availability without defined availability topic.""" assert "availability_topic" not in config[mqtt.DOMAIN][domain] - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() await hass.async_block_till_done() state = hass.states.get(f"{domain}.test") @@ -226,7 +226,7 @@ async def help_test_default_availability_payload( async def help_test_default_availability_list_payload( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, domain: str, config: ConfigType, no_assumed_state: bool = False, @@ -243,7 +243,7 @@ async def help_test_default_availability_list_payload( {"topic": "availability-topic1"}, {"topic": "availability-topic2"}, ] - await help_setup_component(hass, mqtt_mock_entry_no_yaml_config, domain, config) + await help_setup_component(hass, mqtt_mock_entry, domain, config) state = hass.states.get(f"{domain}.test") assert state and state.state == STATE_UNAVAILABLE @@ -286,7 +286,7 @@ async def help_test_default_availability_list_payload( async def help_test_default_availability_list_payload_all( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, domain: str, config: ConfigType, no_assumed_state: bool = False, @@ -304,7 +304,7 @@ async def help_test_default_availability_list_payload_all( {"topic": "availability-topic1"}, {"topic": "availability-topic2"}, ] - await help_setup_component(hass, mqtt_mock_entry_no_yaml_config, domain, config) + await help_setup_component(hass, mqtt_mock_entry, domain, config) state = hass.states.get(f"{domain}.test") assert state and state.state == STATE_UNAVAILABLE @@ -348,7 +348,7 @@ async def help_test_default_availability_list_payload_all( async def help_test_default_availability_list_payload_any( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, domain: str, config: ConfigType, no_assumed_state: bool = False, @@ -366,7 +366,7 @@ async def help_test_default_availability_list_payload_any( {"topic": "availability-topic1"}, {"topic": "availability-topic2"}, ] - await help_setup_component(hass, mqtt_mock_entry_no_yaml_config, domain, config) + await help_setup_component(hass, mqtt_mock_entry, domain, config) state = hass.states.get(f"{domain}.test") assert state and state.state == STATE_UNAVAILABLE @@ -429,7 +429,7 @@ async def help_test_default_availability_list_single( async def help_test_custom_availability_payload( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, domain: str, config: ConfigType, no_assumed_state: bool = False, @@ -445,7 +445,7 @@ async def help_test_custom_availability_payload( config[mqtt.DOMAIN][domain]["availability_topic"] = "availability-topic" config[mqtt.DOMAIN][domain]["payload_available"] = "good" config[mqtt.DOMAIN][domain]["payload_not_available"] = "nogood" - await help_setup_component(hass, mqtt_mock_entry_no_yaml_config, domain, config) + await help_setup_component(hass, mqtt_mock_entry, domain, config) state = hass.states.get(f"{domain}.test") assert state and state.state == STATE_UNAVAILABLE @@ -476,7 +476,7 @@ async def help_test_custom_availability_payload( async def help_test_discovery_update_availability( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, domain: str, config: ConfigType, ) -> None: @@ -484,7 +484,7 @@ async def help_test_discovery_update_availability( This is a test helper for the MQTTAvailability mixin. """ - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() # Add availability settings to config config1 = copy.deepcopy(config) config1[mqtt.DOMAIN][domain]["availability_topic"] = "availability-topic1" @@ -554,7 +554,7 @@ async def help_test_discovery_update_availability( async def help_test_setting_attribute_via_mqtt_json_message( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, domain: str, config: ConfigType, ) -> None: @@ -565,7 +565,7 @@ async def help_test_setting_attribute_via_mqtt_json_message( # Add JSON attributes settings to config config = copy.deepcopy(config) config[mqtt.DOMAIN][domain]["json_attributes_topic"] = "attr-topic" - await help_setup_component(hass, mqtt_mock_entry_no_yaml_config, domain, config) + await help_setup_component(hass, mqtt_mock_entry, domain, config) async_fire_mqtt_message(hass, "attr-topic", '{ "val": "100" }') state = hass.states.get(f"{domain}.test") @@ -575,7 +575,7 @@ async def help_test_setting_attribute_via_mqtt_json_message( async def help_test_setting_blocked_attribute_via_mqtt_json_message( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, domain: str, config: ConfigType, extra_blocked_attributes: frozenset[str] | None, @@ -584,7 +584,7 @@ async def help_test_setting_blocked_attribute_via_mqtt_json_message( This is a test helper for the MqttAttributes mixin. """ - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() extra_blocked_attribute_list = list(extra_blocked_attributes or []) # Add JSON attributes settings to config @@ -608,7 +608,7 @@ async def help_test_setting_blocked_attribute_via_mqtt_json_message( async def help_test_setting_attribute_with_template( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, domain: str, config: ConfigType, ) -> None: @@ -622,7 +622,7 @@ async def help_test_setting_attribute_with_template( config[mqtt.DOMAIN][domain][ "json_attributes_template" ] = "{{ value_json['Timer1'] | tojson }}" - await help_setup_component(hass, mqtt_mock_entry_no_yaml_config, domain, config) + await help_setup_component(hass, mqtt_mock_entry, domain, config) async_fire_mqtt_message( hass, "attr-topic", json.dumps({"Timer1": {"Arm": 0, "Time": "22:18"}}) @@ -636,7 +636,7 @@ async def help_test_setting_attribute_with_template( async def help_test_update_with_json_attrs_not_dict( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, domain: str, config: ConfigType, @@ -648,7 +648,7 @@ async def help_test_update_with_json_attrs_not_dict( # Add JSON attributes settings to config config = copy.deepcopy(config) config[mqtt.DOMAIN][domain]["json_attributes_topic"] = "attr-topic" - await help_setup_component(hass, mqtt_mock_entry_no_yaml_config, domain, config) + await help_setup_component(hass, mqtt_mock_entry, domain, config) async_fire_mqtt_message(hass, "attr-topic", '[ "list", "of", "things"]') state = hass.states.get(f"{domain}.test") @@ -659,7 +659,7 @@ async def help_test_update_with_json_attrs_not_dict( async def help_test_update_with_json_attrs_bad_json( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, domain: str, config: ConfigType, @@ -671,7 +671,7 @@ async def help_test_update_with_json_attrs_bad_json( # Add JSON attributes settings to config config = copy.deepcopy(config) config[mqtt.DOMAIN][domain]["json_attributes_topic"] = "attr-topic" - await help_setup_component(hass, mqtt_mock_entry_no_yaml_config, domain, config) + await help_setup_component(hass, mqtt_mock_entry, domain, config) async_fire_mqtt_message(hass, "attr-topic", "This is not JSON") @@ -682,7 +682,7 @@ async def help_test_update_with_json_attrs_bad_json( async def help_test_discovery_update_attr( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, domain: str, config: ConfigType, @@ -691,7 +691,7 @@ async def help_test_discovery_update_attr( This is a test helper for the MqttAttributes mixin. """ - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() # Add JSON attributes settings to config config1 = copy.deepcopy(config) config1[mqtt.DOMAIN][domain]["json_attributes_topic"] = "attr-topic1" @@ -723,18 +723,18 @@ async def help_test_discovery_update_attr( async def help_test_unique_id( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, domain: str, ) -> None: """Test unique id option only creates one entity per unique_id.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() await hass.async_block_till_done() assert len(hass.states.async_entity_ids(domain)) == 1 async def help_test_discovery_removal( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, domain: str, data: str, @@ -743,7 +743,7 @@ async def help_test_discovery_removal( This is a test helper for the MqttDiscoveryUpdate mixin. """ - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data) await hass.async_block_till_done() @@ -760,7 +760,7 @@ async def help_test_discovery_removal( async def help_test_discovery_update( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog, domain, discovery_config1: DiscoveryInfoType, @@ -772,7 +772,7 @@ async def help_test_discovery_update( This is a test helper for the MqttDiscoveryUpdate mixin. """ - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() # Add some future configuration to the configurations config1 = copy.deepcopy(discovery_config1) config1["some_future_option_1"] = "future_option_1" @@ -825,7 +825,7 @@ async def help_test_discovery_update( async def help_test_discovery_update_unchanged( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, domain: str, data1: str, @@ -835,7 +835,7 @@ async def help_test_discovery_update_unchanged( This is a test helper for the MqttDiscoveryUpdate mixin. """ - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data1) await hass.async_block_till_done() @@ -851,14 +851,14 @@ async def help_test_discovery_update_unchanged( async def help_test_discovery_broken( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, domain: str, data1: str, data2: str, ) -> None: """Test handling of bad discovery message.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data1) await hass.async_block_till_done() @@ -877,7 +877,7 @@ async def help_test_discovery_broken( async def help_test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, domain: str, config: ConfigType, topic: str, @@ -951,7 +951,7 @@ async def help_test_encoding_subscribable_topics( init_payload_value_utf8 = init_payload[1].encode("utf-8") init_payload_value_utf16 = init_payload[1].encode("utf-16") - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message( hass, f"homeassistant/{domain}/item1/config", json.dumps(config1) ) @@ -1012,7 +1012,7 @@ async def help_test_encoding_subscribable_topics( async def help_test_entity_device_info_with_identifier( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, domain: str, config: ConfigType, ) -> None: @@ -1020,7 +1020,7 @@ async def help_test_entity_device_info_with_identifier( This is a test helper for the MqttDiscoveryUpdate mixin. """ - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() # Add device settings to config config = copy.deepcopy(config[mqtt.DOMAIN][domain]) config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID) @@ -1046,7 +1046,7 @@ async def help_test_entity_device_info_with_identifier( async def help_test_entity_device_info_with_connection( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, domain: str, config: ConfigType, ) -> None: @@ -1054,7 +1054,7 @@ async def help_test_entity_device_info_with_connection( This is a test helper for the MqttDiscoveryUpdate mixin. """ - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() # Add device settings to config config = copy.deepcopy(config[mqtt.DOMAIN][domain]) config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_MAC) @@ -1082,12 +1082,12 @@ async def help_test_entity_device_info_with_connection( async def help_test_entity_device_info_remove( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, domain: str, config: ConfigType, ) -> None: """Test device registry remove.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() # Add device settings to config config = copy.deepcopy(config[mqtt.DOMAIN][domain]) config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID) @@ -1114,7 +1114,7 @@ async def help_test_entity_device_info_remove( async def help_test_entity_device_info_update( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, domain: str, config: ConfigType, ) -> None: @@ -1122,7 +1122,7 @@ async def help_test_entity_device_info_update( This is a test helper for the MqttDiscoveryUpdate mixin. """ - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() # Add device settings to config config = copy.deepcopy(config[mqtt.DOMAIN][domain]) config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID) @@ -1150,7 +1150,7 @@ async def help_test_entity_device_info_update( async def help_test_entity_id_update_subscriptions( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, domain: str, config: ConfigType, topics: list[str] | None = None, @@ -1169,7 +1169,7 @@ async def help_test_entity_id_update_subscriptions( entity_registry = er.async_get(hass) mqtt_mock = await help_setup_component( - hass, mqtt_mock_entry_no_yaml_config, domain, config, use_discovery=True + hass, mqtt_mock_entry, domain, config, use_discovery=True ) assert mqtt_mock is not None @@ -1196,14 +1196,14 @@ async def help_test_entity_id_update_subscriptions( async def help_test_entity_id_update_discovery_update( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, domain: str, config: ConfigType, topic: str | None = None, ) -> None: """Test MQTT discovery update after entity_id is updated.""" # Add unique_id to config - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() config = copy.deepcopy(config) config[mqtt.DOMAIN][domain]["unique_id"] = "TOTALLY_UNIQUE" @@ -1243,7 +1243,7 @@ async def help_test_entity_id_update_discovery_update( async def help_test_entity_debug_info( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, domain: str, config: ConfigType, ) -> None: @@ -1251,7 +1251,7 @@ async def help_test_entity_debug_info( This is a test helper for MQTT debug_info. """ - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() # Add device settings to config config = copy.deepcopy(config[mqtt.DOMAIN][domain]) config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID) @@ -1284,7 +1284,7 @@ async def help_test_entity_debug_info( async def help_test_entity_debug_info_max_messages( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, domain: str, config: ConfigType, ) -> None: @@ -1292,7 +1292,7 @@ async def help_test_entity_debug_info_max_messages( This is a test helper for MQTT debug_info. """ - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() # Add device settings to config config = copy.deepcopy(config[mqtt.DOMAIN][domain]) config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID) @@ -1342,7 +1342,7 @@ async def help_test_entity_debug_info_max_messages( async def help_test_entity_debug_info_message( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, domain: str, config: ConfigType, service: str, @@ -1357,7 +1357,7 @@ async def help_test_entity_debug_info_message( This is a test helper for MQTT debug_info. """ # Add device settings to config - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() config = copy.deepcopy(config[mqtt.DOMAIN][domain]) config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID) config["unique_id"] = "veryunique" @@ -1454,7 +1454,7 @@ async def help_test_entity_debug_info_message( async def help_test_entity_debug_info_remove( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, domain: str, config: ConfigType, ) -> None: @@ -1462,7 +1462,7 @@ async def help_test_entity_debug_info_remove( This is a test helper for MQTT debug_info. """ - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() # Add device settings to config config = copy.deepcopy(config[mqtt.DOMAIN][domain]) config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID) @@ -1504,7 +1504,7 @@ async def help_test_entity_debug_info_remove( async def help_test_entity_debug_info_update_entity_id( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, domain: str, config: ConfigType, ) -> None: @@ -1512,7 +1512,7 @@ async def help_test_entity_debug_info_update_entity_id( This is a test helper for MQTT debug_info. """ - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() # Add device settings to config config = copy.deepcopy(config[mqtt.DOMAIN][domain]) config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID) @@ -1566,12 +1566,12 @@ async def help_test_entity_debug_info_update_entity_id( async def help_test_entity_disabled_by_default( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, domain: str, config: ConfigType, ) -> None: """Test device registry remove.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() # Add device settings to config config = copy.deepcopy(config[mqtt.DOMAIN][domain]) config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID) @@ -1608,12 +1608,12 @@ async def help_test_entity_disabled_by_default( async def help_test_entity_category( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, domain: str, config: ConfigType, ) -> None: """Test device registry remove.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() # Add device settings to config config = copy.deepcopy(config[mqtt.DOMAIN][domain]) config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID) @@ -1655,7 +1655,7 @@ async def help_test_entity_category( async def help_test_publishing_with_custom_encoding( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, domain: str, config: ConfigType, @@ -1700,7 +1700,7 @@ async def help_test_publishing_with_custom_encoding( service_data[test_id].update(parameters) # setup test entities using discovery - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() item: int = 0 for component_config in setup_config: conf = json.dumps(component_config) @@ -1868,7 +1868,7 @@ async def help_test_unload_config_entry(hass: HomeAssistant) -> None: async def help_test_unload_config_entry_with_platform( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, domain: str, config: dict[str, dict[str, Any]], ) -> None: @@ -1879,7 +1879,7 @@ async def help_test_unload_config_entry_with_platform( config_name = config_setup with patch("homeassistant.config.load_yaml_config_file", return_value=config_name): - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() # prepare setup through discovery discovery_setup = copy.deepcopy(config[mqtt.DOMAIN][domain]) diff --git a/tests/components/mqtt/test_config_flow.py b/tests/components/mqtt/test_config_flow.py index 4c3ce54be82..78bd598436d 100644 --- a/tests/components/mqtt/test_config_flow.py +++ b/tests/components/mqtt/test_config_flow.py @@ -443,14 +443,14 @@ async def test_hassio_cannot_connect( async def test_option_flow( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, mock_try_connection: MagicMock, ) -> None: """Test config flow options.""" with patch( "homeassistant.config.async_hass_config_yaml", AsyncMock(return_value={}) ) as yaml_mock: - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() mock_try_connection.return_value = True config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0] config_entry.data = { @@ -540,7 +540,7 @@ async def test_option_flow( ) async def test_bad_certificate( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, mock_try_connection_success: MqttMockPahoClient, mock_ssl_context: dict[str, MagicMock], mock_process_uploaded_file: MagicMock, @@ -577,7 +577,7 @@ async def test_bad_certificate( # Client key file without client cert, client cert without key file test_input.pop(mqtt.CONF_CLIENT_KEY) - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() mock_try_connection.return_value = True config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0] # Add at least one advanced option to get the full form @@ -636,7 +636,7 @@ async def test_bad_certificate( ) async def test_keepalive_validation( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, mock_try_connection: MagicMock, mock_reload_after_entry_update: MagicMock, input_value: str, @@ -650,7 +650,7 @@ async def test_keepalive_validation( mqtt.CONF_KEEPALIVE: input_value, } - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() mock_try_connection.return_value = True config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0] # Add at least one advanced option to get the full form @@ -682,12 +682,12 @@ async def test_keepalive_validation( async def test_disable_birth_will( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, mock_try_connection: MagicMock, mock_reload_after_entry_update: MagicMock, ) -> None: """Test disabling birth and will.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() mock_try_connection.return_value = True config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0] config_entry.data = { @@ -753,12 +753,12 @@ async def test_disable_birth_will( async def test_invalid_discovery_prefix( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, mock_try_connection: MagicMock, mock_reload_after_entry_update: MagicMock, ) -> None: """Test setting an invalid discovery prefix.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() mock_try_connection.return_value = True config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0] config_entry.data = { @@ -832,12 +832,12 @@ def get_suggested(schema: vol.Schema, key: str) -> Any: async def test_option_flow_default_suggested_values( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + 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_no_yaml_config() + await mqtt_mock_entry() config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0] config_entry.data = { mqtt.CONF_BROKER: "test-broker", @@ -987,7 +987,7 @@ async def test_option_flow_default_suggested_values( ) async def test_skipping_advanced_options( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, mock_try_connection: MagicMock, mock_reload_after_entry_update: MagicMock, advanced_options: bool, @@ -1001,7 +1001,7 @@ async def test_skipping_advanced_options( "advanced_options": advanced_options, } - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() mock_try_connection.return_value = True config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0] # Initiate with a basic setup diff --git a/tests/components/mqtt/test_cover.py b/tests/components/mqtt/test_cover.py index 3fb008b2181..c388ded6587 100644 --- a/tests/components/mqtt/test_cover.py +++ b/tests/components/mqtt/test_cover.py @@ -109,10 +109,10 @@ def cover_platform_only(): ], ) async def test_state_via_state_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the controlling state via topic.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("cover.test") assert state.state == STATE_UNKNOWN @@ -150,10 +150,10 @@ async def test_state_via_state_topic( ], ) async def test_opening_and_closing_state_via_custom_state_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the controlling opening and closing state via a custom payload.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("cover.test") assert state.state == STATE_UNKNOWN @@ -195,10 +195,10 @@ async def test_opening_and_closing_state_via_custom_state_payload( ], ) async def test_open_closed_state_from_position_optimistic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the state after setting the position using optimistic mode.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("cover.test") assert state.state == STATE_UNKNOWN @@ -247,10 +247,10 @@ async def test_open_closed_state_from_position_optimistic( ], ) async def test_position_via_position_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the controlling state via topic.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("cover.test") assert state.state == STATE_UNKNOWN @@ -289,10 +289,10 @@ async def test_position_via_position_topic( ], ) async def test_state_via_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the controlling state via topic.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("cover.test") assert state.state == STATE_UNKNOWN @@ -330,10 +330,10 @@ async def test_state_via_template( ], ) async def test_state_via_template_and_entity_id( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the controlling state via topic.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("cover.test") assert state.state == STATE_UNKNOWN @@ -369,11 +369,11 @@ async def test_state_via_template_and_entity_id( ) async def test_state_via_template_with_json_value( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test the controlling state via topic with JSON value.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("cover.test") assert state.state == STATE_UNKNOWN @@ -418,10 +418,10 @@ async def test_state_via_template_with_json_value( ], ) async def test_position_via_template_and_entity_id( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the controlling state via topic.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("cover.test") assert state.state == STATE_UNKNOWN @@ -508,11 +508,11 @@ async def test_position_via_template_and_entity_id( ) async def test_optimistic_flag( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, assumed_state: bool, ) -> None: """Test assumed_state is set correctly.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("cover.test") assert state.state == STATE_UNKNOWN @@ -537,10 +537,10 @@ async def test_optimistic_flag( ], ) async def test_optimistic_state_change( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test changing state optimistically.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("cover.test") assert state.state == STATE_UNKNOWN @@ -599,10 +599,10 @@ async def test_optimistic_state_change( ], ) async def test_optimistic_state_change_with_position( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test changing state optimistically.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("cover.test") assert state.state == STATE_UNKNOWN @@ -665,10 +665,10 @@ async def test_optimistic_state_change_with_position( ], ) async def test_send_open_cover_command( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the sending of open_cover.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("cover.test") assert state.state == STATE_UNKNOWN @@ -698,10 +698,10 @@ async def test_send_open_cover_command( ], ) async def test_send_close_cover_command( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the sending of close_cover.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("cover.test") assert state.state == STATE_UNKNOWN @@ -731,10 +731,10 @@ async def test_send_close_cover_command( ], ) async def test_send_stop_cover_command( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the sending of stop_cover.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("cover.test") assert state.state == STATE_UNKNOWN @@ -768,10 +768,10 @@ async def test_send_stop_cover_command( ], ) async def test_current_cover_position( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the current cover position.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state_attributes_dict = hass.states.get("cover.test").attributes assert ATTR_CURRENT_POSITION not in state_attributes_dict @@ -823,10 +823,10 @@ async def test_current_cover_position( ], ) async def test_current_cover_position_inverted( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the current cover position.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state_attributes_dict = hass.states.get("cover.test").attributes assert ATTR_CURRENT_POSITION not in state_attributes_dict @@ -886,11 +886,11 @@ async def test_current_cover_position_inverted( async def test_optimistic_position( hass: HomeAssistant, caplog: pytest.LogCaptureFixture, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test optimistic position is not supported.""" with pytest.raises(AssertionError): - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() assert ( "Invalid config for [mqtt]: 'set_position_topic' must be set together with 'position_topic'" in caplog.text @@ -918,10 +918,10 @@ async def test_optimistic_position( ], ) async def test_position_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test cover position update from received MQTT message.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state_attributes_dict = hass.states.get("cover.test").attributes assert ATTR_CURRENT_POSITION not in state_attributes_dict @@ -985,12 +985,12 @@ async def test_position_update( ) async def test_set_position_templated( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, pos_call: int, pos_message: str, ) -> None: """Test setting cover position via template.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() await hass.services.async_call( cover.DOMAIN, @@ -1035,10 +1035,10 @@ async def test_set_position_templated( ], ) async def test_set_position_templated_and_attributes( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setting cover position via template and using entities attributes.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() await hass.services.async_call( cover.DOMAIN, @@ -1074,10 +1074,10 @@ async def test_set_position_templated_and_attributes( ], ) async def test_set_tilt_templated( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setting cover tilt position via template.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() await hass.services.async_call( cover.DOMAIN, @@ -1119,10 +1119,10 @@ async def test_set_tilt_templated( ], ) async def test_set_tilt_templated_and_attributes( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setting cover tilt position via template and using entities attributes.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() await hass.services.async_call( cover.DOMAIN, @@ -1200,10 +1200,10 @@ async def test_set_tilt_templated_and_attributes( ], ) async def test_set_position_untemplated( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setting cover position via template.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() await hass.services.async_call( cover.DOMAIN, @@ -1236,10 +1236,10 @@ async def test_set_position_untemplated( ], ) async def test_set_position_untemplated_custom_percentage_range( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setting cover position via template.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() await hass.services.async_call( cover.DOMAIN, @@ -1270,10 +1270,10 @@ async def test_set_position_untemplated_custom_percentage_range( ], ) async def test_no_command_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test with no command topic.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() assert hass.states.get("cover.test").attributes["supported_features"] == 240 @@ -1296,10 +1296,10 @@ async def test_no_command_topic( ], ) async def test_no_payload_close( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test with no close payload.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() assert hass.states.get("cover.test").attributes["supported_features"] == 9 @@ -1322,10 +1322,10 @@ async def test_no_payload_close( ], ) async def test_no_payload_open( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test with no open payload.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() assert hass.states.get("cover.test").attributes["supported_features"] == 10 @@ -1348,10 +1348,10 @@ async def test_no_payload_open( ], ) async def test_no_payload_stop( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test with no stop payload.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() assert hass.states.get("cover.test").attributes["supported_features"] == 3 @@ -1376,10 +1376,10 @@ async def test_no_payload_stop( ], ) async def test_with_command_topic_and_tilt( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test with command topic and tilt config.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() assert hass.states.get("cover.test").attributes["supported_features"] == 251 @@ -1405,10 +1405,10 @@ async def test_with_command_topic_and_tilt( ], ) async def test_tilt_defaults( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the defaults.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state_attributes_dict = hass.states.get("cover.test").attributes # Tilt position is not yet known @@ -1436,11 +1436,11 @@ async def test_tilt_defaults( ], ) async def test_tilt_via_invocation_defaults( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test tilt defaults on close/open.""" await hass.async_block_till_done() - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() await hass.services.async_call( cover.DOMAIN, @@ -1525,10 +1525,10 @@ async def test_tilt_via_invocation_defaults( ], ) async def test_tilt_given_value( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test tilting to a given value.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() await hass.services.async_call( cover.DOMAIN, @@ -1618,10 +1618,10 @@ async def test_tilt_given_value( ], ) async def test_tilt_given_value_optimistic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test tilting to a given value.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() await hass.services.async_call( cover.DOMAIN, @@ -1700,10 +1700,10 @@ async def test_tilt_given_value_optimistic( ], ) async def test_tilt_given_value_altered_range( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test tilting to a given value.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() await hass.services.async_call( cover.DOMAIN, @@ -1775,10 +1775,10 @@ async def test_tilt_given_value_altered_range( ], ) async def test_tilt_via_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test tilt by updating status via MQTT.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, "tilt-status-topic", "0") @@ -1819,10 +1819,10 @@ async def test_tilt_via_topic( ], ) async def test_tilt_via_topic_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test tilt by updating status via MQTT and template.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, "tilt-status-topic", "99") @@ -1864,11 +1864,11 @@ async def test_tilt_via_topic_template( ) async def test_tilt_via_topic_template_json_value( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test tilt by updating status via MQTT and template with JSON value.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, "tilt-status-topic", '{"Var1": 9, "Var2": 30}') @@ -1914,10 +1914,10 @@ async def test_tilt_via_topic_template_json_value( ], ) async def test_tilt_via_topic_altered_range( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test tilt status via MQTT with altered tilt range.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, "tilt-status-topic", "0") @@ -1966,10 +1966,10 @@ async def test_tilt_via_topic_altered_range( async def test_tilt_status_out_of_range_warning( hass: HomeAssistant, caplog: pytest.LogCaptureFixture, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test tilt status via MQTT tilt out of range warning message.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, "tilt-status-topic", "60") @@ -2003,10 +2003,10 @@ async def test_tilt_status_out_of_range_warning( async def test_tilt_status_not_numeric_warning( hass: HomeAssistant, caplog: pytest.LogCaptureFixture, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test tilt status via MQTT tilt not numeric warning message.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, "tilt-status-topic", "abc") @@ -2036,10 +2036,10 @@ async def test_tilt_status_not_numeric_warning( ], ) async def test_tilt_via_topic_altered_range_inverted( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test tilt status via MQTT with altered tilt range and inverted tilt position.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, "tilt-status-topic", "0") @@ -2089,10 +2089,10 @@ async def test_tilt_via_topic_altered_range_inverted( ], ) async def test_tilt_via_topic_template_altered_range( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test tilt status via MQTT and template with altered tilt range.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, "tilt-status-topic", "99") @@ -2137,10 +2137,10 @@ async def test_tilt_via_topic_template_altered_range( ], ) async def test_tilt_position( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test tilt via method invocation.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() await hass.services.async_call( cover.DOMAIN, @@ -2176,10 +2176,10 @@ async def test_tilt_position( ], ) async def test_tilt_position_templated( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test tilt position via template.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() await hass.services.async_call( cover.DOMAIN, @@ -2218,10 +2218,10 @@ async def test_tilt_position_templated( ], ) async def test_tilt_position_altered_range( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test tilt via method invocation with altered range.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() await hass.services.async_call( cover.DOMAIN, @@ -2581,39 +2581,39 @@ async def test_find_in_range_altered_inverted(hass: HomeAssistant) -> None: @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_when_connection_lost( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability after MQTT disconnection.""" await help_test_availability_when_connection_lost( - hass, mqtt_mock_entry_no_yaml_config, cover.DOMAIN + hass, mqtt_mock_entry, cover.DOMAIN ) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_without_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability without defined availability topic.""" await help_test_availability_without_topic( - hass, mqtt_mock_entry_no_yaml_config, cover.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, cover.DOMAIN, DEFAULT_CONFIG ) async def test_default_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by default payload with defined topic.""" await help_test_default_availability_payload( - hass, mqtt_mock_entry_no_yaml_config, cover.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, cover.DOMAIN, DEFAULT_CONFIG ) async def test_custom_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by custom payload with defined topic.""" await help_test_custom_availability_payload( - hass, mqtt_mock_entry_no_yaml_config, cover.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, cover.DOMAIN, DEFAULT_CONFIG ) @@ -2632,10 +2632,10 @@ async def test_custom_availability_payload( ], ) async def test_valid_device_class( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of a valid device class.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("cover.test") assert state.attributes.get("device_class") == "garage" @@ -2658,30 +2658,30 @@ async def test_valid_device_class( async def test_invalid_device_class( hass: HomeAssistant, caplog: pytest.LogCaptureFixture, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test the setting of an invalid device class.""" with pytest.raises(AssertionError): - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() assert "Invalid config for [mqtt]: expected CoverDeviceClass" in caplog.text async def test_setting_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_via_mqtt_json_message( - hass, mqtt_mock_entry_no_yaml_config, cover.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, cover.DOMAIN, DEFAULT_CONFIG ) async def test_setting_blocked_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_blocked_attribute_via_mqtt_json_message( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, cover.DOMAIN, DEFAULT_CONFIG, MQTT_COVER_ATTRIBUTES_BLOCKED, @@ -2689,23 +2689,23 @@ async def test_setting_blocked_attribute_via_mqtt_json_message( async def test_setting_attribute_with_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_with_template( - hass, mqtt_mock_entry_no_yaml_config, cover.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, cover.DOMAIN, DEFAULT_CONFIG ) async def test_update_with_json_attrs_not_dict( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_not_dict( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, cover.DOMAIN, DEFAULT_CONFIG, @@ -2714,13 +2714,13 @@ async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_bad_json( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_bad_json( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, cover.DOMAIN, DEFAULT_CONFIG, @@ -2729,13 +2729,13 @@ async def test_update_with_json_attrs_bad_json( async def test_discovery_update_attr( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered MQTTAttributes.""" await help_test_discovery_update_attr( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, cover.DOMAIN, DEFAULT_CONFIG, @@ -2764,40 +2764,38 @@ async def test_discovery_update_attr( ], ) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test unique_id option only creates one cover per id.""" - await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, cover.DOMAIN) + await help_test_unique_id(hass, mqtt_mock_entry, cover.DOMAIN) async def test_discovery_removal_cover( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test removal of discovered cover.""" data = '{ "name": "test", "command_topic": "test_topic" }' - await help_test_discovery_removal( - hass, mqtt_mock_entry_no_yaml_config, caplog, cover.DOMAIN, data - ) + await help_test_discovery_removal(hass, mqtt_mock_entry, caplog, cover.DOMAIN, data) async def test_discovery_update_cover( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered cover.""" config1 = {"name": "Beer", "command_topic": "test_topic"} config2 = {"name": "Milk", "command_topic": "test_topic"} await help_test_discovery_update( - hass, mqtt_mock_entry_no_yaml_config, caplog, cover.DOMAIN, config1, config2 + hass, mqtt_mock_entry, caplog, cover.DOMAIN, config1, config2 ) async def test_discovery_update_unchanged_cover( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered cover.""" @@ -2807,7 +2805,7 @@ async def test_discovery_update_unchanged_cover( ) as discovery_update: await help_test_discovery_update_unchanged( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, cover.DOMAIN, data1, @@ -2818,78 +2816,78 @@ async def test_discovery_update_unchanged_cover( @pytest.mark.no_fail_on_log_exception async def test_discovery_broken( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test handling of bad discovery message.""" data1 = '{ "name": "Beer", "command_topic": "test_topic#" }' data2 = '{ "name": "Milk", "command_topic": "test_topic" }' await help_test_discovery_broken( - hass, mqtt_mock_entry_no_yaml_config, caplog, cover.DOMAIN, data1, data2 + hass, mqtt_mock_entry, caplog, cover.DOMAIN, data1, data2 ) async def test_entity_device_info_with_connection( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT cover device registry integration.""" await help_test_entity_device_info_with_connection( - hass, mqtt_mock_entry_no_yaml_config, cover.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, cover.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_with_identifier( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT cover device registry integration.""" await help_test_entity_device_info_with_identifier( - hass, mqtt_mock_entry_no_yaml_config, cover.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, cover.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry update.""" await help_test_entity_device_info_update( - hass, mqtt_mock_entry_no_yaml_config, cover.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, cover.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_remove( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry remove.""" await help_test_entity_device_info_remove( - hass, mqtt_mock_entry_no_yaml_config, cover.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, cover.DOMAIN, DEFAULT_CONFIG ) async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" await help_test_entity_id_update_subscriptions( - hass, mqtt_mock_entry_no_yaml_config, cover.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, cover.DOMAIN, DEFAULT_CONFIG ) async def test_entity_id_update_discovery_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT discovery update when entity_id is updated.""" await help_test_entity_id_update_discovery_update( - hass, mqtt_mock_entry_no_yaml_config, cover.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, cover.DOMAIN, DEFAULT_CONFIG ) async def test_entity_debug_info_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT debug info.""" await help_test_entity_debug_info_message( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, cover.DOMAIN, DEFAULT_CONFIG, SERVICE_OPEN_COVER, @@ -2918,10 +2916,10 @@ async def test_entity_debug_info_message( ], ) async def test_state_and_position_topics_state_not_set_via_position_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test state is not set via position topic when both state and position topics are set.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("cover.test") assert state.state == STATE_UNKNOWN @@ -2980,10 +2978,10 @@ async def test_state_and_position_topics_state_not_set_via_position_topic( ], ) async def test_set_state_via_position_using_stopped_state( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the controlling state via position topic using stopped state.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("cover.test") assert state.state == STATE_UNKNOWN @@ -3033,10 +3031,10 @@ async def test_set_state_via_position_using_stopped_state( ], ) async def test_position_via_position_topic_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test position by updating status via position template.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, "get-position-topic", "99") @@ -3072,11 +3070,11 @@ async def test_position_via_position_topic_template( ) async def test_position_via_position_topic_template_json_value( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test position by updating status via position template with a JSON value.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, "get-position-topic", '{"Var1": 9, "Var2": 60}') @@ -3122,10 +3120,10 @@ async def test_position_via_position_topic_template_json_value( ], ) async def test_position_template_with_entity_id( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test position by updating status via position template.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, "get-position-topic", "10") @@ -3160,10 +3158,10 @@ async def test_position_template_with_entity_id( ], ) async def test_position_via_position_topic_template_return_json( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test position by updating status via position template and returning json.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, "get-position-topic", "55") @@ -3193,10 +3191,10 @@ async def test_position_via_position_topic_template_return_json( async def test_position_via_position_topic_template_return_json_warning( hass: HomeAssistant, caplog: pytest.LogCaptureFixture, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test position by updating status via position template returning json without position attribute.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, "get-position-topic", "55") @@ -3225,10 +3223,10 @@ async def test_position_via_position_topic_template_return_json_warning( ], ) async def test_position_and_tilt_via_position_topic_template_return_json( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test position and tilt by updating the position via position template.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, "get-position-topic", "0") @@ -3279,10 +3277,10 @@ async def test_position_and_tilt_via_position_topic_template_return_json( ], ) async def test_position_via_position_topic_template_all_variables( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test position by updating status via position template.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, "get-position-topic", "0") @@ -3320,10 +3318,10 @@ async def test_position_via_position_topic_template_all_variables( ], ) async def test_set_state_via_stopped_state_no_position_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the controlling state via stopped state when no position topic.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, "state-topic", "OPEN") @@ -3371,10 +3369,10 @@ async def test_set_state_via_stopped_state_no_position_topic( async def test_position_via_position_topic_template_return_invalid_json( hass: HomeAssistant, caplog: pytest.LogCaptureFixture, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test position by updating status via position template and returning invalid json.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, "get-position-topic", "55") @@ -3399,11 +3397,11 @@ async def test_position_via_position_topic_template_return_invalid_json( async def test_set_position_topic_without_get_position_topic_error( hass: HomeAssistant, caplog: pytest.LogCaptureFixture, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test error when set_position_topic is used without position_topic.""" with pytest.raises(AssertionError): - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() assert ( f"'{CONF_SET_POSITION_TOPIC}' must be set together with '{CONF_GET_POSITION_TOPIC}'." ) in caplog.text @@ -3426,11 +3424,11 @@ async def test_set_position_topic_without_get_position_topic_error( async def test_value_template_without_state_topic_error( hass: HomeAssistant, caplog: pytest.LogCaptureFixture, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test error when value_template is used and state_topic is missing.""" with pytest.raises(AssertionError): - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() assert ( f"'{CONF_VALUE_TEMPLATE}' must be set together with '{CONF_STATE_TOPIC}'." ) in caplog.text @@ -3453,11 +3451,11 @@ async def test_value_template_without_state_topic_error( async def test_position_template_without_position_topic_error( hass: HomeAssistant, caplog: pytest.LogCaptureFixture, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test error when position_template is used and position_topic is missing.""" with pytest.raises(AssertionError): - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() assert ( f"'{CONF_GET_POSITION_TEMPLATE}' must be set together with '{CONF_GET_POSITION_TOPIC}'." in caplog.text @@ -3481,11 +3479,11 @@ async def test_position_template_without_position_topic_error( async def test_set_position_template_without_set_position_topic( hass: HomeAssistant, caplog: pytest.LogCaptureFixture, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test error when set_position_template is used and set_position_topic is missing.""" with pytest.raises(AssertionError): - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() assert ( f"'{CONF_SET_POSITION_TEMPLATE}' must be set together with '{CONF_SET_POSITION_TOPIC}'." in caplog.text @@ -3509,11 +3507,11 @@ async def test_set_position_template_without_set_position_topic( async def test_tilt_command_template_without_tilt_command_topic( hass: HomeAssistant, caplog: pytest.LogCaptureFixture, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test error when tilt_command_template is used and tilt_command_topic is missing.""" with pytest.raises(AssertionError): - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() assert ( f"'{CONF_TILT_COMMAND_TEMPLATE}' must be set together with '{CONF_TILT_COMMAND_TOPIC}'." in caplog.text @@ -3537,11 +3535,11 @@ async def test_tilt_command_template_without_tilt_command_topic( async def test_tilt_status_template_without_tilt_status_topic_topic( hass: HomeAssistant, caplog: pytest.LogCaptureFixture, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test error when tilt_status_template is used and tilt_status_topic is missing.""" with pytest.raises(AssertionError): - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() assert ( f"'{CONF_TILT_STATUS_TEMPLATE}' must be set together with '{CONF_TILT_STATUS_TOPIC}'." in caplog.text @@ -3576,7 +3574,7 @@ async def test_tilt_status_template_without_tilt_status_topic_topic( ) async def test_publishing_with_custom_encoding( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, service: str, topic: str, @@ -3591,7 +3589,7 @@ async def test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, domain, config, @@ -3624,7 +3622,7 @@ async def test_reloadable( ) async def test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, topic: str, value: str, attribute: str | None, @@ -3633,7 +3631,7 @@ async def test_encoding_subscribable_topics( """Test handling of incoming encoded payload.""" await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, cover.DOMAIN, DEFAULT_CONFIG[mqtt.DOMAIN][cover.DOMAIN], topic, @@ -3646,21 +3644,21 @@ async def test_encoding_subscribable_topics( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_setup_manual_entity_from_yaml( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setup manual configured MQTT entity.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() platform = cover.DOMAIN assert hass.states.get(f"{platform}.test") async def test_unload_entry( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test unloading the config entry.""" domain = cover.DOMAIN config = DEFAULT_CONFIG await help_test_unload_config_entry_with_platform( - hass, mqtt_mock_entry_no_yaml_config, domain, config + hass, mqtt_mock_entry, domain, config ) diff --git a/tests/components/mqtt/test_device_tracker.py b/tests/components/mqtt/test_device_tracker.py index a0ac73953b4..182a5a0673d 100644 --- a/tests/components/mqtt/test_device_tracker.py +++ b/tests/components/mqtt/test_device_tracker.py @@ -41,11 +41,11 @@ def device_tracker_platform_only(): async def test_discover_device_tracker( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test discovering an MQTT device tracker component.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message( hass, "homeassistant/device_tracker/bla/config", @@ -63,11 +63,11 @@ async def test_discover_device_tracker( @pytest.mark.no_fail_on_log_exception async def test_discovery_broken( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test handling of bad discovery message.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message( hass, "homeassistant/device_tracker/bla/config", @@ -92,11 +92,11 @@ async def test_discovery_broken( async def test_non_duplicate_device_tracker_discovery( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test for a non duplicate component.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message( hass, "homeassistant/device_tracker/bla/config", @@ -120,11 +120,11 @@ async def test_non_duplicate_device_tracker_discovery( async def test_device_tracker_removal( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test removal of component through empty discovery message.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message( hass, "homeassistant/device_tracker/bla/config", @@ -142,11 +142,11 @@ async def test_device_tracker_removal( async def test_device_tracker_rediscover( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test rediscover of removed component.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message( hass, "homeassistant/device_tracker/bla/config", @@ -173,11 +173,11 @@ async def test_device_tracker_rediscover( async def test_duplicate_device_tracker_removal( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test for a non duplicate component.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message( hass, "homeassistant/device_tracker/bla/config", @@ -198,11 +198,11 @@ async def test_duplicate_device_tracker_removal( async def test_device_tracker_discovery_update( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test for a discovery update event.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message( hass, "homeassistant/device_tracker/bla/config", @@ -231,12 +231,12 @@ async def test_cleanup_device_tracker( hass_ws_client: WebSocketGenerator, device_registry: dr.DeviceRegistry, entity_registry: er.EntityRegistry, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test discovered device is cleaned up when removed from registry.""" assert await async_setup_component(hass, "config", {}) await hass.async_block_till_done() - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() ws_client = await hass_ws_client(hass) async_fire_mqtt_message( @@ -291,11 +291,11 @@ async def test_cleanup_device_tracker( async def test_setting_device_tracker_value_via_mqtt_message( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test the setting of the value via MQTT.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message( hass, "homeassistant/device_tracker/bla/config", @@ -319,11 +319,11 @@ async def test_setting_device_tracker_value_via_mqtt_message( async def test_setting_device_tracker_value_via_mqtt_message_and_template( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test the setting of the value via MQTT.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message( hass, "homeassistant/device_tracker/bla/config", @@ -346,11 +346,11 @@ async def test_setting_device_tracker_value_via_mqtt_message_and_template( async def test_setting_device_tracker_value_via_mqtt_message_and_template2( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test the setting of the value via MQTT.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message( hass, "homeassistant/device_tracker/bla/config", @@ -376,11 +376,11 @@ async def test_setting_device_tracker_value_via_mqtt_message_and_template2( async def test_setting_device_tracker_location_via_mqtt_message( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test the setting of the location via MQTT.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message( hass, "homeassistant/device_tracker/bla/config", @@ -400,11 +400,11 @@ async def test_setting_device_tracker_location_via_mqtt_message( async def test_setting_device_tracker_location_via_lat_lon_message( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test the setting of the latitude and longitude via MQTT.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message( hass, "homeassistant/device_tracker/bla/config", @@ -461,11 +461,11 @@ async def test_setting_device_tracker_location_via_lat_lon_message( async def test_setting_device_tracker_location_via_reset_message( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test the automatic inference of zones via MQTT via reset.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message( hass, "homeassistant/device_tracker/bla/config", @@ -537,11 +537,11 @@ async def test_setting_device_tracker_location_via_reset_message( async def test_setting_device_tracker_location_via_abbr_reset_message( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test the setting of reset via abbreviated names and custom payloads via MQTT.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message( hass, "homeassistant/device_tracker/bla/config", @@ -580,12 +580,12 @@ async def test_setting_device_tracker_location_via_abbr_reset_message( async def test_setting_blocked_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_blocked_attribute_via_mqtt_json_message( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, device_tracker.DOMAIN, DEFAULT_CONFIG, None, @@ -603,10 +603,10 @@ async def test_setting_blocked_attribute_via_mqtt_json_message( ], ) async def test_setup_with_modern_schema( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setup using the modern schema.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() dev_id = "jan" entity_id = f"{device_tracker.DOMAIN}.{dev_id}" assert hass.states.get(entity_id) is not None diff --git a/tests/components/mqtt/test_device_trigger.py b/tests/components/mqtt/test_device_trigger.py index feb81592393..bcfd55488bc 100644 --- a/tests/components/mqtt/test_device_trigger.py +++ b/tests/components/mqtt/test_device_trigger.py @@ -45,10 +45,10 @@ def binary_sensor_and_sensor_only(): async def test_get_triggers( hass: HomeAssistant, device_registry: dr.DeviceRegistry, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test we get the expected triggers from a discovered mqtt device.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() data1 = ( '{ "automation_type":"trigger",' ' "device":{"identifiers":["0AFFD2"]},' @@ -81,10 +81,10 @@ async def test_get_triggers( async def test_get_unknown_triggers( hass: HomeAssistant, device_registry: dr.DeviceRegistry, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test we don't get unknown triggers.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() # Discover a sensor (without device triggers) data1 = ( '{ "device":{"identifiers":["0AFFD2"]},' @@ -128,10 +128,10 @@ async def test_get_unknown_triggers( async def test_get_non_existing_triggers( hass: HomeAssistant, device_registry: dr.DeviceRegistry, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test getting non existing triggers.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() # Discover a sensor (without device triggers) data1 = ( '{ "device":{"identifiers":["0AFFD2"]},' @@ -152,10 +152,10 @@ async def test_get_non_existing_triggers( async def test_discover_bad_triggers( hass: HomeAssistant, device_registry: dr.DeviceRegistry, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test bad discovery message.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() # Test sending bad data data0 = ( '{ "automation_type":"trigger",' @@ -202,10 +202,10 @@ async def test_discover_bad_triggers( async def test_update_remove_triggers( hass: HomeAssistant, device_registry: dr.DeviceRegistry, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test triggers can be updated and removed.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() config1 = { "automation_type": "trigger", "device": {"identifiers": ["0AFFD2"]}, @@ -272,10 +272,10 @@ async def test_if_fires_on_mqtt_message( hass: HomeAssistant, device_registry: dr.DeviceRegistry, calls, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test triggers firing.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() data1 = ( '{ "automation_type":"trigger",' ' "device":{"identifiers":["0AFFD2"]},' @@ -351,10 +351,10 @@ async def test_if_fires_on_mqtt_message_template( hass: HomeAssistant, device_registry: dr.DeviceRegistry, calls, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test triggers firing.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() data1 = ( '{ "automation_type":"trigger",' ' "device":{"identifiers":["0AFFD2"]},' @@ -432,10 +432,10 @@ async def test_if_fires_on_mqtt_message_late_discover( hass: HomeAssistant, device_registry: dr.DeviceRegistry, calls, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test triggers firing of MQTT device triggers discovered after setup.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() data0 = ( '{ "device":{"identifiers":["0AFFD2"]},' ' "state_topic": "foobar/sensor",' @@ -519,10 +519,10 @@ async def test_if_fires_on_mqtt_message_after_update( hass: HomeAssistant, device_registry: dr.DeviceRegistry, calls, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test triggers firing after update.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() data1 = ( '{ "automation_type":"trigger",' ' "device":{"identifiers":["0AFFD2"]},' @@ -598,10 +598,10 @@ async def test_if_fires_on_mqtt_message_after_update( async def test_no_resubscribe_same_topic( hass: HomeAssistant, device_registry: dr.DeviceRegistry, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test subscription to topics without change.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() data1 = ( '{ "automation_type":"trigger",' ' "device":{"identifiers":["0AFFD2"]},' @@ -646,10 +646,10 @@ async def test_not_fires_on_mqtt_message_after_remove_by_mqtt( hass: HomeAssistant, device_registry: dr.DeviceRegistry, calls, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test triggers not firing after removal.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() data1 = ( '{ "automation_type":"trigger",' ' "device":{"identifiers":["0AFFD2"]},' @@ -712,13 +712,13 @@ async def test_not_fires_on_mqtt_message_after_remove_from_registry( hass_ws_client: WebSocketGenerator, device_registry: dr.DeviceRegistry, calls, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test triggers not firing after removal.""" assert await async_setup_component(hass, "config", {}) assert await async_setup_component(hass, "repairs", {}) await hass.async_block_till_done() - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() ws_client = await hass_ws_client(hass) @@ -783,10 +783,10 @@ async def test_not_fires_on_mqtt_message_after_remove_from_registry( async def test_attach_remove( hass: HomeAssistant, device_registry: dr.DeviceRegistry, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test attach and removal of trigger.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() data1 = ( '{ "automation_type":"trigger",' ' "device":{"identifiers":["0AFFD2"]},' @@ -841,10 +841,10 @@ async def test_attach_remove( async def test_attach_remove_late( hass: HomeAssistant, device_registry: dr.DeviceRegistry, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test attach and removal of trigger .""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() data0 = ( '{ "device":{"identifiers":["0AFFD2"]},' ' "state_topic": "foobar/sensor",' @@ -907,10 +907,10 @@ async def test_attach_remove_late( async def test_attach_remove_late2( hass: HomeAssistant, device_registry: dr.DeviceRegistry, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test attach and removal of trigger .""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() data0 = ( '{ "device":{"identifiers":["0AFFD2"]},' ' "state_topic": "foobar/sensor",' @@ -969,10 +969,10 @@ async def test_attach_remove_late2( async def test_entity_device_info_with_connection( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT device registry integration.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() registry = dr.async_get(hass) data = json.dumps( @@ -1007,10 +1007,10 @@ async def test_entity_device_info_with_connection( async def test_entity_device_info_with_identifier( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT device registry integration.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() registry = dr.async_get(hass) data = json.dumps( @@ -1043,10 +1043,10 @@ async def test_entity_device_info_with_identifier( async def test_entity_device_info_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry update.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() registry = dr.async_get(hass) config = { @@ -1086,10 +1086,10 @@ async def test_cleanup_trigger( hass: HomeAssistant, hass_ws_client: WebSocketGenerator, device_registry: dr.DeviceRegistry, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test trigger discovery topic is cleaned when device is removed from registry.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() assert await async_setup_component(hass, "config", {}) ws_client = await hass_ws_client(hass) @@ -1142,10 +1142,10 @@ async def test_cleanup_trigger( async def test_cleanup_device( hass: HomeAssistant, device_registry: dr.DeviceRegistry, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test removal from device registry when trigger is removed.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() config = { "automation_type": "trigger", "topic": "test-topic", @@ -1178,10 +1178,10 @@ async def test_cleanup_device( async def test_cleanup_device_several_triggers( hass: HomeAssistant, device_registry: dr.DeviceRegistry, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test removal from device registry when the last trigger is removed.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() config1 = { "automation_type": "trigger", "topic": "test-topic", @@ -1240,13 +1240,13 @@ async def test_cleanup_device_several_triggers( async def test_cleanup_device_with_entity1( hass: HomeAssistant, device_registry: dr.DeviceRegistry, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test removal from device registry for device with entity. Trigger removed first, then entity. """ - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() config1 = { "automation_type": "trigger", "topic": "test-topic", @@ -1301,13 +1301,13 @@ async def test_cleanup_device_with_entity1( async def test_cleanup_device_with_entity2( hass: HomeAssistant, device_registry: dr.DeviceRegistry, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test removal from device registry for device with entity. Entity removed first, then trigger. """ - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() config1 = { "automation_type": "trigger", "topic": "test-topic", @@ -1360,13 +1360,13 @@ async def test_cleanup_device_with_entity2( async def test_trigger_debug_info( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test debug_info. This is a test helper for MQTT debug_info. """ - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() registry = dr.async_get(hass) config1 = { diff --git a/tests/components/mqtt/test_diagnostics.py b/tests/components/mqtt/test_diagnostics.py index 3eec6887b1a..81a86f1c61f 100644 --- a/tests/components/mqtt/test_diagnostics.py +++ b/tests/components/mqtt/test_diagnostics.py @@ -36,10 +36,10 @@ async def test_entry_diagnostics( hass: HomeAssistant, device_registry: dr.DeviceRegistry, hass_client: ClientSessionGenerator, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test config entry diagnostics.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0] mqtt_mock.connected = True @@ -160,10 +160,10 @@ async def test_redact_diagnostics( hass: HomeAssistant, device_registry: dr.DeviceRegistry, hass_client: ClientSessionGenerator, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test redacting diagnostics.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() expected_config = dict(default_config) expected_config["password"] = "**REDACTED**" expected_config["username"] = "**REDACTED**" diff --git a/tests/components/mqtt/test_discovery.py b/tests/components/mqtt/test_discovery.py index d05c7109845..22cf9ecceed 100644 --- a/tests/components/mqtt/test_discovery.py +++ b/tests/components/mqtt/test_discovery.py @@ -49,10 +49,10 @@ from tests.typing import ( ) async def test_subscribing_config_topic( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test setting up discovery.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0] discovery_topic = "homeassistant" @@ -77,13 +77,13 @@ async def test_subscribing_config_topic( ) async def test_invalid_topic( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, topic: str, log: bool, ) -> None: """Test sending to invalid topic.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() with patch( "homeassistant.components.mqtt.discovery.async_dispatcher_send" ) as mock_dispatcher_send: @@ -104,11 +104,11 @@ async def test_invalid_topic( @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR]) async def test_invalid_json( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test sending in invalid JSON.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() with patch( "homeassistant.components.mqtt.discovery.async_dispatcher_send" ) as mock_dispatcher_send: @@ -124,11 +124,11 @@ async def test_invalid_json( async def test_only_valid_components( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test for a valid component.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() with patch( "homeassistant.components.mqtt.discovery.async_dispatcher_send" ) as mock_dispatcher_send: @@ -150,10 +150,10 @@ async def test_only_valid_components( @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR]) async def test_correct_config_discovery( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test sending in correct JSON.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message( hass, "homeassistant/binary_sensor/bla/config", @@ -171,10 +171,10 @@ async def test_correct_config_discovery( @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.FAN]) async def test_discover_fan( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test discovering an MQTT fan.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message( hass, "homeassistant/fan/bla/config", @@ -192,11 +192,11 @@ async def test_discover_fan( @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.CLIMATE]) async def test_discover_climate( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test discovering an MQTT climate component.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() data = ( '{ "name": "ClimateTest",' ' "current_temperature_topic": "climate/bla/current_temp",' @@ -216,10 +216,10 @@ async def test_discover_climate( @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.ALARM_CONTROL_PANEL]) async def test_discover_alarm_control_panel( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test discovering an MQTT alarm control panel component.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() data = ( '{ "name": "AlarmControlPanelTest",' ' "state_topic": "test_topic",' @@ -385,7 +385,7 @@ async def test_discover_alarm_control_panel( ) async def test_discovery_with_object_id( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, topic: str, config: str, entity_id: str, @@ -393,7 +393,7 @@ async def test_discovery_with_object_id( domain: str, ) -> None: """Test discovering an MQTT entity with object_id.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, topic, config) await hass.async_block_till_done() @@ -407,10 +407,10 @@ async def test_discovery_with_object_id( @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR]) async def test_discovery_incl_nodeid( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test sending in correct JSON with optional node_id included.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message( hass, "homeassistant/binary_sensor/my_node_id/bla/config", @@ -430,11 +430,11 @@ async def test_discovery_incl_nodeid( @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR]) async def test_non_duplicate_discovery( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test for a non duplicate component.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message( hass, "homeassistant/binary_sensor/bla/config", @@ -459,10 +459,10 @@ async def test_non_duplicate_discovery( @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR]) async def test_removal( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test removal of component through empty discovery message.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message( hass, "homeassistant/binary_sensor/bla/config", @@ -481,10 +481,10 @@ async def test_removal( @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR]) async def test_rediscover( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test rediscover of removed component.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message( hass, "homeassistant/binary_sensor/bla/config", @@ -512,10 +512,10 @@ async def test_rediscover( @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR]) async def test_rapid_rediscover( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test immediate rediscover of removed component.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() events = async_capture_events(hass, EVENT_STATE_CHANGED) async_fire_mqtt_message( @@ -565,10 +565,10 @@ async def test_rapid_rediscover( @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR]) async def test_rapid_rediscover_unique( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test immediate rediscover of removed component.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() events = [] @callback @@ -628,10 +628,10 @@ async def test_rapid_rediscover_unique( @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR]) async def test_rapid_reconfigure( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test immediate reconfigure of added component.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() events = [] @callback @@ -684,11 +684,11 @@ async def test_rapid_reconfigure( @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR]) async def test_duplicate_removal( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test for a non duplicate component.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message( hass, "homeassistant/binary_sensor/bla/config", @@ -710,10 +710,10 @@ async def test_cleanup_device( hass_ws_client: WebSocketGenerator, device_registry: dr.DeviceRegistry, entity_registry: er.EntityRegistry, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test discvered device is cleaned up when entry removed from device.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() assert await async_setup_component(hass, "config", {}) ws_client = await hass_ws_client(hass) @@ -772,10 +772,10 @@ async def test_cleanup_device_mqtt( hass: HomeAssistant, device_registry: dr.DeviceRegistry, entity_registry: er.EntityRegistry, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test discvered device is cleaned up when removed through MQTT.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() data = ( '{ "device":{"identifiers":["0AFFD2"]},' ' "state_topic": "foobar/sensor",' @@ -819,12 +819,12 @@ async def test_cleanup_device_multiple_config_entries( hass_ws_client: WebSocketGenerator, device_registry: dr.DeviceRegistry, entity_registry: er.EntityRegistry, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test discovered device is cleaned up when entry removed from device.""" assert await async_setup_component(hass, "config", {}) await hass.async_block_till_done() - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() ws_client = await hass_ws_client(hass) config_entry = MockConfigEntry(domain="test", data={}) @@ -924,10 +924,10 @@ async def test_cleanup_device_multiple_config_entries_mqtt( hass: HomeAssistant, device_registry: dr.DeviceRegistry, entity_registry: er.EntityRegistry, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test discovered device is cleaned up when removed through MQTT.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() config_entry = MockConfigEntry(domain="test", data={}) config_entry.add_to_hass(hass) device_entry = device_registry.async_get_or_create( @@ -1008,10 +1008,10 @@ async def test_cleanup_device_multiple_config_entries_mqtt( @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SWITCH]) async def test_discovery_expansion( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test expansion of abbreviated discovery payload.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() data = ( '{ "~": "some/base/topic",' ' "name": "DiscoveryExpansionTest1",' @@ -1071,10 +1071,10 @@ async def test_discovery_expansion( @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SWITCH]) async def test_discovery_expansion_2( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test expansion of abbreviated discovery payload.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() data = ( '{ "~": "some/base/topic",' ' "name": "DiscoveryExpansionTest1",' @@ -1117,11 +1117,11 @@ async def test_discovery_expansion_2( @pytest.mark.no_fail_on_log_exception async def test_discovery_expansion_3( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test expansion of broken discovery payload.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() data = ( '{ "~": "some/base/topic",' ' "name": "DiscoveryExpansionTest1",' @@ -1153,10 +1153,10 @@ async def test_discovery_expansion_3( async def test_discovery_expansion_without_encoding_and_value_template_1( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test expansion of raw availability payload with a template as list.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() data = ( '{ "~": "some/base/topic",' ' "name": "DiscoveryExpansionTest1",' @@ -1205,10 +1205,10 @@ async def test_discovery_expansion_without_encoding_and_value_template_1( @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SWITCH]) async def test_discovery_expansion_without_encoding_and_value_template_2( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test expansion of raw availability payload with a template directly.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() data = ( '{ "~": "some/base/topic",' ' "name": "DiscoveryExpansionTest1",' @@ -1290,10 +1290,10 @@ ABBREVIATIONS_WHITE_LIST = [ async def test_missing_discover_abbreviations( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Check MQTT platforms for missing abbreviations.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() missing = [] regex = re.compile(r"(CONF_[a-zA-Z\d_]*) *= *[\'\"]([a-zA-Z\d_]*)[\'\"]") for fil in Path(mqtt.__file__).parent.rglob("*.py"): @@ -1319,10 +1319,10 @@ async def test_missing_discover_abbreviations( @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SWITCH]) async def test_no_implicit_state_topic_switch( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test no implicit state topic for switch.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() data = '{ "name": "Test1", "command_topic": "cmnd" }' async_fire_mqtt_message(hass, "homeassistant/switch/bla/config", data) @@ -1352,10 +1352,10 @@ async def test_no_implicit_state_topic_switch( ], ) async def test_complex_discovery_topic_prefix( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Tests handling of discovery topic prefix with multiple slashes.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message( hass, @@ -1379,10 +1379,10 @@ async def test_complex_discovery_topic_prefix( async def test_mqtt_integration_discovery_subscribe_unsubscribe( hass: HomeAssistant, mqtt_client_mock: MqttMockPahoClient, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Check MQTT integration discovery subscribe and unsubscribe.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() mock_entity_platform(hass, "config_flow.comp", None) entry = hass.config_entries.async_entries("mqtt")[0] @@ -1426,10 +1426,10 @@ async def test_mqtt_integration_discovery_subscribe_unsubscribe( async def test_mqtt_discovery_unsubscribe_once( hass: HomeAssistant, mqtt_client_mock: MqttMockPahoClient, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Check MQTT integration discovery unsubscribe once.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() mock_entity_platform(hass, "config_flow.comp", None) entry = hass.config_entries.async_entries("mqtt")[0] @@ -1464,12 +1464,12 @@ async def test_mqtt_discovery_unsubscribe_once( @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SENSOR]) async def test_clear_config_topic_disabled_entity( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, device_registry: dr.DeviceRegistry, caplog: pytest.LogCaptureFixture, ) -> None: """Test the discovery topic is removed when a disabled entity is removed.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() # discover an entity that is not enabled by default config = { "name": "sbfspot_12345", @@ -1540,12 +1540,12 @@ async def test_clear_config_topic_disabled_entity( @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SENSOR]) async def test_clean_up_registry_monitoring( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, device_registry: dr.DeviceRegistry, tmp_path: Path, ) -> None: """Test registry monitoring hook is removed after a reload.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() hooks: dict = hass.data["mqtt"].discovery_registry_hooks # discover an entity that is not enabled by default config1 = { @@ -1595,11 +1595,11 @@ async def test_clean_up_registry_monitoring( @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SENSOR]) async def test_unique_id_collission_has_priority( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, entity_registry: er.EntityRegistry, ) -> None: """Test the unique_id collision detection has priority over registry disabled items.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() config = { "name": "sbfspot_12345", "state_topic": "homeassistant_test/sensor/sbfspot_0/sbfspot_12345/", @@ -1643,10 +1643,10 @@ async def test_unique_id_collission_has_priority( @pytest.mark.xfail(raises=MultipleInvalid) @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SENSOR]) async def test_update_with_bad_config_not_breaks_discovery( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test a bad update does not break discovery.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() # discover a sensor config1 = { "name": "sbfspot_12345", diff --git a/tests/components/mqtt/test_fan.py b/tests/components/mqtt/test_fan.py index 3e3f6219b0d..264165a2448 100644 --- a/tests/components/mqtt/test_fan.py +++ b/tests/components/mqtt/test_fan.py @@ -89,11 +89,11 @@ def fan_platform_only(): async def test_fail_setup_if_no_command_topic( hass: HomeAssistant, caplog: pytest.LogCaptureFixture, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test if command fails with command topic.""" with pytest.raises(AssertionError): - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() assert ( "Invalid config for [mqtt]: required key not provided @ data['mqtt']['fan'][0]['command_topic']" in caplog.text @@ -138,11 +138,11 @@ async def test_fail_setup_if_no_command_topic( ) async def test_controlling_state_via_topic( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test the controlling state via topic.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("fan.test") assert state.state == STATE_UNKNOWN @@ -262,11 +262,11 @@ async def test_controlling_state_via_topic( ) async def test_controlling_state_via_topic_with_different_speed_range( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test the controlling state via topic using an alternate speed range.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, "percentage-state-topic1", "100") state = hass.states.get("fan.test1") @@ -314,11 +314,11 @@ async def test_controlling_state_via_topic_with_different_speed_range( ) async def test_controlling_state_via_topic_no_percentage_topics( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test the controlling state via topic without percentage topics.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("fan.test") assert state.state == STATE_UNKNOWN @@ -384,11 +384,11 @@ async def test_controlling_state_via_topic_no_percentage_topics( ) async def test_controlling_state_via_topic_and_json_message( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test the controlling state via topic and JSON message (percentage mode).""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("fan.test") assert state.state == STATE_UNKNOWN @@ -491,11 +491,11 @@ async def test_controlling_state_via_topic_and_json_message( ) async def test_controlling_state_via_topic_and_json_message_shared_topic( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test the controlling state via topic and JSON message using a shared topic.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("fan.test") assert state.state == STATE_UNKNOWN @@ -572,10 +572,10 @@ async def test_controlling_state_via_topic_and_json_message_shared_topic( ) async def test_sending_mqtt_commands_and_optimistic( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test optimistic mode without state topic.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("fan.test") assert state.state == STATE_UNKNOWN @@ -711,10 +711,10 @@ async def test_sending_mqtt_commands_and_optimistic( ], ) async def test_sending_mqtt_commands_with_alternate_speed_range( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the controlling state via topic using an alternate speed range.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() await common.async_set_percentage(hass, "fan.test1", 0) mqtt_mock.async_publish.assert_called_once_with( @@ -803,11 +803,11 @@ async def test_sending_mqtt_commands_with_alternate_speed_range( ) async def test_sending_mqtt_commands_and_optimistic_no_legacy( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test optimistic mode without state topic without legacy speed command topic.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("fan.test") assert state.state == STATE_UNKNOWN @@ -942,10 +942,10 @@ async def test_sending_mqtt_commands_and_optimistic_no_legacy( ) async def test_sending_mqtt_command_templates_( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test optimistic mode without state topic without legacy speed command topic.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("fan.test") assert state.state == STATE_UNKNOWN @@ -1082,10 +1082,10 @@ async def test_sending_mqtt_command_templates_( ) async def test_sending_mqtt_commands_and_optimistic_no_percentage_topic( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test optimistic mode without state topic without percentage command topic.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("fan.test") assert state.state == STATE_UNKNOWN @@ -1150,10 +1150,10 @@ async def test_sending_mqtt_commands_and_optimistic_no_percentage_topic( ) async def test_sending_mqtt_commands_and_explicit_optimistic( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test optimistic mode with state topic and turn on attributes.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("fan.test") assert state.state == STATE_UNKNOWN @@ -1372,7 +1372,7 @@ async def test_sending_mqtt_commands_and_explicit_optimistic( ) async def test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, topic: str, value: str, attribute: str | None, @@ -1386,7 +1386,7 @@ async def test_encoding_subscribable_topics( config[CONF_OSCILLATION_COMMAND_TOPIC] = "fan/some_oscillation_command_topic" await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, fan.DOMAIN, config, topic, @@ -1418,11 +1418,11 @@ async def test_encoding_subscribable_topics( ) async def test_attributes( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("fan.test") assert state.state == STATE_UNKNOWN @@ -1698,49 +1698,47 @@ async def test_attributes( ) async def test_supported_features( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, name: str, success: bool, features, ) -> None: """Test optimistic mode without state topic.""" if success: - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get(f"fan.{name}") assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == features return with pytest.raises(AssertionError): - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_when_connection_lost( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability after MQTT disconnection.""" - await help_test_availability_when_connection_lost( - hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN - ) + await help_test_availability_when_connection_lost(hass, mqtt_mock_entry, fan.DOMAIN) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_without_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability without defined availability topic.""" await help_test_availability_without_topic( - hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, fan.DOMAIN, DEFAULT_CONFIG ) async def test_default_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by default payload with defined topic.""" await help_test_default_availability_payload( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, fan.DOMAIN, DEFAULT_CONFIG, True, @@ -1750,12 +1748,12 @@ async def test_default_availability_payload( async def test_custom_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by custom payload with defined topic.""" await help_test_custom_availability_payload( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, fan.DOMAIN, DEFAULT_CONFIG, True, @@ -1765,21 +1763,21 @@ async def test_custom_availability_payload( async def test_setting_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_via_mqtt_json_message( - hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, fan.DOMAIN, DEFAULT_CONFIG ) async def test_setting_blocked_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_blocked_attribute_via_mqtt_json_message( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, fan.DOMAIN, DEFAULT_CONFIG, MQTT_FAN_ATTRIBUTES_BLOCKED, @@ -1787,23 +1785,23 @@ async def test_setting_blocked_attribute_via_mqtt_json_message( async def test_setting_attribute_with_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_with_template( - hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, fan.DOMAIN, DEFAULT_CONFIG ) async def test_update_with_json_attrs_not_dict( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_not_dict( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, fan.DOMAIN, DEFAULT_CONFIG, @@ -1812,13 +1810,13 @@ async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_bad_json( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_bad_json( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, fan.DOMAIN, DEFAULT_CONFIG, @@ -1827,12 +1825,12 @@ async def test_update_with_json_attrs_bad_json( async def test_discovery_update_attr( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered MQTTAttributes.""" await help_test_discovery_update_attr( - hass, mqtt_mock_entry_no_yaml_config, caplog, fan.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, caplog, fan.DOMAIN, DEFAULT_CONFIG ) @@ -1860,40 +1858,38 @@ async def test_discovery_update_attr( ], ) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test unique_id option only creates one fan per id.""" - await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN) + await help_test_unique_id(hass, mqtt_mock_entry, fan.DOMAIN) async def test_discovery_removal_fan( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test removal of discovered fan.""" data = '{ "name": "test", "command_topic": "test_topic" }' - await help_test_discovery_removal( - hass, mqtt_mock_entry_no_yaml_config, caplog, fan.DOMAIN, data - ) + await help_test_discovery_removal(hass, mqtt_mock_entry, caplog, fan.DOMAIN, data) async def test_discovery_update_fan( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered fan.""" config1 = {"name": "Beer", "command_topic": "test_topic"} config2 = {"name": "Milk", "command_topic": "test_topic"} await help_test_discovery_update( - hass, mqtt_mock_entry_no_yaml_config, caplog, fan.DOMAIN, config1, config2 + hass, mqtt_mock_entry, caplog, fan.DOMAIN, config1, config2 ) async def test_discovery_update_unchanged_fan( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered fan.""" @@ -1903,7 +1899,7 @@ async def test_discovery_update_unchanged_fan( ) as discovery_update: await help_test_discovery_update_unchanged( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, fan.DOMAIN, data1, @@ -1914,7 +1910,7 @@ async def test_discovery_update_unchanged_fan( @pytest.mark.no_fail_on_log_exception async def test_discovery_broken( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test handling of bad discovery message.""" @@ -1922,71 +1918,71 @@ async def test_discovery_broken( data2 = '{ "name": "Milk", "command_topic": "test_topic" }' await help_test_discovery_broken( - hass, mqtt_mock_entry_no_yaml_config, caplog, fan.DOMAIN, data1, data2 + hass, mqtt_mock_entry, caplog, fan.DOMAIN, data1, data2 ) async def test_entity_device_info_with_connection( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT fan device registry integration.""" await help_test_entity_device_info_with_connection( - hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, fan.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_with_identifier( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT fan device registry integration.""" await help_test_entity_device_info_with_identifier( - hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, fan.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry update.""" await help_test_entity_device_info_update( - hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, fan.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_remove( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry remove.""" await help_test_entity_device_info_remove( - hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, fan.DOMAIN, DEFAULT_CONFIG ) async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" await help_test_entity_id_update_subscriptions( - hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, fan.DOMAIN, DEFAULT_CONFIG ) async def test_entity_id_update_discovery_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT discovery update when entity_id is updated.""" await help_test_entity_id_update_discovery_update( - hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, fan.DOMAIN, DEFAULT_CONFIG ) async def test_entity_debug_info_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT debug info.""" await help_test_entity_debug_info_message( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, fan.DOMAIN, DEFAULT_CONFIG, fan.SERVICE_TURN_ON, @@ -2035,7 +2031,7 @@ async def test_entity_debug_info_message( ) async def test_publishing_with_custom_encoding( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, service: str, topic: str, @@ -2051,7 +2047,7 @@ async def test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, domain, config, @@ -2075,21 +2071,21 @@ async def test_reloadable( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_setup_manual_entity_from_yaml( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setup manual configured MQTT entity.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() platform = fan.DOMAIN assert hass.states.get(f"{platform}.test") async def test_unload_entry( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test unloading the config entry.""" domain = fan.DOMAIN config = DEFAULT_CONFIG await help_test_unload_config_entry_with_platform( - hass, mqtt_mock_entry_no_yaml_config, domain, config + hass, mqtt_mock_entry, domain, config ) diff --git a/tests/components/mqtt/test_humidifier.py b/tests/components/mqtt/test_humidifier.py index 0517e8e6a9c..8cf0c5f47d8 100644 --- a/tests/components/mqtt/test_humidifier.py +++ b/tests/components/mqtt/test_humidifier.py @@ -133,12 +133,12 @@ async def async_set_humidity( ) async def test_fail_setup_if_no_command_topic( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test if command fails with command topic.""" with pytest.raises(AssertionError): - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() assert ( "Invalid config for [mqtt]: required key not provided @ data['mqtt']['humidifier'][0]['command_topic']. Got None" in caplog.text @@ -177,11 +177,11 @@ async def test_fail_setup_if_no_command_topic( ) async def test_controlling_state_via_topic( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test the controlling state via topic.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("humidifier.test") assert state.state == STATE_UNKNOWN @@ -280,12 +280,12 @@ async def test_controlling_state_via_topic( ) async def test_controlling_state_via_topic_and_json_message( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test the controlling state via topic and JSON message.""" await hass.async_block_till_done() - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("humidifier.test") assert state.state == STATE_UNKNOWN @@ -372,11 +372,11 @@ async def test_controlling_state_via_topic_and_json_message( ) async def test_controlling_state_via_topic_and_json_message_shared_topic( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test the controlling state via topic and JSON message using a shared topic.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("humidifier.test") assert state.state == STATE_UNKNOWN @@ -447,11 +447,11 @@ async def test_controlling_state_via_topic_and_json_message_shared_topic( ) async def test_sending_mqtt_commands_and_optimistic( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test optimistic mode without state topic.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("humidifier.test") assert state.state == STATE_UNKNOWN @@ -547,11 +547,11 @@ async def test_sending_mqtt_commands_and_optimistic( ) async def test_sending_mqtt_command_templates_( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Testing command templates with optimistic mode without state topic.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("humidifier.test") assert state.state == STATE_UNKNOWN @@ -648,11 +648,11 @@ async def test_sending_mqtt_command_templates_( ) async def test_sending_mqtt_commands_and_explicit_optimistic( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test optimistic mode with state topic and turn on attributes.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("humidifier.test") assert state.state == STATE_UNKNOWN @@ -753,7 +753,7 @@ async def test_sending_mqtt_commands_and_explicit_optimistic( ) async def test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, topic: str, value: str, attribute: str | None, @@ -765,7 +765,7 @@ async def test_encoding_subscribable_topics( config[CONF_MODE_COMMAND_TOPIC] = "humidifier/some_mode_command_topic" await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, humidifier.DOMAIN, config, topic, @@ -796,11 +796,11 @@ async def test_encoding_subscribable_topics( ) async def test_attributes( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("humidifier.test") assert state.state == STATE_UNKNOWN @@ -939,15 +939,15 @@ async def test_attributes( ) async def test_validity_configurations( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, valid: bool, ) -> None: """Test validity of configurations.""" if valid: - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() return with pytest.raises(AssertionError): - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() @pytest.mark.parametrize( @@ -1043,49 +1043,49 @@ async def test_validity_configurations( ) async def test_supported_features( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, name: str, success: bool, features: humidifier.HumidifierEntityFeature | None, ) -> None: """Test supported features.""" if success: - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get(f"humidifier.{name}") assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == features return with pytest.raises(AssertionError): - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_when_connection_lost( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability after MQTT disconnection.""" await help_test_availability_when_connection_lost( - hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN + hass, mqtt_mock_entry, humidifier.DOMAIN ) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_without_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability without defined availability topic.""" await help_test_availability_without_topic( - hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, humidifier.DOMAIN, DEFAULT_CONFIG ) async def test_default_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by default payload with defined topic.""" await help_test_default_availability_payload( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, humidifier.DOMAIN, DEFAULT_CONFIG, True, @@ -1095,12 +1095,12 @@ async def test_default_availability_payload( async def test_custom_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by custom payload with defined topic.""" await help_test_custom_availability_payload( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, humidifier.DOMAIN, DEFAULT_CONFIG, True, @@ -1110,21 +1110,21 @@ async def test_custom_availability_payload( async def test_setting_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_via_mqtt_json_message( - hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, humidifier.DOMAIN, DEFAULT_CONFIG ) async def test_setting_blocked_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_blocked_attribute_via_mqtt_json_message( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, humidifier.DOMAIN, DEFAULT_CONFIG, MQTT_HUMIDIFIER_ATTRIBUTES_BLOCKED, @@ -1132,23 +1132,23 @@ async def test_setting_blocked_attribute_via_mqtt_json_message( async def test_setting_attribute_with_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_with_template( - hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, humidifier.DOMAIN, DEFAULT_CONFIG ) async def test_update_with_json_attrs_not_dict( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_not_dict( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, humidifier.DOMAIN, DEFAULT_CONFIG, @@ -1157,13 +1157,13 @@ async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_bad_json( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_bad_json( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, humidifier.DOMAIN, DEFAULT_CONFIG, @@ -1172,13 +1172,13 @@ async def test_update_with_json_attrs_bad_json( async def test_discovery_update_attr( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered MQTTAttributes.""" await help_test_discovery_update_attr( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, humidifier.DOMAIN, DEFAULT_CONFIG, @@ -1211,27 +1211,27 @@ async def test_discovery_update_attr( ], ) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test unique_id option only creates one fan per id.""" - await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN) + await help_test_unique_id(hass, mqtt_mock_entry, humidifier.DOMAIN) async def test_discovery_removal_humidifier( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test removal of discovered humidifier.""" data = '{ "name": "test", "command_topic": "test_topic", "target_humidity_command_topic": "test-topic2" }' await help_test_discovery_removal( - hass, mqtt_mock_entry_no_yaml_config, caplog, humidifier.DOMAIN, data + hass, mqtt_mock_entry, caplog, humidifier.DOMAIN, data ) async def test_discovery_update_humidifier( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered humidifier.""" @@ -1247,7 +1247,7 @@ async def test_discovery_update_humidifier( } await help_test_discovery_update( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, humidifier.DOMAIN, config1, @@ -1257,7 +1257,7 @@ async def test_discovery_update_humidifier( async def test_discovery_update_unchanged_humidifier( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered humidifier.""" @@ -1267,7 +1267,7 @@ async def test_discovery_update_unchanged_humidifier( ) as discovery_update: await help_test_discovery_update_unchanged( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, humidifier.DOMAIN, data1, @@ -1278,78 +1278,78 @@ async def test_discovery_update_unchanged_humidifier( @pytest.mark.no_fail_on_log_exception async def test_discovery_broken( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test handling of bad discovery message.""" data1 = '{ "name": "Beer" }' data2 = '{ "name": "Milk", "command_topic": "test_topic", "target_humidity_command_topic": "test-topic2" }' await help_test_discovery_broken( - hass, mqtt_mock_entry_no_yaml_config, caplog, humidifier.DOMAIN, data1, data2 + hass, mqtt_mock_entry, caplog, humidifier.DOMAIN, data1, data2 ) async def test_entity_device_info_with_connection( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT fan device registry integration.""" await help_test_entity_device_info_with_connection( - hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, humidifier.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_with_identifier( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT fan device registry integration.""" await help_test_entity_device_info_with_identifier( - hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, humidifier.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry update.""" await help_test_entity_device_info_update( - hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, humidifier.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_remove( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry remove.""" await help_test_entity_device_info_remove( - hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, humidifier.DOMAIN, DEFAULT_CONFIG ) async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" await help_test_entity_id_update_subscriptions( - hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, humidifier.DOMAIN, DEFAULT_CONFIG ) async def test_entity_id_update_discovery_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT discovery update when entity_id is updated.""" await help_test_entity_id_update_discovery_update( - hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, humidifier.DOMAIN, DEFAULT_CONFIG ) async def test_entity_debug_info_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT debug info.""" await help_test_entity_debug_info_message( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, humidifier.DOMAIN, DEFAULT_CONFIG, humidifier.SERVICE_TURN_ON, @@ -1391,7 +1391,7 @@ async def test_entity_debug_info_message( ) async def test_publishing_with_custom_encoding( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, service: str, topic: str, @@ -1407,7 +1407,7 @@ async def test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, domain, config, @@ -1431,21 +1431,21 @@ async def test_reloadable( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_setup_manual_entity_from_yaml( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setup manual configured MQTT entity.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() platform = humidifier.DOMAIN assert hass.states.get(f"{platform}.test") async def test_unload_config_entry( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test unloading the config entry.""" domain = humidifier.DOMAIN config = DEFAULT_CONFIG await help_test_unload_config_entry_with_platform( - hass, mqtt_mock_entry_no_yaml_config, domain, config + hass, mqtt_mock_entry, domain, config ) diff --git a/tests/components/mqtt/test_init.py b/tests/components/mqtt/test_init.py index 3cab3d63f68..adc3d9273c4 100644 --- a/tests/components/mqtt/test_init.py +++ b/tests/components/mqtt/test_init.py @@ -118,20 +118,20 @@ def record_calls(calls: list[ReceiveMessage]) -> MessageCallbackType: async def test_mqtt_connects_on_home_assistant_mqtt_setup( hass: HomeAssistant, mqtt_client_mock: MqttMockPahoClient, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test if client is connected after mqtt init on bootstrap.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() assert mqtt_client_mock.connect.call_count == 1 async def test_mqtt_disconnects_on_home_assistant_stop( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, mqtt_client_mock: MqttMockPahoClient, ) -> None: """Test if client stops on HA stop.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() hass.bus.fire(EVENT_HOMEASSISTANT_STOP) await hass.async_block_till_done() await hass.async_block_till_done() @@ -182,10 +182,10 @@ async def test_mqtt_await_ack_at_disconnect( async def test_publish( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the publish function.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() await mqtt.async_publish(hass, "test-topic", "test-payload") await hass.async_block_till_done() assert mqtt_mock.async_publish.called @@ -296,7 +296,7 @@ async def test_command_template_value(hass: HomeAssistant) -> None: ) async def test_command_template_variables( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, config: ConfigType, ) -> None: """Test the rendering of entity variables.""" @@ -305,7 +305,7 @@ async def test_command_template_variables( fake_state = ha.State("select.test_select", "milk") mock_restore_cache(hass, (fake_state,)) - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() await hass.async_block_till_done() async_fire_mqtt_message(hass, "homeassistant/select/bla/config", json.dumps(config)) await hass.async_block_till_done() @@ -398,10 +398,10 @@ async def test_value_template_value(hass: HomeAssistant) -> None: async def test_service_call_without_topic_does_not_publish( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the service call if topic is missing.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() with pytest.raises(vol.Invalid): await hass.services.async_call( mqtt.DOMAIN, @@ -413,13 +413,13 @@ async def test_service_call_without_topic_does_not_publish( async def test_service_call_with_topic_and_topic_template_does_not_publish( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the service call with topic/topic template. If both 'topic' and 'topic_template' are provided then fail. """ - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() topic = "test/topic" topic_template = "test/{{ 'topic' }}" with pytest.raises(vol.Invalid): @@ -437,10 +437,10 @@ async def test_service_call_with_topic_and_topic_template_does_not_publish( async def test_service_call_with_invalid_topic_template_does_not_publish( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the service call with a problematic topic template.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() await hass.services.async_call( mqtt.DOMAIN, mqtt.SERVICE_PUBLISH, @@ -454,13 +454,13 @@ async def test_service_call_with_invalid_topic_template_does_not_publish( async def test_service_call_with_template_topic_renders_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the service call with rendered topic template. If 'topic_template' is provided and 'topic' is not, then render it. """ - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() await hass.services.async_call( mqtt.DOMAIN, mqtt.SERVICE_PUBLISH, @@ -475,13 +475,13 @@ async def test_service_call_with_template_topic_renders_template( async def test_service_call_with_template_topic_renders_invalid_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the service call with rendered, invalid topic template. If a wildcard topic is rendered, then fail. """ - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() await hass.services.async_call( mqtt.DOMAIN, mqtt.SERVICE_PUBLISH, @@ -495,13 +495,13 @@ async def test_service_call_with_template_topic_renders_invalid_topic( async def test_service_call_with_invalid_rendered_template_topic_doesnt_render_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the service call with unrendered template. If both 'payload' and 'payload_template' are provided then fail. """ - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() payload = "not a template" payload_template = "a template" with pytest.raises(vol.Invalid): @@ -519,13 +519,13 @@ async def test_service_call_with_invalid_rendered_template_topic_doesnt_render_t async def test_service_call_with_template_payload_renders_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the service call with rendered template. If 'payload_template' is provided and 'payload' is not, then render it. """ - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() await hass.services.async_call( mqtt.DOMAIN, mqtt.SERVICE_PUBLISH, @@ -551,10 +551,10 @@ async def test_service_call_with_template_payload_renders_template( async def test_service_call_with_bad_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the service call with a bad template does not publish.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() await hass.services.async_call( mqtt.DOMAIN, mqtt.SERVICE_PUBLISH, @@ -565,13 +565,13 @@ async def test_service_call_with_bad_template( async def test_service_call_with_payload_doesnt_render_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the service call with unrendered template. If both 'payload' and 'payload_template' are provided then fail. """ - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() payload = "not a template" payload_template = "a template" with pytest.raises(vol.Invalid): @@ -589,13 +589,13 @@ async def test_service_call_with_payload_doesnt_render_template( async def test_service_call_with_ascii_qos_retain_flags( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the service call with args that can be misinterpreted. Empty payload message and ascii formatted qos and retain flags. """ - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() await hass.services.async_call( mqtt.DOMAIN, mqtt.SERVICE_PUBLISH, @@ -615,10 +615,10 @@ async def test_service_call_with_ascii_qos_retain_flags( async def test_publish_function_with_bad_encoding_conditions( hass: HomeAssistant, caplog: pytest.LogCaptureFixture, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test internal publish function with basic use cases.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() await mqtt.async_publish( hass, "some-topic", "test-payload", qos=0, retain=False, encoding=None ) @@ -818,11 +818,11 @@ def test_entity_device_info_schema() -> None: async def test_handle_logging_on_writing_the_entity_state( hass: HomeAssistant, mock_hass_config: None, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test on log handling when an error occurs writing the state.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() await hass.async_block_till_done() async_fire_mqtt_message(hass, "test/state", b"initial_state") await hass.async_block_till_done() @@ -845,12 +845,12 @@ async def test_handle_logging_on_writing_the_entity_state( async def test_receiving_non_utf8_message_gets_logged( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, record_calls: MessageCallbackType, caplog: pytest.LogCaptureFixture, ) -> None: """Test receiving a non utf8 encoded message.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() await mqtt.async_subscribe(hass, "test-topic", record_calls) async_fire_mqtt_message(hass, "test-topic", b"\x9a") @@ -863,12 +863,12 @@ async def test_receiving_non_utf8_message_gets_logged( async def test_all_subscriptions_run_when_decode_fails( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, calls: list[ReceiveMessage], record_calls: MessageCallbackType, ) -> None: """Test all other subscriptions still run when decode fails for one.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() await mqtt.async_subscribe(hass, "test-topic", record_calls, encoding="ascii") await mqtt.async_subscribe(hass, "test-topic", record_calls) @@ -880,12 +880,12 @@ async def test_all_subscriptions_run_when_decode_fails( async def test_subscribe_topic( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, calls: list[ReceiveMessage], record_calls: MessageCallbackType, ) -> None: """Test the subscription of a topic.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() unsub = await mqtt.async_subscribe(hass, "test-topic", record_calls) async_fire_mqtt_message(hass, "test-topic", "test-payload") @@ -909,12 +909,12 @@ async def test_subscribe_topic( async def test_subscribe_topic_non_async( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, calls: list[ReceiveMessage], record_calls: MessageCallbackType, ) -> None: """Test the subscription of a topic using the non-async function.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() unsub = await hass.async_add_executor_job( mqtt.subscribe, hass, "test-topic", record_calls ) @@ -937,11 +937,11 @@ async def test_subscribe_topic_non_async( async def test_subscribe_bad_topic( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, record_calls: MessageCallbackType, ) -> None: """Test the subscription of a topic.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() with pytest.raises(HomeAssistantError): await mqtt.async_subscribe(hass, 55, record_calls) # type: ignore[arg-type] @@ -949,10 +949,10 @@ async def test_subscribe_bad_topic( # Support for a deprecated callback type was removed with HA core 2023.3.0 # Test can be removed from HA core 2023.5.0 async def test_subscribe_with_deprecated_callback_fails( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the subscription of a topic using deprecated callback signature fails.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async def record_calls(topic: str, payload: ReceivePayloadType, qos: int) -> None: """Record calls.""" @@ -967,10 +967,10 @@ async def test_subscribe_with_deprecated_callback_fails( # Support for a deprecated callback type was removed with HA core 2023.3.0 # Test can be removed from HA core 2023.5.0 async def test_subscribe_deprecated_async_fails( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the subscription of a topic using deprecated coroutine signature fails.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() @callback def async_record_calls(topic: str, payload: ReceivePayloadType, qos: int) -> None: @@ -988,12 +988,12 @@ async def test_subscribe_deprecated_async_fails( async def test_subscribe_topic_not_match( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, calls: list[ReceiveMessage], record_calls: MessageCallbackType, ) -> None: """Test if subscribed topic is not a match.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() await mqtt.async_subscribe(hass, "test-topic", record_calls) async_fire_mqtt_message(hass, "another-test-topic", "test-payload") @@ -1004,12 +1004,12 @@ async def test_subscribe_topic_not_match( async def test_subscribe_topic_level_wildcard( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, calls: list[ReceiveMessage], record_calls: MessageCallbackType, ) -> None: """Test the subscription of wildcard topics.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() await mqtt.async_subscribe(hass, "test-topic/+/on", record_calls) async_fire_mqtt_message(hass, "test-topic/bier/on", "test-payload") @@ -1022,12 +1022,12 @@ async def test_subscribe_topic_level_wildcard( async def test_subscribe_topic_level_wildcard_no_subtree_match( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, calls: list[ReceiveMessage], record_calls: MessageCallbackType, ) -> None: """Test the subscription of wildcard topics.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() await mqtt.async_subscribe(hass, "test-topic/+/on", record_calls) async_fire_mqtt_message(hass, "test-topic/bier", "test-payload") @@ -1038,12 +1038,12 @@ async def test_subscribe_topic_level_wildcard_no_subtree_match( async def test_subscribe_topic_level_wildcard_root_topic_no_subtree_match( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, calls: list[ReceiveMessage], record_calls: MessageCallbackType, ) -> None: """Test the subscription of wildcard topics.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() await mqtt.async_subscribe(hass, "test-topic/#", record_calls) async_fire_mqtt_message(hass, "test-topic-123", "test-payload") @@ -1054,12 +1054,12 @@ async def test_subscribe_topic_level_wildcard_root_topic_no_subtree_match( async def test_subscribe_topic_subtree_wildcard_subtree_topic( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, calls: list[ReceiveMessage], record_calls: MessageCallbackType, ) -> None: """Test the subscription of wildcard topics.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() await mqtt.async_subscribe(hass, "test-topic/#", record_calls) async_fire_mqtt_message(hass, "test-topic/bier/on", "test-payload") @@ -1072,12 +1072,12 @@ async def test_subscribe_topic_subtree_wildcard_subtree_topic( async def test_subscribe_topic_subtree_wildcard_root_topic( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, calls: list[ReceiveMessage], record_calls: MessageCallbackType, ) -> None: """Test the subscription of wildcard topics.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() await mqtt.async_subscribe(hass, "test-topic/#", record_calls) async_fire_mqtt_message(hass, "test-topic", "test-payload") @@ -1090,12 +1090,12 @@ async def test_subscribe_topic_subtree_wildcard_root_topic( async def test_subscribe_topic_subtree_wildcard_no_match( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, calls: list[ReceiveMessage], record_calls: MessageCallbackType, ) -> None: """Test the subscription of wildcard topics.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() await mqtt.async_subscribe(hass, "test-topic/#", record_calls) async_fire_mqtt_message(hass, "another-test-topic", "test-payload") @@ -1106,12 +1106,12 @@ async def test_subscribe_topic_subtree_wildcard_no_match( async def test_subscribe_topic_level_wildcard_and_wildcard_root_topic( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, calls: list[ReceiveMessage], record_calls: MessageCallbackType, ) -> None: """Test the subscription of wildcard topics.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() await mqtt.async_subscribe(hass, "+/test-topic/#", record_calls) async_fire_mqtt_message(hass, "hi/test-topic", "test-payload") @@ -1124,12 +1124,12 @@ async def test_subscribe_topic_level_wildcard_and_wildcard_root_topic( async def test_subscribe_topic_level_wildcard_and_wildcard_subtree_topic( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, calls: list[ReceiveMessage], record_calls: MessageCallbackType, ) -> None: """Test the subscription of wildcard topics.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() await mqtt.async_subscribe(hass, "+/test-topic/#", record_calls) async_fire_mqtt_message(hass, "hi/test-topic/here-iam", "test-payload") @@ -1142,12 +1142,12 @@ async def test_subscribe_topic_level_wildcard_and_wildcard_subtree_topic( async def test_subscribe_topic_level_wildcard_and_wildcard_level_no_match( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, calls: list[ReceiveMessage], record_calls: MessageCallbackType, ) -> None: """Test the subscription of wildcard topics.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() await mqtt.async_subscribe(hass, "+/test-topic/#", record_calls) async_fire_mqtt_message(hass, "hi/here-iam/test-topic", "test-payload") @@ -1158,12 +1158,12 @@ async def test_subscribe_topic_level_wildcard_and_wildcard_level_no_match( async def test_subscribe_topic_level_wildcard_and_wildcard_no_match( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, calls: list[ReceiveMessage], record_calls: MessageCallbackType, ) -> None: """Test the subscription of wildcard topics.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() await mqtt.async_subscribe(hass, "+/test-topic/#", record_calls) async_fire_mqtt_message(hass, "hi/another-test-topic", "test-payload") @@ -1174,12 +1174,12 @@ async def test_subscribe_topic_level_wildcard_and_wildcard_no_match( async def test_subscribe_topic_sys_root( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, calls: list[ReceiveMessage], record_calls: MessageCallbackType, ) -> None: """Test the subscription of $ root topics.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() await mqtt.async_subscribe(hass, "$test-topic/subtree/on", record_calls) async_fire_mqtt_message(hass, "$test-topic/subtree/on", "test-payload") @@ -1192,12 +1192,12 @@ async def test_subscribe_topic_sys_root( async def test_subscribe_topic_sys_root_and_wildcard_topic( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, calls: list[ReceiveMessage], record_calls: MessageCallbackType, ) -> None: """Test the subscription of $ root and wildcard topics.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() await mqtt.async_subscribe(hass, "$test-topic/#", record_calls) async_fire_mqtt_message(hass, "$test-topic/some-topic", "test-payload") @@ -1210,12 +1210,12 @@ async def test_subscribe_topic_sys_root_and_wildcard_topic( async def test_subscribe_topic_sys_root_and_wildcard_subtree_topic( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, calls: list[ReceiveMessage], record_calls: MessageCallbackType, ) -> None: """Test the subscription of $ root and wildcard subtree topics.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() await mqtt.async_subscribe(hass, "$test-topic/subtree/#", record_calls) async_fire_mqtt_message(hass, "$test-topic/subtree/some-topic", "test-payload") @@ -1228,12 +1228,12 @@ async def test_subscribe_topic_sys_root_and_wildcard_subtree_topic( async def test_subscribe_special_characters( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, calls: list[ReceiveMessage], record_calls: MessageCallbackType, ) -> None: """Test the subscription to topics with special characters.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() topic = "/test-topic/$(.)[^]{-}" payload = "p4y.l[]a|> ?" @@ -1252,14 +1252,14 @@ async def test_subscribe_special_characters( async def test_subscribe_same_topic( hass: HomeAssistant, mqtt_client_mock: MqttMockPahoClient, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test subscribing to same topic twice and simulate retained messages. When subscribing to the same topic again, SUBSCRIBE must be sent to the broker again for it to resend any retained messages. """ - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() # Fake that the client is connected mqtt_mock().connected = True @@ -1305,11 +1305,11 @@ async def test_subscribe_same_topic( async def test_not_calling_unsubscribe_with_active_subscribers( hass: HomeAssistant, mqtt_client_mock: MqttMockPahoClient, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, record_calls: MessageCallbackType, ) -> None: """Test not calling unsubscribe() when other subscribers are active.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() # Fake that the client is connected mqtt_mock().connected = True @@ -1328,7 +1328,7 @@ async def test_not_calling_unsubscribe_with_active_subscribers( async def test_not_calling_subscribe_when_unsubscribed_within_cooldown( hass: HomeAssistant, mqtt_client_mock: MqttMockPahoClient, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, record_calls: MessageCallbackType, ) -> None: """Test not calling subscribe() when it is unsubscribed. @@ -1336,7 +1336,7 @@ async def test_not_calling_subscribe_when_unsubscribed_within_cooldown( Make sure subscriptions are cleared if unsubscribed before the subscribe cool down period has ended. """ - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() # Fake that the client is connected mqtt_mock().connected = True @@ -1352,10 +1352,10 @@ async def test_not_calling_subscribe_when_unsubscribed_within_cooldown( async def test_unsubscribe_race( hass: HomeAssistant, mqtt_client_mock: MqttMockPahoClient, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test not calling unsubscribe() when other subscribers are active.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() # Fake that the client is connected mqtt_mock().connected = True @@ -1411,11 +1411,11 @@ async def test_unsubscribe_race( async def test_restore_subscriptions_on_reconnect( hass: HomeAssistant, mqtt_client_mock: MqttMockPahoClient, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, record_calls: MessageCallbackType, ) -> None: """Test subscriptions are restored on reconnect.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() # Fake that the client is connected mqtt_mock().connected = True @@ -1442,11 +1442,11 @@ async def test_restore_subscriptions_on_reconnect( async def test_restore_all_active_subscriptions_on_reconnect( hass: HomeAssistant, mqtt_client_mock: MqttMockPahoClient, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, record_calls: MessageCallbackType, ) -> None: """Test active subscriptions are restored correctly on reconnect.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() # Fake that the client is connected mqtt_mock().connected = True @@ -1492,11 +1492,11 @@ async def test_restore_all_active_subscriptions_on_reconnect( async def test_subscribed_at_highest_qos( hass: HomeAssistant, mqtt_client_mock: MqttMockPahoClient, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, record_calls: MessageCallbackType, ) -> None: """Test the highest qos as assigned when subscribing to the same topic.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() # Fake that the client is connected mqtt_mock().connected = True @@ -1592,11 +1592,11 @@ async def test_canceling_debouncer_on_shutdown( hass: HomeAssistant, record_calls: MessageCallbackType, mqtt_client_mock: MqttMockPahoClient, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test canceling the debouncer when HA shuts down.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() # Fake that the client is connected mqtt_mock().connected = True @@ -1692,11 +1692,11 @@ async def test_initial_setup_logs_error( async def test_logs_error_if_no_connect_broker( hass: HomeAssistant, caplog: pytest.LogCaptureFixture, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, mqtt_client_mock: MqttMockPahoClient, ) -> None: """Test for setup failure if connection to broker is missing.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() # test with rc = 3 -> broker unavailable mqtt_client_mock.on_connect(mqtt_client_mock, None, None, 3) await hass.async_block_till_done() @@ -1710,11 +1710,11 @@ async def test_logs_error_if_no_connect_broker( async def test_handle_mqtt_on_callback( hass: HomeAssistant, caplog: pytest.LogCaptureFixture, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, mqtt_client_mock: MqttMockPahoClient, ) -> None: """Test receiving an ACK callback before waiting for it.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() # Simulate an ACK for mid == 1, this will call mqtt_mock._mqtt_handle_mid(mid) mqtt_client_mock.on_publish(mqtt_client_mock, None, 1) await hass.async_block_till_done() @@ -1750,13 +1750,13 @@ async def test_publish_error( @patch("homeassistant.components.mqtt.client.INITIAL_SUBSCRIBE_COOLDOWN", 0.0) async def test_subscribe_error( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, mqtt_client_mock: MqttMockPahoClient, record_calls: MessageCallbackType, caplog: pytest.LogCaptureFixture, ) -> None: """Test publish error.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() mqtt_client_mock.on_connect(mqtt_client_mock, None, None, 0) await hass.async_block_till_done() await hass.async_block_till_done() @@ -1775,7 +1775,7 @@ async def test_subscribe_error( async def test_handle_message_callback( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, mqtt_client_mock: MqttMockPahoClient, ) -> None: """Test for handling an incoming message callback.""" @@ -1785,7 +1785,7 @@ async def test_handle_message_callback( def _callback(args) -> None: callbacks.append(args) - mock_mqtt = await mqtt_mock_entry_no_yaml_config() + mock_mqtt = await mqtt_mock_entry() msg = ReceiveMessage("some-topic", b"test-payload", 1, False) mqtt_client_mock.on_connect(mqtt_client_mock, None, None, 0) await mqtt.async_subscribe(hass, "some-topic", _callback) @@ -1872,12 +1872,12 @@ async def test_setup_manual_mqtt_empty_platform( ) async def test_setup_mqtt_client_protocol( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, protocol: int, ) -> None: """Test MQTT client protocol setup.""" with patch("paho.mqtt.client.Client") as mock_client: - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() # check if protocol setup was correctly assert mock_client.call_args[1]["protocol"] == protocol @@ -1959,7 +1959,7 @@ async def test_setup_raises_config_entry_not_ready_if_no_connect_broker( @patch("homeassistant.components.mqtt.PLATFORMS", []) async def test_setup_uses_certificate_on_certificate_set_to_auto_and_insecure( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, insecure_param: bool | str, ) -> None: """Test setup uses bundled certs when certificate is set to auto and insecure.""" @@ -1977,7 +1977,7 @@ async def test_setup_uses_certificate_on_certificate_set_to_auto_and_insecure( with patch("paho.mqtt.client.Client") as mock_client: mock_client().tls_set = mock_tls_set mock_client().tls_insecure_set = mock_tls_insecure_set - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() await hass.async_block_till_done() assert calls @@ -2003,10 +2003,10 @@ async def test_setup_uses_certificate_on_certificate_set_to_auto_and_insecure( async def test_tls_version( hass: HomeAssistant, mqtt_client_mock: MqttMockPahoClient, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test setup defaults for tls.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() await hass.async_block_till_done() assert ( mqtt_client_mock.tls_set.mock_calls[0][2]["tls_version"] @@ -2031,10 +2031,10 @@ async def test_tls_version( async def test_custom_birth_message( hass: HomeAssistant, mqtt_client_mock: MqttMockPahoClient, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test sending birth message.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() birth = asyncio.Event() async def wait_birth(msg: ReceiveMessage) -> None: @@ -2066,10 +2066,10 @@ async def test_custom_birth_message( async def test_default_birth_message( hass: HomeAssistant, mqtt_client_mock: MqttMockPahoClient, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test sending birth message.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() birth = asyncio.Event() async def wait_birth(msg: ReceiveMessage) -> None: @@ -2093,10 +2093,10 @@ async def test_default_birth_message( async def test_no_birth_message( hass: HomeAssistant, mqtt_client_mock: MqttMockPahoClient, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test disabling birth message.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() with patch("homeassistant.components.mqtt.client.DISCOVERY_COOLDOWN", 0.1): mqtt_client_mock.on_connect(None, None, 0, 0) await hass.async_block_till_done() @@ -2122,10 +2122,10 @@ async def test_delayed_birth_message( hass: HomeAssistant, mqtt_client_mock: MqttMockPahoClient, mqtt_config_entry_data, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test sending birth message does not happen until Home Assistant starts.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() hass.state = CoreState.starting birth = asyncio.Event() @@ -2184,10 +2184,10 @@ async def test_delayed_birth_message( async def test_custom_will_message( hass: HomeAssistant, mqtt_client_mock: MqttMockPahoClient, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test will message.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() mqtt_client_mock.will_set.assert_called_with( topic="death", payload="death", qos=0, retain=False @@ -2197,10 +2197,10 @@ async def test_custom_will_message( async def test_default_will_message( hass: HomeAssistant, mqtt_client_mock: MqttMockPahoClient, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test will message.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() mqtt_client_mock.will_set.assert_called_with( topic="homeassistant/status", payload="offline", qos=0, retain=False @@ -2214,10 +2214,10 @@ async def test_default_will_message( async def test_no_will_message( hass: HomeAssistant, mqtt_client_mock: MqttMockPahoClient, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test will message.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() mqtt_client_mock.will_set.assert_not_called() @@ -2235,11 +2235,11 @@ async def test_no_will_message( async def test_mqtt_subscribes_topics_on_connect( hass: HomeAssistant, mqtt_client_mock: MqttMockPahoClient, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, record_calls: MessageCallbackType, ) -> None: """Test subscription to topic on connect.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() await mqtt.async_subscribe(hass, "topic/test", record_calls) await mqtt.async_subscribe(hass, "home/sensor", record_calls, 2) @@ -2261,7 +2261,7 @@ async def test_mqtt_subscribes_topics_on_connect( async def test_default_entry_setting_are_applied( hass: HomeAssistant, device_registry: dr.DeviceRegistry, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, mqtt_client_mock: MqttMockPahoClient, caplog: pytest.LogCaptureFixture, ) -> None: @@ -2275,7 +2275,7 @@ async def test_default_entry_setting_are_applied( # Config entry data is incomplete but valid according the schema entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0] entry.data = {"broker": "test-broker", "port": 1234} - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() await hass.async_block_till_done() # Discover a device to verify the entry was setup correctly @@ -2292,10 +2292,10 @@ async def test_default_entry_setting_are_applied( async def test_message_callback_exception_gets_logged( hass: HomeAssistant, caplog: pytest.LogCaptureFixture, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test exception raised by message handler.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() @callback def bad_handler(*args) -> None: @@ -2315,10 +2315,10 @@ async def test_message_callback_exception_gets_logged( async def test_mqtt_ws_subscription( hass: HomeAssistant, hass_ws_client: WebSocketGenerator, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test MQTT websocket subscription.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() client = await hass_ws_client(hass) await client.send_json({"id": 5, "type": "mqtt/subscribe", "topic": "test-topic"}) response = await client.receive_json() @@ -2380,11 +2380,11 @@ async def test_mqtt_ws_subscription( async def test_mqtt_ws_subscription_not_admin( hass: HomeAssistant, hass_ws_client: WebSocketGenerator, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, hass_read_only_access_token: str, ) -> None: """Test MQTT websocket user is not admin.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() client = await hass_ws_client(hass, access_token=hass_read_only_access_token) await client.send_json({"id": 5, "type": "mqtt/subscribe", "topic": "test-topic"}) response = await client.receive_json() @@ -2394,10 +2394,10 @@ async def test_mqtt_ws_subscription_not_admin( async def test_dump_service( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test that we can dump a topic.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() mopen = mock_open() await hass.services.async_call( @@ -2420,12 +2420,12 @@ async def test_mqtt_ws_remove_discovered_device( hass: HomeAssistant, device_registry: dr.DeviceRegistry, hass_ws_client: WebSocketGenerator, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test MQTT websocket device removal.""" assert await async_setup_component(hass, "config", {}) await hass.async_block_till_done() - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() data = ( '{ "device":{"identifiers":["0AFFD2"]},' @@ -2462,10 +2462,10 @@ async def test_mqtt_ws_get_device_debug_info( hass: HomeAssistant, device_registry: dr.DeviceRegistry, hass_ws_client: WebSocketGenerator, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test MQTT websocket device debug info.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() config_sensor = { "device": {"identifiers": ["0AFFD2"]}, "state_topic": "foobar/sensor", @@ -2528,10 +2528,10 @@ async def test_mqtt_ws_get_device_debug_info_binary( hass: HomeAssistant, device_registry: dr.DeviceRegistry, hass_ws_client: WebSocketGenerator, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test MQTT websocket device debug info.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() config = { "device": {"identifiers": ["0AFFD2"]}, "topic": "foobar/image", @@ -2592,10 +2592,10 @@ async def test_mqtt_ws_get_device_debug_info_binary( async def test_debug_info_multiple_devices( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test we get correct debug_info when multiple devices are present.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() devices: list[_DebugInfo] = [ { "domain": "sensor", @@ -2674,10 +2674,10 @@ async def test_debug_info_multiple_devices( async def test_debug_info_multiple_entities_triggers( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test we get correct debug_info for a device with multiple entities and triggers.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() config: list[_DebugInfo] = [ { "domain": "sensor", @@ -2763,10 +2763,10 @@ async def test_debug_info_non_mqtt( hass: HomeAssistant, device_registry: dr.DeviceRegistry, entity_registry: er.EntityRegistry, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test we get empty debug_info for a device with non MQTT entities.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() domain = "sensor" platform = getattr(hass.components, f"test.{domain}") platform.init() @@ -2795,10 +2795,10 @@ async def test_debug_info_non_mqtt( async def test_debug_info_wildcard( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test debug info.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() config = { "device": {"identifiers": ["helloworld"]}, "name": "test", @@ -2843,10 +2843,10 @@ async def test_debug_info_wildcard( async def test_debug_info_filter_same( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test debug info removes messages with same timestamp.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() config = { "device": {"identifiers": ["helloworld"]}, "name": "test", @@ -2903,10 +2903,10 @@ async def test_debug_info_filter_same( async def test_debug_info_same_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test debug info.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() config = { "device": {"identifiers": ["helloworld"]}, "name": "test", @@ -2957,10 +2957,10 @@ async def test_debug_info_same_topic( async def test_debug_info_qos_retain( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test debug info.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() config = { "device": {"identifiers": ["helloworld"]}, "name": "test", @@ -3016,10 +3016,10 @@ async def test_debug_info_qos_retain( async def test_publish_json_from_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the publishing of call to services.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() test_str = "{'valid': 'python', 'invalid': 'json'}" test_str_tpl = "{'valid': '{{ \"python\" }}', 'invalid': 'json'}" @@ -3068,11 +3068,11 @@ async def test_publish_json_from_template( async def test_subscribe_connection_status( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, mqtt_client_mock: MqttMockPahoClient, ) -> None: """Test connextion status subscription.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() mqtt_connected_calls = [] @callback @@ -3110,7 +3110,7 @@ async def test_subscribe_connection_status( # This warning and test is to be removed from HA core 2023.6 async def test_one_deprecation_warning_per_platform( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test a deprecation warning is is logged once per platform.""" @@ -3187,11 +3187,11 @@ async def test_publish_or_subscribe_without_valid_config_entry( ) async def test_disabling_and_enabling_entry( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test disabling and enabling the config entry.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0] assert entry.state is ConfigEntryState.LOADED # Late discovery of a light @@ -3269,12 +3269,12 @@ async def test_disabling_and_enabling_entry( ) async def test_setup_manual_items_with_unique_ids( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, unique: bool, ) -> None: """Test setup manual items is generating unique id's.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() assert hass.states.get("light.test1") is not None assert (hass.states.get("light.test2") is not None) == unique @@ -3313,12 +3313,12 @@ async def test_setup_manual_items_with_unique_ids( ) async def test_link_config_entry( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test manual and dynamically setup entities are linked to the config entry.""" # set up manual item - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() # set up item through discovery config_discovery = { diff --git a/tests/components/mqtt/test_legacy_vacuum.py b/tests/components/mqtt/test_legacy_vacuum.py index e4cf5bb8030..bf10a692b7c 100644 --- a/tests/components/mqtt/test_legacy_vacuum.py +++ b/tests/components/mqtt/test_legacy_vacuum.py @@ -125,10 +125,10 @@ def vacuum_platform_only(): @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_default_supported_features( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test that the correct supported features.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() entity = hass.states.get("vacuum.mqtttest") entity_features = entity.attributes.get(mqttvacuum.CONF_SUPPORTED_FEATURES, 0) assert sorted(services_to_strings(entity_features, SERVICE_TO_STRING)) == sorted( @@ -149,10 +149,10 @@ async def test_default_supported_features( [DEFAULT_CONFIG_ALL_SERVICES], ) async def test_all_commands( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test simple commands to the vacuum.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() await common.async_turn_on(hass, "vacuum.mqtttest") mqtt_mock.async_publish.assert_called_once_with( @@ -240,10 +240,10 @@ async def test_all_commands( ], ) async def test_commands_without_supported_features( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test commands which are not supported by the vacuum.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() await common.async_turn_on(hass, "vacuum.mqtttest") mqtt_mock.async_publish.assert_not_called() @@ -299,10 +299,10 @@ async def test_commands_without_supported_features( ], ) async def test_attributes_without_supported_features( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test attributes which are not supported by the vacuum.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() message = """{ "battery_level": 54, @@ -325,10 +325,10 @@ async def test_attributes_without_supported_features( [DEFAULT_CONFIG_ALL_SERVICES], ) async def test_status( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test status updates from the vacuum.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() message = """{ "battery_level": 54, @@ -365,10 +365,10 @@ async def test_status( [DEFAULT_CONFIG_ALL_SERVICES], ) async def test_status_battery( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test status updates from the vacuum.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() message = """{ "battery_level": 54 @@ -383,11 +383,11 @@ async def test_status_battery( [DEFAULT_CONFIG_ALL_SERVICES], ) async def test_status_cleaning( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test status updates from the vacuum.""" await hass.async_block_till_done() - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() message = """{ "cleaning": true @@ -402,10 +402,10 @@ async def test_status_cleaning( [DEFAULT_CONFIG_ALL_SERVICES], ) async def test_status_docked( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test status updates from the vacuum.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() message = """{ "docked": true @@ -420,10 +420,10 @@ async def test_status_docked( [DEFAULT_CONFIG_ALL_SERVICES], ) async def test_status_charging( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test status updates from the vacuum.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() message = """{ "charging": true @@ -435,10 +435,10 @@ async def test_status_charging( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_ALL_SERVICES]) async def test_status_fan_speed( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test status updates from the vacuum.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() message = """{ "fan_speed": "max" @@ -450,10 +450,10 @@ async def test_status_fan_speed( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_ALL_SERVICES]) async def test_status_fan_speed_list( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test status updates from the vacuum.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("vacuum.mqtttest") assert state.attributes.get(ATTR_FAN_SPEED_LIST) == ["min", "medium", "high", "max"] @@ -476,13 +476,13 @@ async def test_status_fan_speed_list( ], ) async def test_status_no_fan_speed_list( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test status updates from the vacuum. If the vacuum doesn't support fan speed, fan speed list should be None. """ - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("vacuum.mqtttest") assert state.attributes.get(ATTR_FAN_SPEED_LIST) is None @@ -490,10 +490,10 @@ async def test_status_no_fan_speed_list( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_ALL_SERVICES]) async def test_status_error( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test status updates from the vacuum.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() message = """{ "error": "Error1" @@ -526,10 +526,10 @@ async def test_status_error( ], ) async def test_battery_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test that you can use non-default templates for battery_level.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, "retroroomba/battery_level", "54") state = hass.states.get("vacuum.mqtttest") @@ -539,10 +539,10 @@ async def test_battery_template( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_ALL_SERVICES]) async def test_status_invalid_json( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test to make sure nothing breaks if the vacuum sends bad JSON.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, "vacuum/state", '{"asdfasas false}') state = hass.states.get("vacuum.mqtttest") @@ -563,12 +563,12 @@ async def test_status_invalid_json( ) async def test_missing_templates( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test to make sure missing template is not allowed.""" with pytest.raises(AssertionError): - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() assert ( "Invalid config for [mqtt]: some but not all values in the same group of inclusion" in caplog.text @@ -577,58 +577,58 @@ async def test_missing_templates( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_2]) async def test_availability_when_connection_lost( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability after MQTT disconnection.""" await help_test_availability_when_connection_lost( - hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN + hass, mqtt_mock_entry, vacuum.DOMAIN ) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_2]) async def test_availability_without_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability without defined availability topic.""" await help_test_availability_without_topic( - hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2 + hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2 ) async def test_default_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by default payload with defined topic.""" await help_test_default_availability_payload( - hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2 + hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2 ) async def test_custom_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by custom payload with defined topic.""" await help_test_custom_availability_payload( - hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2 + hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2 ) async def test_setting_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_via_mqtt_json_message( - hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2 + hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2 ) async def test_setting_blocked_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_blocked_attribute_via_mqtt_json_message( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2, MQTT_LEGACY_VACUUM_ATTRIBUTES_BLOCKED, @@ -636,23 +636,23 @@ async def test_setting_blocked_attribute_via_mqtt_json_message( async def test_setting_attribute_with_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_with_template( - hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2 + hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2 ) async def test_update_with_json_attrs_not_dict( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_not_dict( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, vacuum.DOMAIN, DEFAULT_CONFIG_2, @@ -661,13 +661,13 @@ async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_bad_json( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_bad_json( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, vacuum.DOMAIN, DEFAULT_CONFIG_2, @@ -676,13 +676,13 @@ async def test_update_with_json_attrs_bad_json( async def test_discovery_update_attr( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered MQTTAttributes.""" await help_test_discovery_update_attr( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, vacuum.DOMAIN, DEFAULT_CONFIG_2, @@ -711,40 +711,40 @@ async def test_discovery_update_attr( ], ) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one vacuum per unique_id.""" - await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN) + await help_test_unique_id(hass, mqtt_mock_entry, vacuum.DOMAIN) async def test_discovery_removal_vacuum( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test removal of discovered vacuum.""" data = json.dumps(DEFAULT_CONFIG_2[mqtt.DOMAIN][vacuum.DOMAIN]) await help_test_discovery_removal( - hass, mqtt_mock_entry_no_yaml_config, caplog, vacuum.DOMAIN, data + hass, mqtt_mock_entry, caplog, vacuum.DOMAIN, data ) async def test_discovery_update_vacuum( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered vacuum.""" config1 = {"name": "Beer", "command_topic": "test_topic"} config2 = {"name": "Milk", "command_topic": "test_topic"} await help_test_discovery_update( - hass, mqtt_mock_entry_no_yaml_config, caplog, vacuum.DOMAIN, config1, config2 + hass, mqtt_mock_entry, caplog, vacuum.DOMAIN, config1, config2 ) async def test_discovery_update_unchanged_vacuum( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered vacuum.""" @@ -754,7 +754,7 @@ async def test_discovery_update_unchanged_vacuum( ) as discovery_update: await help_test_discovery_update_unchanged( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, vacuum.DOMAIN, data1, @@ -765,55 +765,55 @@ async def test_discovery_update_unchanged_vacuum( @pytest.mark.no_fail_on_log_exception async def test_discovery_broken( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test handling of bad discovery message.""" data1 = '{ "name": "Beer",' ' "command_topic": "test_topic#" }' data2 = '{ "name": "Milk",' ' "command_topic": "test_topic" }' await help_test_discovery_broken( - hass, mqtt_mock_entry_no_yaml_config, caplog, vacuum.DOMAIN, data1, data2 + hass, mqtt_mock_entry, caplog, vacuum.DOMAIN, data1, data2 ) async def test_entity_device_info_with_connection( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT vacuum device registry integration.""" await help_test_entity_device_info_with_connection( - hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2 + hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2 ) async def test_entity_device_info_with_identifier( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT vacuum device registry integration.""" await help_test_entity_device_info_with_identifier( - hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2 + hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2 ) async def test_entity_device_info_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry update.""" await help_test_entity_device_info_update( - hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2 + hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2 ) async def test_entity_device_info_remove( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry remove.""" await help_test_entity_device_info_remove( - hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2 + hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2 ) async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" config = { @@ -829,7 +829,7 @@ async def test_entity_id_update_subscriptions( } await help_test_entity_id_update_subscriptions( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, vacuum.DOMAIN, config, ["test-topic", "avty-topic"], @@ -837,16 +837,16 @@ async def test_entity_id_update_subscriptions( async def test_entity_id_update_discovery_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT discovery update when entity_id is updated.""" await help_test_entity_id_update_discovery_update( - hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2 + hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2 ) async def test_entity_debug_info_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT debug info.""" config = { @@ -862,7 +862,7 @@ async def test_entity_debug_info_message( } await help_test_entity_debug_info_message( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, vacuum.DOMAIN, config, vacuum.SERVICE_TURN_ON, @@ -911,7 +911,7 @@ async def test_entity_debug_info_message( ) async def test_publishing_with_custom_encoding( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, service: str, topic: str, @@ -932,7 +932,7 @@ async def test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, domain, config, @@ -977,7 +977,7 @@ async def test_reloadable( ) async def test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, topic: str, value: str, attribute: str | None, @@ -1002,7 +1002,7 @@ async def test_encoding_subscribable_topics( await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, vacuum.DOMAIN, config, topic, @@ -1015,9 +1015,9 @@ async def test_encoding_subscribable_topics( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_setup_manual_entity_from_yaml( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setup manual configured MQTT entity.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() platform = vacuum.DOMAIN assert hass.states.get(f"{platform}.mqtttest") diff --git a/tests/components/mqtt/test_light.py b/tests/components/mqtt/test_light.py index 6ad52103a06..0f5370b865c 100644 --- a/tests/components/mqtt/test_light.py +++ b/tests/components/mqtt/test_light.py @@ -247,12 +247,12 @@ def light_platform_only(): ) async def test_fail_setup_if_no_command_topic( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test if command fails with command topic.""" with pytest.raises(AssertionError): - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() assert ( "Invalid config for [mqtt]: required key not provided @ data['mqtt']['light'][0]['command_topic']. Got None." in caplog.text @@ -274,10 +274,10 @@ async def test_fail_setup_if_no_command_topic( ], ) async def test_no_color_brightness_color_temp_hs_white_xy_if_no_topics( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test if there is no color and brightness if no topic.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -352,12 +352,12 @@ async def test_no_color_brightness_color_temp_hs_white_xy_if_no_topics( ], ) async def test_controlling_state_via_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the controlling of the state via topic.""" color_modes = ["color_temp", "hs", "rgb", "rgbw", "rgbww", "xy"] - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -480,11 +480,11 @@ async def test_controlling_state_via_topic( ) async def test_invalid_state_via_topic( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test handling of empty data via topic.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -597,10 +597,10 @@ async def test_invalid_state_via_topic( ], ) async def test_brightness_controlling_scale( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the brightness controlling scale.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -646,10 +646,10 @@ async def test_brightness_controlling_scale( ], ) async def test_brightness_from_rgb_controlling_scale( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the brightness controlling scale.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() await hass.async_block_till_done() state = hass.states.get("light.test") @@ -728,12 +728,12 @@ async def test_brightness_from_rgb_controlling_scale( ], ) async def test_controlling_state_via_topic_with_templates( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of the state with a template.""" color_modes = ["color_temp", "hs", "rgb", "rgbw", "rgbww", "xy"] - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -821,7 +821,7 @@ async def test_controlling_state_via_topic_with_templates( ], ) async def test_sending_mqtt_commands_and_optimistic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the sending of command in optimistic mode.""" color_modes = ["color_temp", "hs", "rgb", "rgbw", "rgbww", "xy"] @@ -838,7 +838,7 @@ async def test_sending_mqtt_commands_and_optimistic( ) mock_restore_cache(hass, (fake_state,)) - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_ON @@ -1009,10 +1009,10 @@ async def test_sending_mqtt_commands_and_optimistic( ], ) async def test_sending_mqtt_rgb_command_with_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the sending of RGB command with template.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -1052,10 +1052,10 @@ async def test_sending_mqtt_rgb_command_with_template( ], ) async def test_sending_mqtt_rgbw_command_with_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the sending of RGBW command with template.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -1095,10 +1095,10 @@ async def test_sending_mqtt_rgbw_command_with_template( ], ) async def test_sending_mqtt_rgbww_command_with_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the sending of RGBWW command with template.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -1137,10 +1137,10 @@ async def test_sending_mqtt_rgbww_command_with_template( ], ) async def test_sending_mqtt_color_temp_command_with_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the sending of Color Temp command with template.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -1176,10 +1176,10 @@ async def test_sending_mqtt_color_temp_command_with_template( ], ) async def test_on_command_first( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test on command being sent before brightness.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -1217,10 +1217,10 @@ async def test_on_command_first( ], ) async def test_on_command_last( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test on command being sent after brightness.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -1260,10 +1260,10 @@ async def test_on_command_last( ], ) async def test_on_command_brightness( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test on command being sent as only brightness.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -1322,10 +1322,10 @@ async def test_on_command_brightness( ], ) async def test_on_command_brightness_scaled( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test brightness scale.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -1395,10 +1395,10 @@ async def test_on_command_brightness_scaled( ], ) async def test_on_command_rgb( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test on command in RGB brightness mode.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -1491,10 +1491,10 @@ async def test_on_command_rgb( ], ) async def test_on_command_rgbw( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test on command in RGBW brightness mode.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -1587,10 +1587,10 @@ async def test_on_command_rgbw( ], ) async def test_on_command_rgbww( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test on command in RGBWW brightness mode.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -1684,10 +1684,10 @@ async def test_on_command_rgbww( ], ) async def test_on_command_rgb_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test on command in RGB brightness mode with RGB template.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -1727,10 +1727,10 @@ async def test_on_command_rgb_template( ], ) async def test_on_command_rgbw_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test on command in RGBW brightness mode with RGBW template.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -1770,10 +1770,10 @@ async def test_on_command_rgbw_template( ], ) async def test_on_command_rgbww_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test on command in RGBWW brightness mode with RGBWW template.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -1824,12 +1824,12 @@ async def test_on_command_rgbww_template( ], ) async def test_on_command_white( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test sending commands for RGB + white light.""" color_modes = ["rgb", "white"] - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -1916,12 +1916,12 @@ async def test_on_command_white( ], ) async def test_explicit_color_mode( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test explicit color mode over mqtt.""" color_modes = ["color_temp", "hs", "rgb", "rgbw", "rgbww", "xy"] - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -2062,12 +2062,12 @@ async def test_explicit_color_mode( ], ) async def test_explicit_color_mode_templated( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test templated explicit color mode over mqtt.""" color_modes = ["color_temp", "hs"] - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -2157,12 +2157,12 @@ async def test_explicit_color_mode_templated( ], ) async def test_white_state_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test state updates for RGB + white light.""" color_modes = ["rgb", "white"] - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -2213,10 +2213,10 @@ async def test_white_state_update( ], ) async def test_effect( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test effect.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -2242,58 +2242,58 @@ async def test_effect( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_when_connection_lost( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability after MQTT disconnection.""" await help_test_availability_when_connection_lost( - hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN + hass, mqtt_mock_entry, light.DOMAIN ) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_without_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability without defined availability topic.""" await help_test_availability_without_topic( - hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG ) async def test_default_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by default payload with defined topic.""" await help_test_default_availability_payload( - hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG ) async def test_custom_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by custom payload with defined topic.""" await help_test_custom_availability_payload( - hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG ) async def test_setting_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_via_mqtt_json_message( - hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG ) async def test_setting_blocked_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_blocked_attribute_via_mqtt_json_message( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG, MQTT_LIGHT_ATTRIBUTES_BLOCKED, @@ -2301,23 +2301,23 @@ async def test_setting_blocked_attribute_via_mqtt_json_message( async def test_setting_attribute_with_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_with_template( - hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG ) async def test_update_with_json_attrs_not_dict( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_not_dict( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, light.DOMAIN, DEFAULT_CONFIG, @@ -2326,13 +2326,13 @@ async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_bad_json( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_bad_json( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, light.DOMAIN, DEFAULT_CONFIG, @@ -2341,13 +2341,13 @@ async def test_update_with_json_attrs_bad_json( async def test_discovery_update_attr( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered MQTTAttributes.""" await help_test_discovery_update_attr( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, light.DOMAIN, DEFAULT_CONFIG, @@ -2378,15 +2378,15 @@ async def test_discovery_update_attr( ], ) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one light per unique_id.""" - await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN) + await help_test_unique_id(hass, mqtt_mock_entry, light.DOMAIN) async def test_discovery_removal_light( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test removal of discovered light.""" @@ -2395,18 +2395,16 @@ async def test_discovery_removal_light( ' "state_topic": "test_topic",' ' "command_topic": "test_topic" }' ) - await help_test_discovery_removal( - hass, mqtt_mock_entry_no_yaml_config, caplog, light.DOMAIN, data - ) + await help_test_discovery_removal(hass, mqtt_mock_entry, caplog, light.DOMAIN, data) async def test_discovery_ignores_extra_keys( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test discovery ignores extra keys that are not blocked.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() # inserted `platform` key should be ignored data = ( '{ "name": "Beer",' ' "platform": "mqtt",' ' "command_topic": "test_topic"}' @@ -2420,7 +2418,7 @@ async def test_discovery_ignores_extra_keys( async def test_discovery_update_light_topic_and_template( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered light.""" @@ -2665,7 +2663,7 @@ async def test_discovery_update_light_topic_and_template( await help_test_discovery_update( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, light.DOMAIN, config1, @@ -2677,7 +2675,7 @@ async def test_discovery_update_light_topic_and_template( async def test_discovery_update_light_template( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered light.""" @@ -2880,7 +2878,7 @@ async def test_discovery_update_light_template( await help_test_discovery_update( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, light.DOMAIN, config1, @@ -2892,7 +2890,7 @@ async def test_discovery_update_light_template( async def test_discovery_update_unchanged_light( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered light.""" @@ -2906,7 +2904,7 @@ async def test_discovery_update_unchanged_light( ) as discovery_update: await help_test_discovery_update_unchanged( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, light.DOMAIN, data1, @@ -2917,7 +2915,7 @@ async def test_discovery_update_unchanged_light( @pytest.mark.no_fail_on_log_exception async def test_discovery_broken( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test handling of bad discovery message.""" @@ -2928,71 +2926,71 @@ async def test_discovery_broken( ' "command_topic": "test_topic" }' ) await help_test_discovery_broken( - hass, mqtt_mock_entry_no_yaml_config, caplog, light.DOMAIN, data1, data2 + hass, mqtt_mock_entry, caplog, light.DOMAIN, data1, data2 ) async def test_entity_device_info_with_connection( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT light device registry integration.""" await help_test_entity_device_info_with_connection( - hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_with_identifier( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT light device registry integration.""" await help_test_entity_device_info_with_identifier( - hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry update.""" await help_test_entity_device_info_update( - hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_remove( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry remove.""" await help_test_entity_device_info_remove( - hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG ) async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" await help_test_entity_id_update_subscriptions( - hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG ) async def test_entity_id_update_discovery_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT discovery update when entity_id is updated.""" await help_test_entity_id_update_discovery_update( - hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG ) async def test_entity_debug_info_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT debug info.""" await help_test_entity_debug_info_message( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG, light.SERVICE_TURN_ON, @@ -3015,10 +3013,10 @@ async def test_entity_debug_info_message( ], ) async def test_max_mireds( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setting min_mireds and max_mireds.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("light.test") assert state.attributes.get("min_mireds") == 153 @@ -3113,7 +3111,7 @@ async def test_max_mireds( ) async def test_publishing_with_custom_encoding( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, service: str, topic: str, @@ -3133,7 +3131,7 @@ async def test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, domain, config, @@ -3189,7 +3187,7 @@ async def test_reloadable( ) async def test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, topic: str, value: str, attribute: str | None, @@ -3211,7 +3209,7 @@ async def test_encoding_subscribable_topics( await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, light.DOMAIN, config, topic, @@ -3230,7 +3228,7 @@ async def test_encoding_subscribable_topics( ) async def test_encoding_subscribable_topics_brightness( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, topic: str, value: str, @@ -3244,7 +3242,7 @@ async def test_encoding_subscribable_topics_brightness( await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, light.DOMAIN, config, topic, @@ -3274,10 +3272,10 @@ async def test_encoding_subscribable_topics_brightness( ], ) async def test_sending_mqtt_brightness_command_with_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the sending of Brightness command with template.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -3318,10 +3316,10 @@ async def test_sending_mqtt_brightness_command_with_template( ], ) async def test_sending_mqtt_effect_command_with_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the sending of Effect command with template.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -3362,10 +3360,10 @@ async def test_sending_mqtt_effect_command_with_template( ], ) async def test_sending_mqtt_hs_command_with_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the sending of HS Color command with template.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -3405,10 +3403,10 @@ async def test_sending_mqtt_hs_command_with_template( ], ) async def test_sending_mqtt_xy_command_with_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the sending of XY Color command with template.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -3430,21 +3428,21 @@ async def test_sending_mqtt_xy_command_with_template( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_setup_manual_entity_from_yaml( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setup manual configured MQTT entity.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() platform = light.DOMAIN assert hass.states.get(f"{platform}.test") async def test_unload_entry( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test unloading the config entry.""" domain = light.DOMAIN config = DEFAULT_CONFIG await help_test_unload_config_entry_with_platform( - hass, mqtt_mock_entry_no_yaml_config, domain, config + hass, mqtt_mock_entry, domain, config ) diff --git a/tests/components/mqtt/test_light_json.py b/tests/components/mqtt/test_light_json.py index 1b24f7636f5..5add22af721 100644 --- a/tests/components/mqtt/test_light_json.py +++ b/tests/components/mqtt/test_light_json.py @@ -192,12 +192,12 @@ class JsonValidator: ) async def test_fail_setup_if_no_command_topic( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test if setup fails with no command topic.""" with pytest.raises(AssertionError): - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() assert ( "Invalid config for [mqtt]: required key not provided @ data['mqtt']['light'][0]['command_topic']. Got None." in caplog.text @@ -215,12 +215,12 @@ async def test_fail_setup_if_no_command_topic( ) async def test_fail_setup_if_color_mode_deprecated( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test if setup fails if color mode is combined with deprecated config keys.""" with pytest.raises(AssertionError): - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() assert ( "Invalid config for [mqtt]: color_mode must not be combined with any of" in caplog.text @@ -258,13 +258,13 @@ async def test_fail_setup_if_color_mode_deprecated( ) async def test_fail_setup_if_color_modes_invalid( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, error: str, ) -> None: """Test if setup fails if supported color modes is invalid.""" with pytest.raises(AssertionError): - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() assert error in caplog.text @@ -284,10 +284,10 @@ async def test_fail_setup_if_color_modes_invalid( ], ) async def test_legacy_rgb_light( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test legacy RGB light flags expected features and color modes.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("light.test") color_modes = [light.ColorMode.HS] @@ -312,10 +312,10 @@ async def test_legacy_rgb_light( ], ) async def test_no_color_brightness_color_temp_if_no_topics( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test for no RGB, brightness, color temp, effector XY.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -373,10 +373,10 @@ async def test_no_color_brightness_color_temp_if_no_topics( ], ) async def test_controlling_state_via_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the controlling of the state via topic.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -504,12 +504,12 @@ async def test_controlling_state_via_topic( ) async def test_controlling_state_via_topic2( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test the controlling of the state via topic for a light supporting color mode.""" supported_color_modes = ["color_temp", "hs", "rgb", "rgbw", "rgbww", "white", "xy"] - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -681,7 +681,7 @@ async def test_controlling_state_via_topic2( ], ) async def test_sending_mqtt_commands_and_optimistic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the sending of command in optimistic mode.""" fake_state = State( @@ -696,7 +696,7 @@ async def test_sending_mqtt_commands_and_optimistic( ) mock_restore_cache(hass, (fake_state,)) - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_ON @@ -834,7 +834,7 @@ async def test_sending_mqtt_commands_and_optimistic( ], ) async def test_sending_mqtt_commands_and_optimistic2( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the sending of command in optimistic mode for a light supporting color mode.""" supported_color_modes = ["color_temp", "hs", "rgb", "rgbw", "rgbww", "white", "xy"] @@ -851,7 +851,7 @@ async def test_sending_mqtt_commands_and_optimistic2( ) mock_restore_cache(hass, (fake_state,)) - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_ON @@ -1063,10 +1063,10 @@ async def test_sending_mqtt_commands_and_optimistic2( ], ) async def test_sending_hs_color( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test light.turn_on with hs color sends hs color parameters.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -1125,11 +1125,11 @@ async def test_sending_hs_color( ], ) async def test_sending_rgb_color_no_brightness( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test light.turn_on with hs color sends rgb color parameters.""" await hass.async_block_till_done() - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -1184,10 +1184,10 @@ async def test_sending_rgb_color_no_brightness( ], ) async def test_sending_rgb_color_no_brightness2( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test light.turn_on with hs color sends rgb color parameters.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -1264,10 +1264,10 @@ async def test_sending_rgb_color_no_brightness2( ], ) async def test_sending_rgb_color_with_brightness( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test light.turn_on with hs color sends rgb color parameters.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -1333,11 +1333,11 @@ async def test_sending_rgb_color_with_brightness( ], ) async def test_sending_rgb_color_with_scaled_brightness( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test light.turn_on with hs color sends rgb color parameters.""" await hass.async_block_till_done() - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -1405,10 +1405,10 @@ async def test_sending_rgb_color_with_scaled_brightness( ], ) async def test_sending_scaled_white( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test light.turn_on with scaled white.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -1449,10 +1449,10 @@ async def test_sending_scaled_white( ], ) async def test_sending_xy_color( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test light.turn_on with hs color sends xy color parameters.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -1511,10 +1511,10 @@ async def test_sending_xy_color( ], ) async def test_effect( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test for effect being sent when included.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -1578,10 +1578,10 @@ async def test_effect( ], ) async def test_flash_short_and_long( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test for flash length being sent when included.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -1641,10 +1641,10 @@ async def test_flash_short_and_long( ], ) async def test_transition( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test for transition time being sent when included.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -1693,10 +1693,10 @@ async def test_transition( ], ) async def test_brightness_scale( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test for brightness scaling.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -1741,10 +1741,10 @@ async def test_brightness_scale( ], ) async def test_white_scale( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test for white scaling.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -1801,10 +1801,10 @@ async def test_white_scale( ], ) async def test_invalid_values( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test that invalid color/brightness/etc. values are ignored.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -1912,58 +1912,58 @@ async def test_invalid_values( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_when_connection_lost( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability after MQTT disconnection.""" await help_test_availability_when_connection_lost( - hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN + hass, mqtt_mock_entry, light.DOMAIN ) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_without_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability without defined availability topic.""" await help_test_availability_without_topic( - hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG ) async def test_default_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by default payload with defined topic.""" await help_test_default_availability_payload( - hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG ) async def test_custom_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by custom payload with defined topic.""" await help_test_custom_availability_payload( - hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG ) async def test_setting_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_via_mqtt_json_message( - hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG ) async def test_setting_blocked_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_blocked_attribute_via_mqtt_json_message( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG, MQTT_LIGHT_ATTRIBUTES_BLOCKED, @@ -1971,23 +1971,23 @@ async def test_setting_blocked_attribute_via_mqtt_json_message( async def test_setting_attribute_with_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_with_template( - hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG ) async def test_update_with_json_attrs_not_dict( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_not_dict( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, light.DOMAIN, DEFAULT_CONFIG, @@ -1996,13 +1996,13 @@ async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_bad_json( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_bad_json( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, light.DOMAIN, DEFAULT_CONFIG, @@ -2011,13 +2011,13 @@ async def test_update_with_json_attrs_bad_json( async def test_discovery_update_attr( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered MQTTAttributes.""" await help_test_discovery_update_attr( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, light.DOMAIN, DEFAULT_CONFIG, @@ -2050,22 +2050,22 @@ async def test_discovery_update_attr( ], ) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one light per unique_id.""" - await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN) + await help_test_unique_id(hass, mqtt_mock_entry, light.DOMAIN) async def test_discovery_removal( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test removal of discovered mqtt_json lights.""" data = '{ "name": "test", "schema": "json", "command_topic": "test_topic" }' await help_test_discovery_removal( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, light.DOMAIN, data, @@ -2074,7 +2074,7 @@ async def test_discovery_removal( async def test_discovery_update_light( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered light.""" @@ -2092,7 +2092,7 @@ async def test_discovery_update_light( } await help_test_discovery_update( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, light.DOMAIN, config1, @@ -2102,7 +2102,7 @@ async def test_discovery_update_light( async def test_discovery_update_unchanged_light( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered light.""" @@ -2117,7 +2117,7 @@ async def test_discovery_update_unchanged_light( ) as discovery_update: await help_test_discovery_update_unchanged( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, light.DOMAIN, data1, @@ -2128,7 +2128,7 @@ async def test_discovery_update_unchanged_light( @pytest.mark.no_fail_on_log_exception async def test_discovery_broken( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test handling of bad discovery message.""" @@ -2141,7 +2141,7 @@ async def test_discovery_broken( ) await help_test_discovery_broken( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, light.DOMAIN, data1, @@ -2150,78 +2150,78 @@ async def test_discovery_broken( async def test_entity_device_info_with_connection( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT light device registry integration.""" await help_test_entity_device_info_with_connection( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG, ) async def test_entity_device_info_with_identifier( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT light device registry integration.""" await help_test_entity_device_info_with_identifier( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG, ) async def test_entity_device_info_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry update.""" await help_test_entity_device_info_update( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG, ) async def test_entity_device_info_remove( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry remove.""" await help_test_entity_device_info_remove( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG, ) async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" await help_test_entity_id_update_subscriptions( - hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG ) async def test_entity_id_update_discovery_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT discovery update when entity_id is updated.""" await help_test_entity_id_update_discovery_update( - hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG ) async def test_entity_debug_info_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT debug info.""" await help_test_entity_debug_info_message( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG, light.SERVICE_TURN_ON, @@ -2247,10 +2247,10 @@ async def test_entity_debug_info_message( ], ) async def test_max_mireds( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setting min_mireds and max_mireds.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("light.test") assert state.attributes.get("min_mireds") == 153 @@ -2282,7 +2282,7 @@ async def test_max_mireds( ) async def test_publishing_with_custom_encoding( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, service: str, topic: str, @@ -2300,7 +2300,7 @@ async def test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, domain, config, @@ -2338,7 +2338,7 @@ async def test_reloadable( ) async def test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, topic: str, value: str, attribute: str | None, @@ -2358,7 +2358,7 @@ async def test_encoding_subscribable_topics( ] await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, light.DOMAIN, config, topic, @@ -2372,9 +2372,9 @@ async def test_encoding_subscribable_topics( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_setup_manual_entity_from_yaml( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setup manual configured MQTT entity.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() platform = light.DOMAIN assert hass.states.get(f"{platform}.test") diff --git a/tests/components/mqtt/test_light_template.py b/tests/components/mqtt/test_light_template.py index 166687b8595..3369a5591c9 100644 --- a/tests/components/mqtt/test_light_template.py +++ b/tests/components/mqtt/test_light_template.py @@ -141,12 +141,12 @@ def light_platform_only(): ) async def test_setup_fails( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test that setup fails with missing required configuration items.""" with pytest.raises(AssertionError): - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() assert "Invalid config" in caplog.text @@ -170,10 +170,10 @@ async def test_setup_fails( ], ) async def test_rgb_light( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test RGB light flags brightness support.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -207,10 +207,10 @@ async def test_rgb_light( ], ) async def test_state_change_via_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test state change via topic.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -270,10 +270,10 @@ async def test_state_change_via_topic( ], ) async def test_state_brightness_color_effect_temp_change_via_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test state, bri, color, effect, color temp change.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -382,7 +382,7 @@ async def test_state_brightness_color_effect_temp_change_via_topic( ], ) async def test_sending_mqtt_commands_and_optimistic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the sending of command in optimistic mode.""" fake_state = State( @@ -397,7 +397,7 @@ async def test_sending_mqtt_commands_and_optimistic( ) mock_restore_cache(hass, (fake_state,)) - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_ON @@ -524,10 +524,10 @@ async def test_sending_mqtt_commands_and_optimistic( ], ) async def test_sending_mqtt_commands_non_optimistic_brightness_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the sending of command in optimistic mode.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -633,10 +633,10 @@ async def test_sending_mqtt_commands_non_optimistic_brightness_template( ], ) async def test_effect( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test effect sent over MQTT in optimistic mode.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -687,10 +687,10 @@ async def test_effect( ], ) async def test_flash( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test flash sent over MQTT in optimistic mode.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -738,10 +738,10 @@ async def test_flash( ], ) async def test_transition( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test for transition time being sent when included.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -796,11 +796,11 @@ async def test_transition( ], ) async def test_invalid_values( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test that invalid values are ignored.""" await hass.async_block_till_done() - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("light.test") assert state.state == STATE_UNKNOWN @@ -864,58 +864,58 @@ async def test_invalid_values( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_when_connection_lost( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability after MQTT disconnection.""" await help_test_availability_when_connection_lost( - hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN + hass, mqtt_mock_entry, light.DOMAIN ) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_without_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability without defined availability topic.""" await help_test_availability_without_topic( - hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG ) async def test_default_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by default payload with defined topic.""" await help_test_default_availability_payload( - hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG ) async def test_custom_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by custom payload with defined topic.""" await help_test_custom_availability_payload( - hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG ) async def test_setting_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_via_mqtt_json_message( - hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG ) async def test_setting_blocked_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_blocked_attribute_via_mqtt_json_message( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG, MQTT_LIGHT_ATTRIBUTES_BLOCKED, @@ -923,23 +923,23 @@ async def test_setting_blocked_attribute_via_mqtt_json_message( async def test_setting_attribute_with_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_with_template( - hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG ) async def test_update_with_json_attrs_not_dict( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_not_dict( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, light.DOMAIN, DEFAULT_CONFIG, @@ -948,13 +948,13 @@ async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_bad_json( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_bad_json( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, light.DOMAIN, DEFAULT_CONFIG, @@ -963,13 +963,13 @@ async def test_update_with_json_attrs_bad_json( async def test_discovery_update_attr( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered MQTTAttributes.""" await help_test_discovery_update_attr( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, light.DOMAIN, DEFAULT_CONFIG, @@ -1006,15 +1006,15 @@ async def test_discovery_update_attr( ], ) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one light per unique_id.""" - await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN) + await help_test_unique_id(hass, mqtt_mock_entry, light.DOMAIN) async def test_discovery_removal( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test removal of discovered mqtt_json lights.""" @@ -1025,14 +1025,12 @@ async def test_discovery_removal( ' "command_on_template": "on",' ' "command_off_template": "off"}' ) - await help_test_discovery_removal( - hass, mqtt_mock_entry_no_yaml_config, caplog, light.DOMAIN, data - ) + await help_test_discovery_removal(hass, mqtt_mock_entry, caplog, light.DOMAIN, data) async def test_discovery_update_light( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered light.""" @@ -1053,13 +1051,13 @@ async def test_discovery_update_light( "command_off_template": "off", } await help_test_discovery_update( - hass, mqtt_mock_entry_no_yaml_config, caplog, light.DOMAIN, config1, config2 + hass, mqtt_mock_entry, caplog, light.DOMAIN, config1, config2 ) async def test_discovery_update_unchanged_light( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered light.""" @@ -1076,7 +1074,7 @@ async def test_discovery_update_unchanged_light( ) as discovery_update: await help_test_discovery_update_unchanged( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, light.DOMAIN, data1, @@ -1087,7 +1085,7 @@ async def test_discovery_update_unchanged_light( @pytest.mark.no_fail_on_log_exception async def test_discovery_broken( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test handling of bad discovery message.""" @@ -1101,66 +1099,66 @@ async def test_discovery_broken( ' "command_off_template": "off"}' ) await help_test_discovery_broken( - hass, mqtt_mock_entry_no_yaml_config, caplog, light.DOMAIN, data1, data2 + hass, mqtt_mock_entry, caplog, light.DOMAIN, data1, data2 ) async def test_entity_device_info_with_connection( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT light device registry integration.""" await help_test_entity_device_info_with_connection( - hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_with_identifier( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT light device registry integration.""" await help_test_entity_device_info_with_identifier( - hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry update.""" await help_test_entity_device_info_update( - hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_remove( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry remove.""" await help_test_entity_device_info_remove( - hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG ) async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" await help_test_entity_id_update_subscriptions( - hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG ) async def test_entity_id_update_discovery_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT discovery update when entity_id is updated.""" await help_test_entity_id_update_discovery_update( - hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG ) async def test_entity_debug_info_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT debug info.""" config = { @@ -1177,7 +1175,7 @@ async def test_entity_debug_info_message( } await help_test_entity_debug_info_message( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, light.DOMAIN, config, light.SERVICE_TURN_ON, @@ -1203,10 +1201,10 @@ async def test_entity_debug_info_message( ], ) async def test_max_mireds( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setting min_mireds and max_mireds.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("light.test") assert state.attributes.get("min_mireds") == 153 @@ -1238,7 +1236,7 @@ async def test_max_mireds( ) async def test_publishing_with_custom_encoding( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, service: str, topic: str, @@ -1256,7 +1254,7 @@ async def test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, domain, config, @@ -1288,7 +1286,7 @@ async def test_reloadable( ) async def test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, topic: str, value: str, attribute: str | None, @@ -1300,7 +1298,7 @@ async def test_encoding_subscribable_topics( config["state_template"] = "{{ value }}" await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, light.DOMAIN, config, topic, @@ -1313,21 +1311,21 @@ async def test_encoding_subscribable_topics( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_setup_manual_entity_from_yaml( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setup manual configured MQTT entity.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() platform = light.DOMAIN assert hass.states.get(f"{platform}.test") async def test_unload_entry( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test unloading the config entry.""" domain = light.DOMAIN config = DEFAULT_CONFIG await help_test_unload_config_entry_with_platform( - hass, mqtt_mock_entry_no_yaml_config, domain, config + hass, mqtt_mock_entry, domain, config ) diff --git a/tests/components/mqtt/test_lock.py b/tests/components/mqtt/test_lock.py index f13de403535..3c878a85f9e 100644 --- a/tests/components/mqtt/test_lock.py +++ b/tests/components/mqtt/test_lock.py @@ -98,12 +98,12 @@ def lock_platform_only(): ) async def test_controlling_state_via_topic( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, payload: str, lock_state: str, ) -> None: """Test the controlling state via topic.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("lock.test") assert state.state is STATE_UNLOCKED @@ -128,12 +128,12 @@ async def test_controlling_state_via_topic( ) async def test_controlling_non_default_state_via_topic( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, payload: str, lock_state: str, ) -> None: """Test the controlling state via topic.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("lock.test") assert state.state is STATE_UNLOCKED @@ -188,12 +188,12 @@ async def test_controlling_non_default_state_via_topic( ) async def test_controlling_state_via_topic_and_json_message( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, payload: str, lock_state: str, ) -> None: """Test the controlling state via topic and JSON message.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("lock.test") assert state.state is STATE_UNLOCKED @@ -247,12 +247,12 @@ async def test_controlling_state_via_topic_and_json_message( ) async def test_controlling_non_default_state_via_topic_and_json_message( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, payload: str, lock_state: str, ) -> None: """Test the controlling state via topic and JSON message.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("lock.test") assert state.state is STATE_UNLOCKED @@ -281,10 +281,10 @@ async def test_controlling_non_default_state_via_topic_and_json_message( ], ) async def test_sending_mqtt_commands_and_optimistic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test optimistic mode without state topic.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("lock.test") assert state.state is STATE_UNLOCKED @@ -332,10 +332,10 @@ async def test_sending_mqtt_commands_and_optimistic( ], ) async def test_sending_mqtt_commands_with_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test sending commands with template.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("lock.test") assert state.state is STATE_UNLOCKED @@ -392,10 +392,10 @@ async def test_sending_mqtt_commands_with_template( ], ) async def test_sending_mqtt_commands_and_explicit_optimistic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test optimistic mode without state topic.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("lock.test") assert state.state is STATE_UNLOCKED @@ -441,10 +441,10 @@ async def test_sending_mqtt_commands_and_explicit_optimistic( ], ) async def test_sending_mqtt_commands_support_open_and_optimistic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test open function of the lock without state topic.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("lock.test") assert state.state is STATE_UNLOCKED @@ -503,10 +503,10 @@ async def test_sending_mqtt_commands_support_open_and_optimistic( ], ) async def test_sending_mqtt_commands_support_open_and_explicit_optimistic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test open function of the lock without state topic.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("lock.test") assert state.state is STATE_UNLOCKED @@ -567,10 +567,10 @@ async def test_sending_mqtt_commands_support_open_and_explicit_optimistic( ], ) async def test_sending_mqtt_commands_pessimistic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test function of the lock with state topics.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("lock.test") assert state.state is STATE_UNLOCKED @@ -652,58 +652,58 @@ async def test_sending_mqtt_commands_pessimistic( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_when_connection_lost( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability after MQTT disconnection.""" await help_test_availability_when_connection_lost( - hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN + hass, mqtt_mock_entry, lock.DOMAIN ) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_without_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability without defined availability topic.""" await help_test_availability_without_topic( - hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, lock.DOMAIN, DEFAULT_CONFIG ) async def test_default_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by default payload with defined topic.""" await help_test_default_availability_payload( - hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, lock.DOMAIN, DEFAULT_CONFIG ) async def test_custom_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by custom payload with defined topic.""" await help_test_custom_availability_payload( - hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, lock.DOMAIN, DEFAULT_CONFIG ) async def test_setting_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_via_mqtt_json_message( - hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, lock.DOMAIN, DEFAULT_CONFIG ) async def test_setting_blocked_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_blocked_attribute_via_mqtt_json_message( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, lock.DOMAIN, DEFAULT_CONFIG, MQTT_LOCK_ATTRIBUTES_BLOCKED, @@ -711,23 +711,23 @@ async def test_setting_blocked_attribute_via_mqtt_json_message( async def test_setting_attribute_with_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_with_template( - hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, lock.DOMAIN, DEFAULT_CONFIG ) async def test_update_with_json_attrs_not_dict( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_not_dict( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, lock.DOMAIN, DEFAULT_CONFIG, @@ -736,13 +736,13 @@ async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_bad_json( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_bad_json( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, lock.DOMAIN, DEFAULT_CONFIG, @@ -751,12 +751,12 @@ async def test_update_with_json_attrs_bad_json( async def test_discovery_update_attr( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered MQTTAttributes.""" await help_test_discovery_update_attr( - hass, mqtt_mock_entry_no_yaml_config, caplog, lock.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, caplog, lock.DOMAIN, DEFAULT_CONFIG ) @@ -784,27 +784,25 @@ async def test_discovery_update_attr( ], ) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one lock per unique_id.""" - await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN) + await help_test_unique_id(hass, mqtt_mock_entry, lock.DOMAIN) async def test_discovery_removal_lock( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test removal of discovered lock.""" data = '{ "name": "test",' ' "command_topic": "test_topic" }' - await help_test_discovery_removal( - hass, mqtt_mock_entry_no_yaml_config, caplog, lock.DOMAIN, data - ) + await help_test_discovery_removal(hass, mqtt_mock_entry, caplog, lock.DOMAIN, data) async def test_discovery_update_lock( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered lock.""" @@ -821,13 +819,13 @@ async def test_discovery_update_lock( "availability_topic": "availability_topic2", } await help_test_discovery_update( - hass, mqtt_mock_entry_no_yaml_config, caplog, lock.DOMAIN, config1, config2 + hass, mqtt_mock_entry, caplog, lock.DOMAIN, config1, config2 ) async def test_discovery_update_unchanged_lock( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered lock.""" @@ -841,7 +839,7 @@ async def test_discovery_update_unchanged_lock( ) as discovery_update: await help_test_discovery_update_unchanged( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, lock.DOMAIN, data1, @@ -852,78 +850,78 @@ async def test_discovery_update_unchanged_lock( @pytest.mark.no_fail_on_log_exception async def test_discovery_broken( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test handling of bad discovery message.""" data1 = '{ "name": "Beer" }' data2 = '{ "name": "Milk",' ' "command_topic": "test_topic" }' await help_test_discovery_broken( - hass, mqtt_mock_entry_no_yaml_config, caplog, lock.DOMAIN, data1, data2 + hass, mqtt_mock_entry, caplog, lock.DOMAIN, data1, data2 ) async def test_entity_device_info_with_connection( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT lock device registry integration.""" await help_test_entity_device_info_with_connection( - hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, lock.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_with_identifier( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT lock device registry integration.""" await help_test_entity_device_info_with_identifier( - hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, lock.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry update.""" await help_test_entity_device_info_update( - hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, lock.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_remove( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry remove.""" await help_test_entity_device_info_remove( - hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, lock.DOMAIN, DEFAULT_CONFIG ) async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" await help_test_entity_id_update_subscriptions( - hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, lock.DOMAIN, DEFAULT_CONFIG ) async def test_entity_id_update_discovery_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT discovery update when entity_id is updated.""" await help_test_entity_id_update_discovery_update( - hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, lock.DOMAIN, DEFAULT_CONFIG ) async def test_entity_debug_info_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT debug info.""" await help_test_entity_debug_info_message( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, lock.DOMAIN, DEFAULT_CONFIG, SERVICE_LOCK, @@ -945,7 +943,7 @@ async def test_entity_debug_info_message( ) async def test_publishing_with_custom_encoding( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, service: str, topic: str, @@ -959,7 +957,7 @@ async def test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, domain, config, @@ -989,7 +987,7 @@ async def test_reloadable( ) async def test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, topic: str, value: str, attribute: str | None, @@ -998,7 +996,7 @@ async def test_encoding_subscribable_topics( """Test handling of incoming encoded payload.""" await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, lock.DOMAIN, DEFAULT_CONFIG[mqtt.DOMAIN][lock.DOMAIN], topic, @@ -1010,21 +1008,21 @@ async def test_encoding_subscribable_topics( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_setup_manual_entity_from_yaml( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setup manual configured MQTT entity.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() platform = lock.DOMAIN assert hass.states.get(f"{platform}.test") async def test_unload_entry( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test unloading the config entry.""" domain = lock.DOMAIN config = DEFAULT_CONFIG await help_test_unload_config_entry_with_platform( - hass, mqtt_mock_entry_no_yaml_config, domain, config + hass, mqtt_mock_entry, domain, config ) diff --git a/tests/components/mqtt/test_mixins.py b/tests/components/mqtt/test_mixins.py index 18d59f98675..c7285f0fa5f 100644 --- a/tests/components/mqtt/test_mixins.py +++ b/tests/components/mqtt/test_mixins.py @@ -33,14 +33,14 @@ from tests.typing import MqttMockHAClientGenerator @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SENSOR]) async def test_availability_with_shared_state_topic( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test the state is not changed twice. When an entity with a shared state_topic and availability_topic becomes available The state should only change once. """ - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() events = [] diff --git a/tests/components/mqtt/test_number.py b/tests/components/mqtt/test_number.py index bd28d75ac9a..1c47793e342 100644 --- a/tests/components/mqtt/test_number.py +++ b/tests/components/mqtt/test_number.py @@ -93,10 +93,10 @@ def number_platform_only(): ], ) async def test_run_number_setup( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test that it fetches the given payload.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, "test/state_number", "10") @@ -142,11 +142,11 @@ async def test_run_number_setup( ], ) async def test_value_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test that it fetches the given payload with a template.""" topic = "test/state_number" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, topic, '{"val":10}') @@ -186,7 +186,7 @@ async def test_value_template( ], ) async def test_restore_native_value( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test that the stored native_value is restored.""" @@ -201,7 +201,7 @@ async def test_restore_native_value( mock_restore_cache_with_extra_data( hass, ((State("number.test_number", "abc"), RESTORE_DATA),) ) - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("number.test_number") assert state.state == "37.8" @@ -222,7 +222,7 @@ async def test_restore_native_value( ], ) async def test_run_number_service_optimistic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test that set_value service works in optimistic mode.""" topic = "test/number" @@ -239,7 +239,7 @@ async def test_run_number_service_optimistic( hass, ((State("number.test_number", "abc"), RESTORE_DATA),) ) - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("number.test_number") assert state.state == "3" @@ -300,7 +300,7 @@ async def test_run_number_service_optimistic( ], ) async def test_run_number_service_optimistic_with_command_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test that set_value service works in optimistic mode and with a command_template.""" topic = "test/number" @@ -316,7 +316,7 @@ async def test_run_number_service_optimistic_with_command_template( mock_restore_cache_with_extra_data( hass, ((State("number.test_number", "abc"), RESTORE_DATA),) ) - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("number.test_number") assert state.state == "3" @@ -379,13 +379,13 @@ async def test_run_number_service_optimistic_with_command_template( ], ) async def test_run_number_service( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test that set_value service works in non optimistic mode.""" cmd_topic = "test/number/set" state_topic = "test/number" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() async_fire_mqtt_message(hass, state_topic, "32") state = hass.states.get("number.test_number") @@ -418,13 +418,13 @@ async def test_run_number_service( ], ) async def test_run_number_service_with_command_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test that set_value service works in non optimistic mode and with a command_template.""" cmd_topic = "test/number/set" state_topic = "test/number" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() async_fire_mqtt_message(hass, state_topic, "32") state = hass.states.get("number.test_number") @@ -445,58 +445,58 @@ async def test_run_number_service_with_command_template( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_when_connection_lost( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability after MQTT disconnection.""" await help_test_availability_when_connection_lost( - hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN + hass, mqtt_mock_entry, number.DOMAIN ) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_without_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability without defined availability topic.""" await help_test_availability_without_topic( - hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, number.DOMAIN, DEFAULT_CONFIG ) async def test_default_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by default payload with defined topic.""" await help_test_default_availability_payload( - hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, number.DOMAIN, DEFAULT_CONFIG ) async def test_custom_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by custom payload with defined topic.""" await help_test_custom_availability_payload( - hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, number.DOMAIN, DEFAULT_CONFIG ) async def test_setting_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_via_mqtt_json_message( - hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, number.DOMAIN, DEFAULT_CONFIG ) async def test_setting_blocked_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_blocked_attribute_via_mqtt_json_message( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, number.DOMAIN, DEFAULT_CONFIG, MQTT_NUMBER_ATTRIBUTES_BLOCKED, @@ -504,23 +504,23 @@ async def test_setting_blocked_attribute_via_mqtt_json_message( async def test_setting_attribute_with_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_with_template( - hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, number.DOMAIN, DEFAULT_CONFIG ) async def test_update_with_json_attrs_not_dict( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_not_dict( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, number.DOMAIN, DEFAULT_CONFIG, @@ -529,13 +529,13 @@ async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_bad_json( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_bad_json( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, number.DOMAIN, DEFAULT_CONFIG, @@ -544,13 +544,13 @@ async def test_update_with_json_attrs_bad_json( async def test_discovery_update_attr( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered MQTTAttributes.""" await help_test_discovery_update_attr( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, number.DOMAIN, DEFAULT_CONFIG, @@ -581,27 +581,27 @@ async def test_discovery_update_attr( ], ) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one number per unique_id.""" - await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN) + await help_test_unique_id(hass, mqtt_mock_entry, number.DOMAIN) async def test_discovery_removal_number( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test removal of discovered number.""" data = json.dumps(DEFAULT_CONFIG[mqtt.DOMAIN][number.DOMAIN]) await help_test_discovery_removal( - hass, mqtt_mock_entry_no_yaml_config, caplog, number.DOMAIN, data + hass, mqtt_mock_entry, caplog, number.DOMAIN, data ) async def test_discovery_update_number( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered number.""" @@ -617,13 +617,13 @@ async def test_discovery_update_number( } await help_test_discovery_update( - hass, mqtt_mock_entry_no_yaml_config, caplog, number.DOMAIN, config1, config2 + hass, mqtt_mock_entry, caplog, number.DOMAIN, config1, config2 ) async def test_discovery_update_unchanged_number( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered number.""" @@ -635,7 +635,7 @@ async def test_discovery_update_unchanged_number( ) as discovery_update: await help_test_discovery_update_unchanged( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, number.DOMAIN, data1, @@ -646,7 +646,7 @@ async def test_discovery_update_unchanged_number( @pytest.mark.no_fail_on_log_exception async def test_discovery_broken( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test handling of bad discovery message.""" @@ -656,71 +656,71 @@ async def test_discovery_broken( ) await help_test_discovery_broken( - hass, mqtt_mock_entry_no_yaml_config, caplog, number.DOMAIN, data1, data2 + hass, mqtt_mock_entry, caplog, number.DOMAIN, data1, data2 ) async def test_entity_device_info_with_connection( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT number device registry integration.""" await help_test_entity_device_info_with_connection( - hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, number.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_with_identifier( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT number device registry integration.""" await help_test_entity_device_info_with_identifier( - hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, number.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry update.""" await help_test_entity_device_info_update( - hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, number.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_remove( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry remove.""" await help_test_entity_device_info_remove( - hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, number.DOMAIN, DEFAULT_CONFIG ) async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" await help_test_entity_id_update_subscriptions( - hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, number.DOMAIN, DEFAULT_CONFIG ) async def test_entity_id_update_discovery_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT discovery update when entity_id is updated.""" await help_test_entity_id_update_discovery_update( - hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, number.DOMAIN, DEFAULT_CONFIG ) async def test_entity_debug_info_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT debug info.""" await help_test_entity_debug_info_message( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, number.DOMAIN, DEFAULT_CONFIG, SERVICE_SET_VALUE, @@ -748,10 +748,10 @@ async def test_entity_debug_info_message( ], ) async def test_min_max_step_attributes( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test min/max/step attributes.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("number.test_number") assert state.attributes.get(ATTR_MIN) == 5 @@ -777,12 +777,12 @@ async def test_min_max_step_attributes( ) async def test_invalid_min_max_attributes( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test invalid min/max attributes.""" with pytest.raises(AssertionError): - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() assert f"'{CONF_MAX}' must be > '{CONF_MIN}'" in caplog.text @@ -801,10 +801,10 @@ async def test_invalid_min_max_attributes( ], ) async def test_default_mode( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test default mode.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("number.test_number") assert state.attributes.get(ATTR_MODE) == "auto" @@ -856,11 +856,11 @@ async def test_default_mode( ) async def test_mode( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, mode, ) -> None: """Test mode.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("number.test_number") assert state.attributes.get(ATTR_MODE) == mode @@ -899,15 +899,15 @@ async def test_mode( ) async def test_invalid_mode( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, valid: bool, ) -> None: """Test invalid mode.""" if valid: - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() return with pytest.raises(AssertionError): - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() @pytest.mark.parametrize( @@ -927,12 +927,12 @@ async def test_invalid_mode( async def test_mqtt_payload_not_a_number_warning( hass: HomeAssistant, caplog: pytest.LogCaptureFixture, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test warning for MQTT payload which is not a number.""" topic = "test/state_number" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, topic, "not_a_number") @@ -960,13 +960,13 @@ async def test_mqtt_payload_not_a_number_warning( async def test_mqtt_payload_out_of_range_error( hass: HomeAssistant, caplog: pytest.LogCaptureFixture, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test error when MQTT payload is out of min/max range.""" topic = "test/state_number" await hass.async_block_till_done() - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, topic, "115.5") @@ -991,7 +991,7 @@ async def test_mqtt_payload_out_of_range_error( ) async def test_publishing_with_custom_encoding( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, service: str, topic: str, @@ -1005,7 +1005,7 @@ async def test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, domain, config, @@ -1036,7 +1036,7 @@ async def test_reloadable( ) async def test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, topic: str, value: str, attribute: str | None, @@ -1045,7 +1045,7 @@ async def test_encoding_subscribable_topics( """Test handling of incoming encoded payload.""" await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, number.DOMAIN, DEFAULT_CONFIG[mqtt.DOMAIN][number.DOMAIN], topic, @@ -1057,21 +1057,21 @@ async def test_encoding_subscribable_topics( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_setup_manual_entity_from_yaml( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setup manual configured MQTT entity.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() platform = number.DOMAIN assert hass.states.get(f"{platform}.test") async def test_unload_entry( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test unloading the config entry.""" domain = number.DOMAIN config = DEFAULT_CONFIG await help_test_unload_config_entry_with_platform( - hass, mqtt_mock_entry_no_yaml_config, domain, config + hass, mqtt_mock_entry, domain, config ) diff --git a/tests/components/mqtt/test_scene.py b/tests/components/mqtt/test_scene.py index 56350c90c0d..9c4b5b53be9 100644 --- a/tests/components/mqtt/test_scene.py +++ b/tests/components/mqtt/test_scene.py @@ -58,13 +58,13 @@ def scene_platform_only(): ], ) async def test_sending_mqtt_commands( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the sending MQTT commands.""" fake_state = State("scene.test", STATE_UNKNOWN) mock_restore_cache(hass, (fake_state,)) - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("scene.test") assert state.state == STATE_UNKNOWN @@ -79,26 +79,26 @@ async def test_sending_mqtt_commands( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_when_connection_lost( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability after MQTT disconnection.""" await help_test_availability_when_connection_lost( - hass, mqtt_mock_entry_no_yaml_config, scene.DOMAIN + hass, mqtt_mock_entry, scene.DOMAIN ) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_without_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability without defined availability topic.""" await help_test_availability_without_topic( - hass, mqtt_mock_entry_no_yaml_config, scene.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, scene.DOMAIN, DEFAULT_CONFIG ) async def test_default_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by default payload with defined topic.""" config = { @@ -112,7 +112,7 @@ async def test_default_availability_payload( } await help_test_default_availability_payload( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, scene.DOMAIN, config, True, @@ -122,7 +122,7 @@ async def test_default_availability_payload( async def test_custom_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by custom payload with defined topic.""" config = { @@ -137,7 +137,7 @@ async def test_custom_availability_payload( await help_test_custom_availability_payload( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, scene.DOMAIN, config, True, @@ -168,27 +168,25 @@ async def test_custom_availability_payload( ], ) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one scene per unique_id.""" - await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, scene.DOMAIN) + await help_test_unique_id(hass, mqtt_mock_entry, scene.DOMAIN) async def test_discovery_removal_scene( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test removal of discovered scene.""" data = '{ "name": "test",' ' "command_topic": "test_topic" }' - await help_test_discovery_removal( - hass, mqtt_mock_entry_no_yaml_config, caplog, scene.DOMAIN, data - ) + await help_test_discovery_removal(hass, mqtt_mock_entry, caplog, scene.DOMAIN, data) async def test_discovery_update_payload( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered scene.""" @@ -201,7 +199,7 @@ async def test_discovery_update_payload( await help_test_discovery_update( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, scene.DOMAIN, config1, @@ -211,7 +209,7 @@ async def test_discovery_update_payload( async def test_discovery_update_unchanged_scene( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered scene.""" @@ -221,7 +219,7 @@ async def test_discovery_update_unchanged_scene( ) as discovery_update: await help_test_discovery_update_unchanged( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, scene.DOMAIN, data1, @@ -232,14 +230,14 @@ async def test_discovery_update_unchanged_scene( @pytest.mark.no_fail_on_log_exception async def test_discovery_broken( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test handling of bad discovery message.""" data1 = '{ "name": "Beer" }' data2 = '{ "name": "Milk",' ' "command_topic": "test_topic" }' await help_test_discovery_broken( - hass, mqtt_mock_entry_no_yaml_config, caplog, scene.DOMAIN, data1, data2 + hass, mqtt_mock_entry, caplog, scene.DOMAIN, data1, data2 ) @@ -255,21 +253,21 @@ async def test_reloadable( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_setup_manual_entity_from_yaml( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setup manual configured MQTT entity.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() platform = scene.DOMAIN assert hass.states.get(f"{platform}.test") async def test_unload_entry( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test unloading the config entry.""" domain = scene.DOMAIN config = DEFAULT_CONFIG await help_test_unload_config_entry_with_platform( - hass, mqtt_mock_entry_no_yaml_config, domain, config + hass, mqtt_mock_entry, domain, config ) diff --git a/tests/components/mqtt/test_select.py b/tests/components/mqtt/test_select.py index bbda9c88deb..583e65bc61c 100644 --- a/tests/components/mqtt/test_select.py +++ b/tests/components/mqtt/test_select.py @@ -99,11 +99,11 @@ def _test_run_select_setup_params( ) async def test_run_select_setup( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, topic: str, ) -> None: """Test that it fetches the given payload.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, topic, "milk") @@ -137,10 +137,10 @@ async def test_run_select_setup( ], ) async def test_value_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test that it fetches the given payload with a template.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, "test/select_stat", '{"val":"milk"}') @@ -179,13 +179,13 @@ async def test_value_template( ], ) async def test_run_select_service_optimistic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test that set_value service works in optimistic mode.""" fake_state = State("select.test_select", "milk") mock_restore_cache(hass, (fake_state,)) - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("select.test_select") assert state.state == "milk" @@ -220,13 +220,13 @@ async def test_run_select_service_optimistic( ], ) async def test_run_select_service_optimistic_with_command_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test that set_value service works in optimistic mode and with a command_template.""" fake_state = State("select.test_select", "milk") mock_restore_cache(hass, (fake_state,)) - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("select.test_select") assert state.state == "milk" @@ -263,13 +263,13 @@ async def test_run_select_service_optimistic_with_command_template( ], ) async def test_run_select_service( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test that set_value service works in non optimistic mode.""" cmd_topic = "test/select/set" state_topic = "test/select" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() async_fire_mqtt_message(hass, state_topic, "beer") state = hass.states.get("select.test_select") @@ -303,13 +303,13 @@ async def test_run_select_service( ], ) async def test_run_select_service_with_command_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test that set_value service works in non optimistic mode and with a command_template.""" cmd_topic = "test/select/set" state_topic = "test/select" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() async_fire_mqtt_message(hass, state_topic, "beer") state = hass.states.get("select.test_select") @@ -328,58 +328,58 @@ async def test_run_select_service_with_command_template( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_when_connection_lost( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability after MQTT disconnection.""" await help_test_availability_when_connection_lost( - hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN + hass, mqtt_mock_entry, select.DOMAIN ) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_without_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability without defined availability topic.""" await help_test_availability_without_topic( - hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, select.DOMAIN, DEFAULT_CONFIG ) async def test_default_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by default payload with defined topic.""" await help_test_default_availability_payload( - hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, select.DOMAIN, DEFAULT_CONFIG ) async def test_custom_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by custom payload with defined topic.""" await help_test_custom_availability_payload( - hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, select.DOMAIN, DEFAULT_CONFIG ) async def test_setting_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_via_mqtt_json_message( - hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, select.DOMAIN, DEFAULT_CONFIG ) async def test_setting_blocked_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_blocked_attribute_via_mqtt_json_message( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, select.DOMAIN, DEFAULT_CONFIG, MQTT_SELECT_ATTRIBUTES_BLOCKED, @@ -387,23 +387,23 @@ async def test_setting_blocked_attribute_via_mqtt_json_message( async def test_setting_attribute_with_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_with_template( - hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, select.DOMAIN, DEFAULT_CONFIG ) async def test_update_with_json_attrs_not_dict( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_not_dict( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, select.DOMAIN, DEFAULT_CONFIG, @@ -412,13 +412,13 @@ async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_bad_json( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_bad_json( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, select.DOMAIN, DEFAULT_CONFIG, @@ -427,13 +427,13 @@ async def test_update_with_json_attrs_bad_json( async def test_discovery_update_attr( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered MQTTAttributes.""" await help_test_discovery_update_attr( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, select.DOMAIN, DEFAULT_CONFIG, @@ -466,27 +466,27 @@ async def test_discovery_update_attr( ], ) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one select per unique_id.""" - await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN) + await help_test_unique_id(hass, mqtt_mock_entry, select.DOMAIN) async def test_discovery_removal_select( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test removal of discovered select.""" data = json.dumps(DEFAULT_CONFIG[mqtt.DOMAIN][select.DOMAIN]) await help_test_discovery_removal( - hass, mqtt_mock_entry_no_yaml_config, caplog, select.DOMAIN, data + hass, mqtt_mock_entry, caplog, select.DOMAIN, data ) async def test_discovery_update_select( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered select.""" @@ -504,13 +504,13 @@ async def test_discovery_update_select( } await help_test_discovery_update( - hass, mqtt_mock_entry_no_yaml_config, caplog, select.DOMAIN, config1, config2 + hass, mqtt_mock_entry, caplog, select.DOMAIN, config1, config2 ) async def test_discovery_update_unchanged_select( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered select.""" @@ -520,7 +520,7 @@ async def test_discovery_update_unchanged_select( ) as discovery_update: await help_test_discovery_update_unchanged( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, select.DOMAIN, data1, @@ -531,7 +531,7 @@ async def test_discovery_update_unchanged_select( @pytest.mark.no_fail_on_log_exception async def test_discovery_broken( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test handling of bad discovery message.""" @@ -539,71 +539,71 @@ async def test_discovery_broken( data2 = '{ "name": "Milk", "state_topic": "test-topic", "command_topic": "test-topic", "options": ["milk", "beer"]}' await help_test_discovery_broken( - hass, mqtt_mock_entry_no_yaml_config, caplog, select.DOMAIN, data1, data2 + hass, mqtt_mock_entry, caplog, select.DOMAIN, data1, data2 ) async def test_entity_device_info_with_connection( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT select device registry integration.""" await help_test_entity_device_info_with_connection( - hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, select.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_with_identifier( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT select device registry integration.""" await help_test_entity_device_info_with_identifier( - hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, select.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry update.""" await help_test_entity_device_info_update( - hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, select.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_remove( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry remove.""" await help_test_entity_device_info_remove( - hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, select.DOMAIN, DEFAULT_CONFIG ) async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" await help_test_entity_id_update_subscriptions( - hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, select.DOMAIN, DEFAULT_CONFIG ) async def test_entity_id_update_discovery_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT discovery update when entity_id is updated.""" await help_test_entity_id_update_discovery_update( - hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, select.DOMAIN, DEFAULT_CONFIG ) async def test_entity_debug_info_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT debug info.""" await help_test_entity_debug_info_message( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, select.DOMAIN, DEFAULT_CONFIG, select.SERVICE_SELECT_OPTION, @@ -638,11 +638,11 @@ def _test_options_attributes_options_config( ) async def test_options_attributes( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, options: list[str], ) -> None: """Test options attribute.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("select.test_select") assert state.attributes.get(ATTR_OPTIONS) == options @@ -666,10 +666,10 @@ async def test_options_attributes( async def test_mqtt_payload_not_an_option_warning( hass: HomeAssistant, caplog: pytest.LogCaptureFixture, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test warning for MQTT payload which is not a valid option.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, "test/select_stat", "öl") @@ -695,7 +695,7 @@ async def test_mqtt_payload_not_an_option_warning( ) async def test_publishing_with_custom_encoding( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, service: str, topic: str, @@ -710,7 +710,7 @@ async def test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, domain, config, @@ -741,7 +741,7 @@ async def test_reloadable( ) async def test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, topic: str, value: str, attribute: str | None, @@ -752,7 +752,7 @@ async def test_encoding_subscribable_topics( config["options"] = ["milk", "beer"] await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, select.DOMAIN, config, topic, @@ -764,31 +764,31 @@ async def test_encoding_subscribable_topics( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_setup_manual_entity_from_yaml( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setup manual configured MQTT entity.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() platform = select.DOMAIN assert hass.states.get(f"{platform}.test") async def test_unload_entry( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test unloading the config entry.""" domain = select.DOMAIN config = DEFAULT_CONFIG await help_test_unload_config_entry_with_platform( - hass, mqtt_mock_entry_no_yaml_config, domain, config + hass, mqtt_mock_entry, domain, config ) async def test_persistent_state_after_reconfig( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test of the state is persistent after reconfiguring the select options.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() discovery_data = '{ "name": "Milk", "state_topic": "test-topic", "command_topic": "test-topic", "options": ["milk", "beer"]}' await help_test_discovery_setup(hass, SELECT_DOMAIN, discovery_data, "milk") diff --git a/tests/components/mqtt/test_sensor.py b/tests/components/mqtt/test_sensor.py index 01c897a9d86..67979e69e1d 100644 --- a/tests/components/mqtt/test_sensor.py +++ b/tests/components/mqtt/test_sensor.py @@ -99,10 +99,10 @@ def sensor_platform_only(): ], ) async def test_setting_sensor_value_via_mqtt_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of the value via MQTT.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, "test-topic", "100.22") state = hass.states.get("sensor.test") @@ -217,7 +217,7 @@ async def test_setting_sensor_value_via_mqtt_message( ) async def test_setting_sensor_native_value_handling_via_mqtt_message( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, device_class: sensor.SensorDeviceClass | None, native_value: str, @@ -225,7 +225,7 @@ async def test_setting_sensor_native_value_handling_via_mqtt_message( log: bool, ) -> None: """Test the setting of the value via MQTT.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, "test-topic", native_value) state = hass.states.get("sensor.test") @@ -253,11 +253,11 @@ async def test_setting_sensor_native_value_handling_via_mqtt_message( ) async def test_setting_numeric_sensor_native_value_handling_via_mqtt_message( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test the setting of a numeric sensor value via MQTT.""" await hass.async_block_till_done() - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() # float value async_fire_mqtt_message(hass, "test-topic", '{ "power": 45.3, "current": 5.24 }') @@ -308,10 +308,10 @@ async def test_setting_numeric_sensor_native_value_handling_via_mqtt_message( ], ) async def test_setting_sensor_value_expires_availability_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the expiration of the value.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("sensor.test") assert state.state == STATE_UNAVAILABLE @@ -342,10 +342,10 @@ async def test_setting_sensor_value_expires_availability_topic( ], ) async def test_setting_sensor_value_expires( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the expiration of the value.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() # State should be unavailable since expire_after is defined and > 0 state = hass.states.get("sensor.test") @@ -420,10 +420,10 @@ async def expires_helper(hass: HomeAssistant) -> None: ], ) async def test_setting_sensor_value_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of the value via MQTT with JSON payload.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, "test-topic", '{ "val": "100" }') state = hass.states.get("sensor.test") @@ -452,10 +452,10 @@ async def test_setting_sensor_value_via_mqtt_json_message( ], ) async def test_setting_sensor_value_via_mqtt_json_message_and_default_current_state( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of the value via MQTT with fall back to current state.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message( hass, "test-topic", '{ "val": "valcontent", "par": "parcontent" }' @@ -488,11 +488,11 @@ async def test_setting_sensor_value_via_mqtt_json_message_and_default_current_st ) async def test_setting_sensor_last_reset_via_mqtt_message( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test the setting of the last_reset property via MQTT.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, "last-reset-topic", "2020-01-02 08:11:00") state = hass.states.get("sensor.test") @@ -525,10 +525,10 @@ async def test_setting_sensor_bad_last_reset_via_mqtt_message( hass: HomeAssistant, caplog: pytest.LogCaptureFixture, datestring, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test the setting of the last_reset property via MQTT.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, "last-reset-topic", datestring) state = hass.states.get("sensor.test") @@ -553,10 +553,10 @@ async def test_setting_sensor_bad_last_reset_via_mqtt_message( ], ) async def test_setting_sensor_empty_last_reset_via_mqtt_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of the last_reset property via MQTT.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, "last-reset-topic", "") state = hass.states.get("sensor.test") @@ -581,10 +581,10 @@ async def test_setting_sensor_empty_last_reset_via_mqtt_message( ], ) async def test_setting_sensor_last_reset_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of the value via MQTT with JSON payload.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message( hass, "last-reset-topic", '{ "last_reset": "2020-01-02 08:11:00" }' @@ -625,12 +625,12 @@ async def test_setting_sensor_last_reset_via_mqtt_json_message( ) async def test_setting_sensor_last_reset_via_mqtt_json_message_2( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test the setting of the value via MQTT with JSON payload.""" await hass.async_block_till_done() - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message( hass, @@ -662,10 +662,10 @@ async def test_setting_sensor_last_reset_via_mqtt_json_message_2( ], ) async def test_force_update_disabled( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test force update option.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() events: list[Event] = [] @@ -700,10 +700,10 @@ async def test_force_update_disabled( ], ) async def test_force_update_enabled( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test force update option.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() events: list[Event] = [] @@ -724,57 +724,57 @@ async def test_force_update_enabled( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_when_connection_lost( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability after MQTT disconnection.""" await help_test_availability_when_connection_lost( - hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN + hass, mqtt_mock_entry, sensor.DOMAIN ) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_without_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability without defined availability topic.""" await help_test_availability_without_topic( - hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG ) async def test_default_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by default payload with defined topic.""" await help_test_default_availability_payload( - hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG ) async def test_default_availability_list_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by default payload with defined topic.""" await help_test_default_availability_list_payload( - hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG ) async def test_default_availability_list_payload_all( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by default payload with defined topic.""" await help_test_default_availability_list_payload_all( - hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG ) async def test_default_availability_list_payload_any( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by default payload with defined topic.""" await help_test_default_availability_list_payload_any( - hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG ) @@ -791,20 +791,20 @@ async def test_default_availability_list_single( async def test_custom_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by custom payload with defined topic.""" await help_test_custom_availability_payload( - hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG ) async def test_discovery_update_availability( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability discovery update.""" await help_test_discovery_update_availability( - hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG ) @@ -824,12 +824,12 @@ async def test_discovery_update_availability( ) async def test_invalid_device_class( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test device_class option with invalid value.""" with pytest.raises(AssertionError): - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() assert ( "Invalid config for [mqtt]: expected SensorDeviceClass or one of" in caplog.text ) @@ -858,10 +858,10 @@ async def test_invalid_device_class( ], ) async def test_valid_device_class( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device_class option with valid values.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("sensor.test_1") assert state.attributes["device_class"] == "temperature" @@ -887,12 +887,12 @@ async def test_valid_device_class( ) async def test_invalid_state_class( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test state_class option with invalid value.""" with pytest.raises(AssertionError): - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() assert ( "Invalid config for [mqtt]: expected SensorStateClass or one of" in caplog.text ) @@ -921,10 +921,10 @@ async def test_invalid_state_class( ], ) async def test_valid_state_class( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test state_class option with valid values.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("sensor.test_1") assert state.attributes["state_class"] == "measurement" @@ -935,21 +935,21 @@ async def test_valid_state_class( async def test_setting_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_via_mqtt_json_message( - hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG ) async def test_setting_blocked_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_blocked_attribute_via_mqtt_json_message( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG, MQTT_SENSOR_ATTRIBUTES_BLOCKED, @@ -957,23 +957,23 @@ async def test_setting_blocked_attribute_via_mqtt_json_message( async def test_setting_attribute_with_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_with_template( - hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG ) async def test_update_with_json_attrs_not_dict( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_not_dict( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, sensor.DOMAIN, DEFAULT_CONFIG, @@ -982,13 +982,13 @@ async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_bad_json( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_bad_json( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, sensor.DOMAIN, DEFAULT_CONFIG, @@ -997,13 +997,13 @@ async def test_update_with_json_attrs_bad_json( async def test_discovery_update_attr( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered MQTTAttributes.""" await help_test_discovery_update_attr( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, sensor.DOMAIN, DEFAULT_CONFIG, @@ -1032,27 +1032,27 @@ async def test_discovery_update_attr( ], ) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one sensor per unique_id.""" - await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN) + await help_test_unique_id(hass, mqtt_mock_entry, sensor.DOMAIN) async def test_discovery_removal_sensor( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test removal of discovered sensor.""" data = '{ "name": "test", "state_topic": "test_topic" }' await help_test_discovery_removal( - hass, mqtt_mock_entry_no_yaml_config, caplog, sensor.DOMAIN, data + hass, mqtt_mock_entry, caplog, sensor.DOMAIN, data ) async def test_discovery_update_sensor_topic_template( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered sensor.""" @@ -1077,7 +1077,7 @@ async def test_discovery_update_sensor_topic_template( await help_test_discovery_update( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, sensor.DOMAIN, config1, @@ -1089,7 +1089,7 @@ async def test_discovery_update_sensor_topic_template( async def test_discovery_update_sensor_template( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered sensor.""" @@ -1112,7 +1112,7 @@ async def test_discovery_update_sensor_template( await help_test_discovery_update( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, sensor.DOMAIN, config1, @@ -1124,7 +1124,7 @@ async def test_discovery_update_sensor_template( async def test_discovery_update_unchanged_sensor( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered sensor.""" @@ -1134,7 +1134,7 @@ async def test_discovery_update_unchanged_sensor( ) as discovery_update: await help_test_discovery_update_unchanged( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, sensor.DOMAIN, data1, @@ -1145,76 +1145,76 @@ async def test_discovery_update_unchanged_sensor( @pytest.mark.no_fail_on_log_exception async def test_discovery_broken( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test handling of bad discovery message.""" data1 = '{ "name": "Beer", "state_topic": "test_topic#" }' data2 = '{ "name": "Milk", "state_topic": "test_topic" }' await help_test_discovery_broken( - hass, mqtt_mock_entry_no_yaml_config, caplog, sensor.DOMAIN, data1, data2 + hass, mqtt_mock_entry, caplog, sensor.DOMAIN, data1, data2 ) async def test_entity_device_info_with_connection( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT sensor device registry integration.""" await help_test_entity_device_info_with_connection( - hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_with_identifier( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT sensor device registry integration.""" await help_test_entity_device_info_with_identifier( - hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry update.""" await help_test_entity_device_info_update( - hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_remove( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry remove.""" await help_test_entity_device_info_remove( - hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG ) async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" await help_test_entity_id_update_subscriptions( - hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG ) async def test_entity_id_update_discovery_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT discovery update when entity_id is updated.""" await help_test_entity_id_update_discovery_update( - hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_with_hub( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT sensor device registry integration.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() registry = dr.async_get(hass) hub = registry.async_get_or_create( config_entry_id="123", @@ -1241,66 +1241,66 @@ async def test_entity_device_info_with_hub( async def test_entity_debug_info( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT sensor debug info.""" await help_test_entity_debug_info( - hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG ) async def test_entity_debug_info_max_messages( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT sensor debug info.""" await help_test_entity_debug_info_max_messages( - hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG ) async def test_entity_debug_info_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT debug info.""" await help_test_entity_debug_info_message( - hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG, None + hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG, None ) async def test_entity_debug_info_remove( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT sensor debug info.""" await help_test_entity_debug_info_remove( - hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG ) async def test_entity_debug_info_update_entity_id( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT sensor debug info.""" await help_test_entity_debug_info_update_entity_id( - hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG ) async def test_entity_disabled_by_default( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test entity disabled by default.""" await help_test_entity_disabled_by_default( - hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG ) @pytest.mark.no_fail_on_log_exception async def test_entity_category( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test entity category.""" await help_test_entity_category( - hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG ) @@ -1325,10 +1325,10 @@ async def test_entity_category( ], ) async def test_value_template_with_entity_id( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the access to attributes in value_template via the entity_id.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, "test-topic", "100") state = hass.states.get("sensor.test") @@ -1373,7 +1373,7 @@ async def test_reloadable( ) async def test_cleanup_triggers_and_restoring_state( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, tmp_path: Path, freezer: FrozenDateTimeFactory, @@ -1382,7 +1382,7 @@ async def test_cleanup_triggers_and_restoring_state( """Test cleanup old triggers at reloading and restoring the state.""" freezer.move_to("2022-02-02 12:01:00+01:00") - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, "test-topic1", "100") state = hass.states.get("sensor.test1") assert state.state == "38" # 100 °F -> 38 °C @@ -1429,7 +1429,7 @@ async def test_cleanup_triggers_and_restoring_state( ) async def test_skip_restoring_state_with_over_due_expire_trigger( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, freezer: FrozenDateTimeFactory, ) -> None: """Test restoring a state with over due expire timer.""" @@ -1444,7 +1444,7 @@ async def test_skip_restoring_state_with_over_due_expire_trigger( fake_extra_data = MagicMock() mock_restore_cache_with_extra_data(hass, ((fake_state, fake_extra_data),)) - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("sensor.test3") assert state.state == STATE_UNAVAILABLE @@ -1458,7 +1458,7 @@ async def test_skip_restoring_state_with_over_due_expire_trigger( ) async def test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, topic: str, value: str, attribute: str | None, @@ -1467,7 +1467,7 @@ async def test_encoding_subscribable_topics( """Test handling of incoming encoded payload.""" await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG[mqtt.DOMAIN][sensor.DOMAIN], topic, @@ -1480,21 +1480,21 @@ async def test_encoding_subscribable_topics( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_setup_manual_entity_from_yaml( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setup manual configured MQTT entity.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() platform = sensor.DOMAIN assert hass.states.get(f"{platform}.test") async def test_unload_entry( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test unloading the config entry.""" domain = sensor.DOMAIN config = DEFAULT_CONFIG await help_test_unload_config_entry_with_platform( - hass, mqtt_mock_entry_no_yaml_config, domain, config + hass, mqtt_mock_entry, domain, config ) diff --git a/tests/components/mqtt/test_siren.py b/tests/components/mqtt/test_siren.py index 7b20e802a5c..76a9cb9c6f6 100644 --- a/tests/components/mqtt/test_siren.py +++ b/tests/components/mqtt/test_siren.py @@ -103,10 +103,10 @@ async def async_turn_off( ], ) async def test_controlling_state_via_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the controlling state via topic.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("siren.test") assert state.state == STATE_UNKNOWN @@ -140,11 +140,11 @@ async def test_controlling_state_via_topic( ], ) async def test_sending_mqtt_commands_and_optimistic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the sending MQTT commands in optimistic mode.""" await hass.async_block_till_done() - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("siren.test") assert state.state == STATE_OFF @@ -187,11 +187,11 @@ async def test_sending_mqtt_commands_and_optimistic( ) async def test_controlling_state_via_topic_and_json_message( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test the controlling state via topic and JSON message.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("siren.test") assert state.state == STATE_UNKNOWN @@ -230,11 +230,11 @@ async def test_controlling_state_via_topic_and_json_message( ) async def test_controlling_state_and_attributes_with_json_message_without_template( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test the controlling state via topic and JSON message without a value template.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("siren.test") assert state.state == STATE_UNKNOWN @@ -324,10 +324,10 @@ async def test_controlling_state_and_attributes_with_json_message_without_templa ], ) async def test_filtering_not_supported_attributes_optimistic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setting attributes with support flags optimistic.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state1 = hass.states.get("siren.test1") assert state1.state == STATE_OFF @@ -422,10 +422,10 @@ async def test_filtering_not_supported_attributes_optimistic( ], ) async def test_filtering_not_supported_attributes_via_state( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setting attributes with support flags via state.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state1 = hass.states.get("siren.test1") assert state1.state == STATE_UNKNOWN @@ -479,26 +479,26 @@ async def test_filtering_not_supported_attributes_via_state( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_when_connection_lost( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability after MQTT disconnection.""" await help_test_availability_when_connection_lost( - hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN + hass, mqtt_mock_entry, siren.DOMAIN ) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_without_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability without defined availability topic.""" await help_test_availability_without_topic( - hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, siren.DOMAIN, DEFAULT_CONFIG ) async def test_default_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by default payload with defined topic.""" config = { @@ -514,7 +514,7 @@ async def test_default_availability_payload( } await help_test_default_availability_payload( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, siren.DOMAIN, config, True, @@ -524,7 +524,7 @@ async def test_default_availability_payload( async def test_custom_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by custom payload with defined topic.""" config = { @@ -541,7 +541,7 @@ async def test_custom_availability_payload( await help_test_custom_availability_payload( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, siren.DOMAIN, config, True, @@ -569,10 +569,10 @@ async def test_custom_availability_payload( ], ) async def test_custom_state_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the state payload.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("siren.test") assert state.state == STATE_UNKNOWN @@ -590,41 +590,41 @@ async def test_custom_state_payload( async def test_setting_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_via_mqtt_json_message( - hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, siren.DOMAIN, DEFAULT_CONFIG ) async def test_setting_blocked_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_blocked_attribute_via_mqtt_json_message( - hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG, {} + hass, mqtt_mock_entry, siren.DOMAIN, DEFAULT_CONFIG, {} ) async def test_setting_attribute_with_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_with_template( - hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, siren.DOMAIN, DEFAULT_CONFIG ) async def test_update_with_json_attrs_not_dict( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_not_dict( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, siren.DOMAIN, DEFAULT_CONFIG, @@ -633,13 +633,13 @@ async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_bad_json( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_bad_json( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, siren.DOMAIN, DEFAULT_CONFIG, @@ -648,13 +648,13 @@ async def test_update_with_json_attrs_bad_json( async def test_discovery_update_attr( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered MQTTAttributes.""" await help_test_discovery_update_attr( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, siren.DOMAIN, DEFAULT_CONFIG, @@ -685,15 +685,15 @@ async def test_discovery_update_attr( ], ) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one siren per unique_id.""" - await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN) + await help_test_unique_id(hass, mqtt_mock_entry, siren.DOMAIN) async def test_discovery_removal_siren( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test removal of discovered siren.""" @@ -702,14 +702,12 @@ async def test_discovery_removal_siren( ' "state_topic": "test_topic",' ' "command_topic": "test_topic" }' ) - await help_test_discovery_removal( - hass, mqtt_mock_entry_no_yaml_config, caplog, siren.DOMAIN, data - ) + await help_test_discovery_removal(hass, mqtt_mock_entry, caplog, siren.DOMAIN, data) async def test_discovery_update_siren_topic_template( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered siren.""" @@ -736,7 +734,7 @@ async def test_discovery_update_siren_topic_template( await help_test_discovery_update( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, siren.DOMAIN, config1, @@ -748,7 +746,7 @@ async def test_discovery_update_siren_topic_template( async def test_discovery_update_siren_template( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered siren.""" @@ -773,7 +771,7 @@ async def test_discovery_update_siren_template( await help_test_discovery_update( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, siren.DOMAIN, config1, @@ -809,10 +807,10 @@ async def test_discovery_update_siren_template( ) async def test_command_templates( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test siren with command templates optimistic.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state1 = hass.states.get("siren.beer") assert state1.state == STATE_OFF @@ -875,7 +873,7 @@ async def test_command_templates( async def test_discovery_update_unchanged_siren( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered siren.""" @@ -890,7 +888,7 @@ async def test_discovery_update_unchanged_siren( ) as discovery_update: await help_test_discovery_update_unchanged( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, siren.DOMAIN, data1, @@ -901,7 +899,7 @@ async def test_discovery_update_unchanged_siren( @pytest.mark.no_fail_on_log_exception async def test_discovery_broken( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test handling of bad discovery message.""" @@ -912,71 +910,71 @@ async def test_discovery_broken( ' "command_topic": "test_topic" }' ) await help_test_discovery_broken( - hass, mqtt_mock_entry_no_yaml_config, caplog, siren.DOMAIN, data1, data2 + hass, mqtt_mock_entry, caplog, siren.DOMAIN, data1, data2 ) async def test_entity_device_info_with_connection( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT siren device registry integration.""" await help_test_entity_device_info_with_connection( - hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, siren.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_with_identifier( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT siren device registry integration.""" await help_test_entity_device_info_with_identifier( - hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, siren.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry update.""" await help_test_entity_device_info_update( - hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, siren.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_remove( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry remove.""" await help_test_entity_device_info_remove( - hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, siren.DOMAIN, DEFAULT_CONFIG ) async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" await help_test_entity_id_update_subscriptions( - hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, siren.DOMAIN, DEFAULT_CONFIG ) async def test_entity_id_update_discovery_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT discovery update when entity_id is updated.""" await help_test_entity_id_update_discovery_update( - hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, siren.DOMAIN, DEFAULT_CONFIG ) async def test_entity_debug_info_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT debug info.""" await help_test_entity_debug_info_message( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, siren.DOMAIN, DEFAULT_CONFIG, siren.SERVICE_TURN_ON, @@ -1005,7 +1003,7 @@ async def test_entity_debug_info_message( ) async def test_publishing_with_custom_encoding( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, service: str, topic: str, @@ -1020,7 +1018,7 @@ async def test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, domain, config, @@ -1050,7 +1048,7 @@ async def test_reloadable( ) async def test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, topic: str, value: str, attribute: str | None, @@ -1059,7 +1057,7 @@ async def test_encoding_subscribable_topics( """Test handling of incoming encoded payload.""" await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, siren.DOMAIN, DEFAULT_CONFIG[mqtt.DOMAIN][siren.DOMAIN], topic, @@ -1071,21 +1069,21 @@ async def test_encoding_subscribable_topics( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_setup_manual_entity_from_yaml( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setup manual configured MQTT entity.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() platform = siren.DOMAIN assert hass.states.get(f"{platform}.test") async def test_unload_entry( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test unloading the config entry.""" domain = siren.DOMAIN config = DEFAULT_CONFIG await help_test_unload_config_entry_with_platform( - hass, mqtt_mock_entry_no_yaml_config, domain, config + hass, mqtt_mock_entry, domain, config ) diff --git a/tests/components/mqtt/test_state_vacuum.py b/tests/components/mqtt/test_state_vacuum.py index dffaebca172..203f5d55b95 100644 --- a/tests/components/mqtt/test_state_vacuum.py +++ b/tests/components/mqtt/test_state_vacuum.py @@ -105,10 +105,10 @@ def vacuum_platform_only(): @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_default_supported_features( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test that the correct supported features.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() entity = hass.states.get("vacuum.mqtttest") entity_features = entity.attributes.get(mqttvacuum.CONF_SUPPORTED_FEATURES, 0) assert sorted(services_to_strings(entity_features, SERVICE_TO_STRING)) == sorted( @@ -118,10 +118,10 @@ async def test_default_supported_features( @pytest.mark.parametrize("hass_config", [CONFIG_ALL_SERVICES]) async def test_all_commands( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test simple commands send to the vacuum.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() await hass.services.async_call( DOMAIN, SERVICE_START, {"entity_id": ENTITY_MATCH_ALL}, blocking=True @@ -201,10 +201,10 @@ async def test_all_commands( ], ) async def test_commands_without_supported_features( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test commands which are not supported by the vacuum.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() await hass.services.async_call( DOMAIN, SERVICE_START, {"entity_id": ENTITY_MATCH_ALL}, blocking=True @@ -254,10 +254,10 @@ async def test_commands_without_supported_features( @pytest.mark.parametrize("hass_config", [CONFIG_ALL_SERVICES]) async def test_status( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test status updates from the vacuum.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("vacuum.mqtttest") assert state.state == STATE_UNKNOWN @@ -310,10 +310,10 @@ async def test_status( ], ) async def test_no_fan_vacuum( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test status updates from the vacuum when fan is not supported.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() message = """{ "battery_level": 54, @@ -357,10 +357,10 @@ async def test_no_fan_vacuum( @pytest.mark.parametrize("hass_config", [CONFIG_ALL_SERVICES]) @pytest.mark.no_fail_on_log_exception async def test_status_invalid_json( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test to make sure nothing breaks if the vacuum sends bad JSON.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, "vacuum/state", '{"asdfasas false}') state = hass.states.get("vacuum.mqtttest") @@ -369,58 +369,58 @@ async def test_status_invalid_json( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_2]) async def test_availability_when_connection_lost( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability after MQTT disconnection.""" await help_test_availability_when_connection_lost( - hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN + hass, mqtt_mock_entry, vacuum.DOMAIN ) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_2]) async def test_availability_without_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability without defined availability topic.""" await help_test_availability_without_topic( - hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2 + hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2 ) async def test_default_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by default payload with defined topic.""" await help_test_default_availability_payload( - hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2 + hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2 ) async def test_custom_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by custom payload with defined topic.""" await help_test_custom_availability_payload( - hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2 + hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2 ) async def test_setting_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_via_mqtt_json_message( - hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2 + hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2 ) async def test_setting_blocked_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_blocked_attribute_via_mqtt_json_message( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2, MQTT_VACUUM_ATTRIBUTES_BLOCKED, @@ -428,23 +428,23 @@ async def test_setting_blocked_attribute_via_mqtt_json_message( async def test_setting_attribute_with_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_with_template( - hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2 + hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2 ) async def test_update_with_json_attrs_not_dict( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_not_dict( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, vacuum.DOMAIN, DEFAULT_CONFIG_2, @@ -453,13 +453,13 @@ async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_bad_json( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_bad_json( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, vacuum.DOMAIN, DEFAULT_CONFIG_2, @@ -468,13 +468,13 @@ async def test_update_with_json_attrs_bad_json( async def test_discovery_update_attr( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered MQTTAttributes.""" await help_test_discovery_update_attr( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, vacuum.DOMAIN, DEFAULT_CONFIG_2, @@ -505,40 +505,40 @@ async def test_discovery_update_attr( ], ) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one vacuum per unique_id.""" - await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN) + await help_test_unique_id(hass, mqtt_mock_entry, vacuum.DOMAIN) async def test_discovery_removal_vacuum( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test removal of discovered vacuum.""" data = '{ "schema": "state", "name": "test", "command_topic": "test_topic"}' await help_test_discovery_removal( - hass, mqtt_mock_entry_no_yaml_config, caplog, vacuum.DOMAIN, data + hass, mqtt_mock_entry, caplog, vacuum.DOMAIN, data ) async def test_discovery_update_vacuum( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered vacuum.""" config1 = {"schema": "state", "name": "Beer", "command_topic": "test_topic"} config2 = {"schema": "state", "name": "Milk", "command_topic": "test_topic"} await help_test_discovery_update( - hass, mqtt_mock_entry_no_yaml_config, caplog, vacuum.DOMAIN, config1, config2 + hass, mqtt_mock_entry, caplog, vacuum.DOMAIN, config1, config2 ) async def test_discovery_update_unchanged_vacuum( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered vacuum.""" @@ -548,7 +548,7 @@ async def test_discovery_update_unchanged_vacuum( ) as discovery_update: await help_test_discovery_update_unchanged( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, vacuum.DOMAIN, data1, @@ -559,78 +559,78 @@ async def test_discovery_update_unchanged_vacuum( @pytest.mark.no_fail_on_log_exception async def test_discovery_broken( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test handling of bad discovery message.""" data1 = '{ "schema": "state", "name": "Beer", "command_topic": "test_topic#"}' data2 = '{ "schema": "state", "name": "Milk", "command_topic": "test_topic"}' await help_test_discovery_broken( - hass, mqtt_mock_entry_no_yaml_config, caplog, vacuum.DOMAIN, data1, data2 + hass, mqtt_mock_entry, caplog, vacuum.DOMAIN, data1, data2 ) async def test_entity_device_info_with_connection( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT vacuum device registry integration.""" await help_test_entity_device_info_with_connection( - hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2 + hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2 ) async def test_entity_device_info_with_identifier( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT vacuum device registry integration.""" await help_test_entity_device_info_with_identifier( - hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2 + hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2 ) async def test_entity_device_info_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry update.""" await help_test_entity_device_info_update( - hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2 + hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2 ) async def test_entity_device_info_remove( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry remove.""" await help_test_entity_device_info_remove( - hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2 + hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2 ) async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" await help_test_entity_id_update_subscriptions( - hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2 + hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2 ) async def test_entity_id_update_discovery_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT discovery update when entity_id is updated.""" await help_test_entity_id_update_discovery_update( - hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2 + hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2 ) async def test_entity_debug_info_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT debug info.""" await help_test_entity_debug_info_message( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2, vacuum.SERVICE_START, @@ -681,7 +681,7 @@ async def test_entity_debug_info_message( ) async def test_publishing_with_custom_encoding( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, service: str, topic: str, @@ -707,7 +707,7 @@ async def test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, domain, config, @@ -748,7 +748,7 @@ async def test_reloadable( ) async def test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, topic: str, value: str, attribute: str | None, @@ -757,7 +757,7 @@ async def test_encoding_subscribable_topics( """Test handling of incoming encoded payload.""" await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG[mqtt.DOMAIN][vacuum.DOMAIN], topic, @@ -770,9 +770,9 @@ async def test_encoding_subscribable_topics( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_setup_manual_entity_from_yaml( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setup manual configured MQTT entity.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() platform = vacuum.DOMAIN assert hass.states.get(f"{platform}.mqtttest") diff --git a/tests/components/mqtt/test_subscription.py b/tests/components/mqtt/test_subscription.py index f720b44321e..fe8c9fb6101 100644 --- a/tests/components/mqtt/test_subscription.py +++ b/tests/components/mqtt/test_subscription.py @@ -23,11 +23,11 @@ def no_platforms(): async def test_subscribe_topics( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test subscription to topics.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() calls1 = [] @callback @@ -76,11 +76,11 @@ async def test_subscribe_topics( async def test_modify_topics( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test modification of topics.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() calls1 = [] @callback @@ -143,11 +143,11 @@ async def test_modify_topics( async def test_qos_encoding_default( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test default qos and encoding.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() @callback def msg_callback(*args): @@ -165,11 +165,11 @@ async def test_qos_encoding_default( async def test_qos_encoding_custom( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test custom qos and encoding.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() @callback def msg_callback(*args): @@ -194,11 +194,11 @@ async def test_qos_encoding_custom( async def test_no_change( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test subscription to topics without change.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() calls = [] diff --git a/tests/components/mqtt/test_switch.py b/tests/components/mqtt/test_switch.py index 79f2bcc4a7c..5088558b143 100644 --- a/tests/components/mqtt/test_switch.py +++ b/tests/components/mqtt/test_switch.py @@ -79,10 +79,10 @@ def switch_platform_only(): ], ) async def test_controlling_state_via_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the controlling state via topic.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("switch.test") assert state.state == STATE_UNKNOWN @@ -122,13 +122,13 @@ async def test_controlling_state_via_topic( ], ) async def test_sending_mqtt_commands_and_optimistic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the sending MQTT commands in optimistic mode.""" fake_state = State("switch.test", "on") mock_restore_cache(hass, (fake_state,)) - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("switch.test") assert state.state == STATE_ON @@ -166,10 +166,10 @@ async def test_sending_mqtt_commands_and_optimistic( ], ) async def test_sending_inital_state_and_optimistic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the initial state in optimistic mode.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("switch.test") assert state.state == STATE_UNKNOWN @@ -194,10 +194,10 @@ async def test_sending_inital_state_and_optimistic( ], ) async def test_controlling_state_via_topic_and_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the controlling state via topic and JSON message.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("switch.test") assert state.state == STATE_UNKNOWN @@ -220,26 +220,26 @@ async def test_controlling_state_via_topic_and_json_message( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_when_connection_lost( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability after MQTT disconnection.""" await help_test_availability_when_connection_lost( - hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN + hass, mqtt_mock_entry, switch.DOMAIN ) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_without_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability without defined availability topic.""" await help_test_availability_without_topic( - hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, switch.DOMAIN, DEFAULT_CONFIG ) async def test_default_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by default payload with defined topic.""" config = { @@ -255,7 +255,7 @@ async def test_default_availability_payload( } await help_test_default_availability_payload( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, switch.DOMAIN, config, True, @@ -265,7 +265,7 @@ async def test_default_availability_payload( async def test_custom_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by custom payload with defined topic.""" config = { @@ -282,7 +282,7 @@ async def test_custom_availability_payload( await help_test_custom_availability_payload( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, switch.DOMAIN, config, True, @@ -310,10 +310,10 @@ async def test_custom_availability_payload( ], ) async def test_custom_state_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the state payload.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("switch.test") assert state.state == STATE_UNKNOWN @@ -331,41 +331,41 @@ async def test_custom_state_payload( async def test_setting_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_via_mqtt_json_message( - hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, switch.DOMAIN, DEFAULT_CONFIG ) async def test_setting_blocked_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_blocked_attribute_via_mqtt_json_message( - hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG, {} + hass, mqtt_mock_entry, switch.DOMAIN, DEFAULT_CONFIG, {} ) async def test_setting_attribute_with_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_with_template( - hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, switch.DOMAIN, DEFAULT_CONFIG ) async def test_update_with_json_attrs_not_dict( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_not_dict( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, switch.DOMAIN, DEFAULT_CONFIG, @@ -374,13 +374,13 @@ async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_bad_json( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_bad_json( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, switch.DOMAIN, DEFAULT_CONFIG, @@ -389,13 +389,13 @@ async def test_update_with_json_attrs_bad_json( async def test_discovery_update_attr( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered MQTTAttributes.""" await help_test_discovery_update_attr( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, switch.DOMAIN, DEFAULT_CONFIG, @@ -426,15 +426,15 @@ async def test_discovery_update_attr( ], ) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one switch per unique_id.""" - await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN) + await help_test_unique_id(hass, mqtt_mock_entry, switch.DOMAIN) async def test_discovery_removal_switch( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test removal of discovered switch.""" @@ -444,13 +444,13 @@ async def test_discovery_removal_switch( ' "command_topic": "test_topic" }' ) await help_test_discovery_removal( - hass, mqtt_mock_entry_no_yaml_config, caplog, switch.DOMAIN, data + hass, mqtt_mock_entry, caplog, switch.DOMAIN, data ) async def test_discovery_update_switch_topic_template( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered switch.""" @@ -477,7 +477,7 @@ async def test_discovery_update_switch_topic_template( await help_test_discovery_update( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, switch.DOMAIN, config1, @@ -489,7 +489,7 @@ async def test_discovery_update_switch_topic_template( async def test_discovery_update_switch_template( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered switch.""" @@ -514,7 +514,7 @@ async def test_discovery_update_switch_template( await help_test_discovery_update( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, switch.DOMAIN, config1, @@ -526,7 +526,7 @@ async def test_discovery_update_switch_template( async def test_discovery_update_unchanged_switch( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered switch.""" @@ -541,7 +541,7 @@ async def test_discovery_update_unchanged_switch( ) as discovery_update: await help_test_discovery_update_unchanged( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, switch.DOMAIN, data1, @@ -552,7 +552,7 @@ async def test_discovery_update_unchanged_switch( @pytest.mark.no_fail_on_log_exception async def test_discovery_broken( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test handling of bad discovery message.""" @@ -563,71 +563,71 @@ async def test_discovery_broken( ' "command_topic": "test_topic" }' ) await help_test_discovery_broken( - hass, mqtt_mock_entry_no_yaml_config, caplog, switch.DOMAIN, data1, data2 + hass, mqtt_mock_entry, caplog, switch.DOMAIN, data1, data2 ) async def test_entity_device_info_with_connection( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT switch device registry integration.""" await help_test_entity_device_info_with_connection( - hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, switch.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_with_identifier( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT switch device registry integration.""" await help_test_entity_device_info_with_identifier( - hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, switch.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry update.""" await help_test_entity_device_info_update( - hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, switch.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_remove( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry remove.""" await help_test_entity_device_info_remove( - hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, switch.DOMAIN, DEFAULT_CONFIG ) async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" await help_test_entity_id_update_subscriptions( - hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, switch.DOMAIN, DEFAULT_CONFIG ) async def test_entity_id_update_discovery_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT discovery update when entity_id is updated.""" await help_test_entity_id_update_discovery_update( - hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, switch.DOMAIN, DEFAULT_CONFIG ) async def test_entity_debug_info_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT debug info.""" await help_test_entity_debug_info_message( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, switch.DOMAIN, DEFAULT_CONFIG, switch.SERVICE_TURN_ON, @@ -655,7 +655,7 @@ async def test_entity_debug_info_message( ) async def test_publishing_with_custom_encoding( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, service: str, topic: str, @@ -669,7 +669,7 @@ async def test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, domain, config, @@ -699,7 +699,7 @@ async def test_reloadable( ) async def test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, topic: str, value: str, attribute: str | None, @@ -708,7 +708,7 @@ async def test_encoding_subscribable_topics( """Test handling of incoming encoded payload.""" await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, switch.DOMAIN, DEFAULT_CONFIG[mqtt.DOMAIN][switch.DOMAIN], topic, @@ -720,21 +720,21 @@ async def test_encoding_subscribable_topics( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_setup_manual_entity_from_yaml( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setup manual configured MQTT entity.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() platform = switch.DOMAIN assert hass.states.get(f"{platform}.test") async def test_unload_entry( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test unloading the config entry.""" domain = switch.DOMAIN config = DEFAULT_CONFIG await help_test_unload_config_entry_with_platform( - hass, mqtt_mock_entry_no_yaml_config, domain, config + hass, mqtt_mock_entry, domain, config ) diff --git a/tests/components/mqtt/test_tag.py b/tests/components/mqtt/test_tag.py index 2f7a9d0cc06..f8c7b55f7ce 100644 --- a/tests/components/mqtt/test_tag.py +++ b/tests/components/mqtt/test_tag.py @@ -64,11 +64,11 @@ def tag_mock(): async def test_discover_bad_tag( hass: HomeAssistant, device_registry: dr.DeviceRegistry, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, tag_mock, ) -> None: """Test bad discovery message.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() config1 = copy.deepcopy(DEFAULT_CONFIG_DEVICE) # Test sending bad data @@ -91,11 +91,11 @@ async def test_discover_bad_tag( async def test_if_fires_on_mqtt_message_with_device( hass: HomeAssistant, device_registry: dr.DeviceRegistry, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, tag_mock, ) -> None: """Test tag scanning, with device.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() config = copy.deepcopy(DEFAULT_CONFIG_DEVICE) async_fire_mqtt_message(hass, "homeassistant/tag/bla1/config", json.dumps(config)) @@ -111,11 +111,11 @@ async def test_if_fires_on_mqtt_message_with_device( async def test_if_fires_on_mqtt_message_without_device( hass: HomeAssistant, device_registry: dr.DeviceRegistry, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, tag_mock, ) -> None: """Test tag scanning, without device.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() config = copy.deepcopy(DEFAULT_CONFIG) async_fire_mqtt_message(hass, "homeassistant/tag/bla1/config", json.dumps(config)) @@ -130,11 +130,11 @@ async def test_if_fires_on_mqtt_message_without_device( async def test_if_fires_on_mqtt_message_with_template( hass: HomeAssistant, device_registry: dr.DeviceRegistry, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, tag_mock, ) -> None: """Test tag scanning, with device.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() config = copy.deepcopy(DEFAULT_CONFIG_JSON) async_fire_mqtt_message(hass, "homeassistant/tag/bla1/config", json.dumps(config)) @@ -149,11 +149,11 @@ async def test_if_fires_on_mqtt_message_with_template( async def test_strip_tag_id( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, tag_mock, ) -> None: """Test strip whitespace from tag_id.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() config = copy.deepcopy(DEFAULT_CONFIG) async_fire_mqtt_message(hass, "homeassistant/tag/bla1/config", json.dumps(config)) @@ -168,11 +168,11 @@ async def test_strip_tag_id( async def test_if_fires_on_mqtt_message_after_update_with_device( hass: HomeAssistant, device_registry: dr.DeviceRegistry, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, tag_mock, ) -> None: """Test tag scanning after update.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() config1 = copy.deepcopy(DEFAULT_CONFIG_DEVICE) config1["some_future_option_1"] = "future_option_1" config2 = copy.deepcopy(DEFAULT_CONFIG_DEVICE) @@ -217,11 +217,11 @@ async def test_if_fires_on_mqtt_message_after_update_with_device( async def test_if_fires_on_mqtt_message_after_update_without_device( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, tag_mock, ) -> None: """Test tag scanning after update.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() config1 = copy.deepcopy(DEFAULT_CONFIG) config2 = copy.deepcopy(DEFAULT_CONFIG) config2["topic"] = "foobar/tag_scanned2" @@ -264,11 +264,11 @@ async def test_if_fires_on_mqtt_message_after_update_without_device( async def test_if_fires_on_mqtt_message_after_update_with_template( hass: HomeAssistant, device_registry: dr.DeviceRegistry, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, tag_mock, ) -> None: """Test tag scanning after update.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() config1 = copy.deepcopy(DEFAULT_CONFIG_JSON) config2 = copy.deepcopy(DEFAULT_CONFIG_JSON) config2["value_template"] = "{{ value_json.RDM6300.UID }}" @@ -313,10 +313,10 @@ async def test_if_fires_on_mqtt_message_after_update_with_template( async def test_no_resubscribe_same_topic( hass: HomeAssistant, device_registry: dr.DeviceRegistry, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test subscription to topics without change.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() config = copy.deepcopy(DEFAULT_CONFIG_DEVICE) async_fire_mqtt_message(hass, "homeassistant/tag/bla1/config", json.dumps(config)) @@ -332,11 +332,11 @@ async def test_no_resubscribe_same_topic( async def test_not_fires_on_mqtt_message_after_remove_by_mqtt_with_device( hass: HomeAssistant, device_registry: dr.DeviceRegistry, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, tag_mock, ) -> None: """Test tag scanning after removal.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() config = copy.deepcopy(DEFAULT_CONFIG_DEVICE) async_fire_mqtt_message(hass, "homeassistant/tag/bla1/config", json.dumps(config)) @@ -368,11 +368,11 @@ async def test_not_fires_on_mqtt_message_after_remove_by_mqtt_with_device( async def test_not_fires_on_mqtt_message_after_remove_by_mqtt_without_device( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, tag_mock, ) -> None: """Test tag scanning not firing after removal.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() config = copy.deepcopy(DEFAULT_CONFIG) async_fire_mqtt_message(hass, "homeassistant/tag/bla1/config", json.dumps(config)) @@ -405,13 +405,13 @@ async def test_not_fires_on_mqtt_message_after_remove_from_registry( hass: HomeAssistant, hass_ws_client: WebSocketGenerator, device_registry: dr.DeviceRegistry, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, tag_mock, ) -> None: """Test tag scanning after removal.""" assert await async_setup_component(hass, "config", {}) await hass.async_block_till_done() - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() ws_client = await hass_ws_client(hass) config = copy.deepcopy(DEFAULT_CONFIG_DEVICE) @@ -445,10 +445,10 @@ async def test_not_fires_on_mqtt_message_after_remove_from_registry( async def test_entity_device_info_with_connection( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT device registry integration.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() registry = dr.async_get(hass) data = json.dumps( @@ -480,10 +480,10 @@ async def test_entity_device_info_with_connection( async def test_entity_device_info_with_identifier( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT device registry integration.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() registry = dr.async_get(hass) data = json.dumps( @@ -513,10 +513,10 @@ async def test_entity_device_info_with_identifier( async def test_entity_device_info_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry update.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() registry = dr.async_get(hass) config = { @@ -553,12 +553,12 @@ async def test_cleanup_tag( hass: HomeAssistant, hass_ws_client: WebSocketGenerator, device_registry: dr.DeviceRegistry, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test tag discovery topic is cleaned when device is removed from registry.""" assert await async_setup_component(hass, "config", {}) await hass.async_block_till_done() - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() ws_client = await hass_ws_client(hass) mqtt_entry = hass.config_entries.async_entries("mqtt")[0] @@ -636,10 +636,10 @@ async def test_cleanup_tag( async def test_cleanup_device( hass: HomeAssistant, device_registry: dr.DeviceRegistry, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test removal from device registry when tag is removed.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() config = { "topic": "test-topic", "device": {"identifiers": ["helloworld"]}, @@ -664,11 +664,11 @@ async def test_cleanup_device( async def test_cleanup_device_several_tags( hass: HomeAssistant, device_registry: dr.DeviceRegistry, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, tag_mock, ) -> None: """Test removal from device registry when the last tag is removed.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() config1 = { "topic": "test-topic1", "device": {"identifiers": ["helloworld"]}, @@ -712,13 +712,13 @@ async def test_cleanup_device_several_tags( async def test_cleanup_device_with_entity_and_trigger_1( hass: HomeAssistant, device_registry: dr.DeviceRegistry, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test removal from device registry for device with tag, entity and trigger. Tag removed first, then trigger and entity. """ - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() config1 = { "topic": "test-topic", "device": {"identifiers": ["helloworld"]}, @@ -779,13 +779,13 @@ async def test_cleanup_device_with_entity_and_trigger_1( async def test_cleanup_device_with_entity2( hass: HomeAssistant, device_registry: dr.DeviceRegistry, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test removal from device registry for device with tag, entity and trigger. Trigger and entity removed first, then tag. """ - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() config1 = { "topic": "test-topic", "device": {"identifiers": ["helloworld"]}, @@ -846,11 +846,11 @@ async def test_cleanup_device_with_entity2( @pytest.mark.xfail(raises=MultipleInvalid) async def test_update_with_bad_config_not_breaks_discovery( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, tag_mock, ) -> None: """Test a bad update does not break discovery.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() config1 = { "topic": "test-topic", "device": {"identifiers": ["helloworld"]}, diff --git a/tests/components/mqtt/test_text.py b/tests/components/mqtt/test_text.py index 10e9f0780d5..b96b82277b0 100644 --- a/tests/components/mqtt/test_text.py +++ b/tests/components/mqtt/test_text.py @@ -87,10 +87,10 @@ async def async_set_value( ], ) async def test_controlling_state_via_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the controlling state via topic.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("text.test") assert state.state == STATE_UNKNOWN @@ -133,11 +133,11 @@ async def test_controlling_state_via_topic( ) async def test_controlling_validation_state_via_topic( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test the validation of a received state.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("text.test") assert state.state == STATE_UNKNOWN @@ -203,11 +203,11 @@ async def test_controlling_validation_state_via_topic( ], ) async def test_attribute_validation_max_greater_then_min( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the validation of min and max configuration attributes.""" with pytest.raises(AssertionError): - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() @pytest.mark.parametrize( @@ -226,11 +226,11 @@ async def test_attribute_validation_max_greater_then_min( ], ) async def test_attribute_validation_max_not_greater_then_max_state_length( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the max value of of max configuration attribute.""" with pytest.raises(AssertionError): - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() @pytest.mark.parametrize( @@ -248,10 +248,10 @@ async def test_attribute_validation_max_not_greater_then_max_state_length( ], ) async def test_sending_mqtt_commands_and_optimistic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the sending MQTT commands in optimistic mode.""" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() state = hass.states.get("text.test") assert state.state == STATE_UNKNOWN @@ -294,10 +294,10 @@ async def test_sending_mqtt_commands_and_optimistic( ], ) async def test_set_text_validation( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the initial state in optimistic mode.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() state = hass.states.get("text.test") assert state.state == STATE_UNKNOWN @@ -322,26 +322,26 @@ async def test_set_text_validation( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_when_connection_lost( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability after MQTT disconnection.""" await help_test_availability_when_connection_lost( - hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN + hass, mqtt_mock_entry, text.DOMAIN ) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_without_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability without defined availability topic.""" await help_test_availability_without_topic( - hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, text.DOMAIN, DEFAULT_CONFIG ) async def test_default_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by default payload with defined topic.""" config = { @@ -355,7 +355,7 @@ async def test_default_availability_payload( } await help_test_default_availability_payload( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, text.DOMAIN, config, True, @@ -365,7 +365,7 @@ async def test_default_availability_payload( async def test_custom_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by custom payload with defined topic.""" config = { @@ -380,7 +380,7 @@ async def test_custom_availability_payload( await help_test_custom_availability_payload( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, text.DOMAIN, config, True, @@ -390,41 +390,41 @@ async def test_custom_availability_payload( async def test_setting_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_via_mqtt_json_message( - hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, text.DOMAIN, DEFAULT_CONFIG ) async def test_setting_blocked_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_blocked_attribute_via_mqtt_json_message( - hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN, DEFAULT_CONFIG, {} + hass, mqtt_mock_entry, text.DOMAIN, DEFAULT_CONFIG, {} ) async def test_setting_attribute_with_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_with_template( - hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, text.DOMAIN, DEFAULT_CONFIG ) async def test_update_with_json_attrs_not_dict( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_not_dict( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, text.DOMAIN, DEFAULT_CONFIG, @@ -433,13 +433,13 @@ async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_bad_json( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_bad_json( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, text.DOMAIN, DEFAULT_CONFIG, @@ -448,13 +448,13 @@ async def test_update_with_json_attrs_bad_json( async def test_discovery_update_attr( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered MQTTAttributes.""" await help_test_discovery_update_attr( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, text.DOMAIN, DEFAULT_CONFIG, @@ -485,15 +485,15 @@ async def test_discovery_update_attr( ], ) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one text per unique_id.""" - await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN) + await help_test_unique_id(hass, mqtt_mock_entry, text.DOMAIN) async def test_discovery_removal_text( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test removal of discovered text entity.""" @@ -502,14 +502,12 @@ async def test_discovery_removal_text( ' "state_topic": "test_topic",' ' "command_topic": "test_topic" }' ) - await help_test_discovery_removal( - hass, mqtt_mock_entry_no_yaml_config, caplog, text.DOMAIN, data - ) + await help_test_discovery_removal(hass, mqtt_mock_entry, caplog, text.DOMAIN, data) async def test_discovery_text_update( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered text entity.""" @@ -525,13 +523,13 @@ async def test_discovery_text_update( } await help_test_discovery_update( - hass, mqtt_mock_entry_no_yaml_config, caplog, text.DOMAIN, config1, config2 + hass, mqtt_mock_entry, caplog, text.DOMAIN, config1, config2 ) async def test_discovery_update_unchanged_update( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered update.""" @@ -541,7 +539,7 @@ async def test_discovery_update_unchanged_update( ) as discovery_update: await help_test_discovery_update_unchanged( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, text.DOMAIN, data1, @@ -551,20 +549,20 @@ async def test_discovery_update_unchanged_update( async def test_discovery_update_text( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered text entity.""" config1 = {"name": "Beer", "command_topic": "cmd-topic1"} config2 = {"name": "Milk", "command_topic": "cmd-topic2"} await help_test_discovery_update( - hass, mqtt_mock_entry_no_yaml_config, caplog, text.DOMAIN, config1, config2 + hass, mqtt_mock_entry, caplog, text.DOMAIN, config1, config2 ) async def test_discovery_update_unchanged_climate( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered text entity.""" @@ -574,7 +572,7 @@ async def test_discovery_update_unchanged_climate( ) as discovery_update: await help_test_discovery_update_unchanged( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, text.DOMAIN, data1, @@ -585,7 +583,7 @@ async def test_discovery_update_unchanged_climate( @pytest.mark.no_fail_on_log_exception async def test_discovery_broken( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test handling of bad discovery message.""" @@ -596,70 +594,70 @@ async def test_discovery_broken( ' "command_topic": "test_topic" }' ) await help_test_discovery_broken( - hass, mqtt_mock_entry_no_yaml_config, caplog, text.DOMAIN, data1, data2 + hass, mqtt_mock_entry, caplog, text.DOMAIN, data1, data2 ) async def test_entity_device_info_with_connection( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT text device registry integration.""" await help_test_entity_device_info_with_connection( - hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, text.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_with_identifier( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT text device registry integration.""" await help_test_entity_device_info_with_identifier( - hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, text.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry update.""" await help_test_entity_device_info_update( - hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, text.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_remove( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry remove.""" await help_test_entity_device_info_remove( - hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, text.DOMAIN, DEFAULT_CONFIG ) async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" await help_test_entity_id_update_subscriptions( - hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, text.DOMAIN, DEFAULT_CONFIG ) async def test_entity_id_update_discovery_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT discovery update when entity_id is updated.""" await help_test_entity_id_update_discovery_update( - hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, text.DOMAIN, DEFAULT_CONFIG ) async def test_entity_debug_info_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT debug info.""" await help_test_entity_debug_info_message( - hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN, DEFAULT_CONFIG, None + hass, mqtt_mock_entry, text.DOMAIN, DEFAULT_CONFIG, None ) @@ -677,7 +675,7 @@ async def test_entity_debug_info_message( ) async def test_publishing_with_custom_encoding( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, service: str, topic: str, @@ -691,7 +689,7 @@ async def test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, domain, config, @@ -721,7 +719,7 @@ async def test_reloadable( ) async def test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, topic: str, value: str, attribute: str | None, @@ -730,7 +728,7 @@ async def test_encoding_subscribable_topics( """Test handling of incoming encoded payload.""" await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, text.DOMAIN, DEFAULT_CONFIG[mqtt.DOMAIN][text.DOMAIN], topic, @@ -742,21 +740,21 @@ async def test_encoding_subscribable_topics( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_setup_manual_entity_from_yaml( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setup manual configured MQTT entity.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() platform = text.DOMAIN assert hass.states.get(f"{platform}.test") async def test_unload_entry( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test unloading the config entry.""" domain = text.DOMAIN config = DEFAULT_CONFIG await help_test_unload_config_entry_with_platform( - hass, mqtt_mock_entry_no_yaml_config, domain, config + hass, mqtt_mock_entry, domain, config ) diff --git a/tests/components/mqtt/test_trigger.py b/tests/components/mqtt/test_trigger.py index c4b197275a3..83868c3387c 100644 --- a/tests/components/mqtt/test_trigger.py +++ b/tests/components/mqtt/test_trigger.py @@ -26,10 +26,10 @@ def no_platforms(): @pytest.fixture(autouse=True) -async def setup_comp(hass: HomeAssistant, mqtt_mock_entry_no_yaml_config): +async def setup_comp(hass: HomeAssistant, mqtt_mock_entry): """Initialize components.""" mock_component(hass, "group") - return await mqtt_mock_entry_no_yaml_config() + return await mqtt_mock_entry() async def test_if_fires_on_topic_match(hass: HomeAssistant, calls) -> None: diff --git a/tests/components/mqtt/test_update.py b/tests/components/mqtt/test_update.py index bdd85768b85..e3f06d88f9d 100644 --- a/tests/components/mqtt/test_update.py +++ b/tests/components/mqtt/test_update.py @@ -81,12 +81,12 @@ def update_platform_only(): ], ) async def test_run_update_setup( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test that it fetches the given payload.""" installed_version_topic = "test/installed-version" latest_version_topic = "test/latest-version" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, installed_version_topic, "1.9.0") async_fire_mqtt_message(hass, latest_version_topic, "1.9.0") @@ -131,12 +131,12 @@ async def test_run_update_setup( ], ) async def test_run_update_setup_float( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test that it fetches the given payload when the version is parsable as a number.""" installed_version_topic = "test/installed-version" latest_version_topic = "test/latest-version" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, installed_version_topic, "1.9") async_fire_mqtt_message(hass, latest_version_topic, "1.9") @@ -179,12 +179,12 @@ async def test_run_update_setup_float( ], ) async def test_value_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test that it fetches the given payload with a template.""" installed_version_topic = "test/installed-version" latest_version_topic = "test/latest-version" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, installed_version_topic, '{"installed":"1.9.0"}') async_fire_mqtt_message(hass, latest_version_topic, '{"latest":"1.9.0"}') @@ -227,12 +227,12 @@ async def test_value_template( ], ) async def test_value_template_float( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test that it fetches the given payload with a template when the version is parsable as a number.""" installed_version_topic = "test/installed-version" latest_version_topic = "test/latest-version" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, installed_version_topic, '{"installed":"1.9"}') async_fire_mqtt_message(hass, latest_version_topic, '{"latest":"1.9"}') @@ -272,11 +272,11 @@ async def test_value_template_float( ], ) async def test_empty_json_state_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test an empty JSON payload.""" state_topic = "test/state-topic" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, state_topic, "{}") @@ -300,11 +300,11 @@ async def test_empty_json_state_message( ], ) async def test_json_state_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test whether it fetches data from a JSON payload.""" state_topic = "test/state-topic" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message( hass, @@ -358,11 +358,11 @@ async def test_json_state_message( ], ) async def test_json_state_message_with_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test whether it fetches data from a JSON payload with template.""" state_topic = "test/state-topic" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() async_fire_mqtt_message(hass, state_topic, '{"installed":"1.9.0","latest":"1.9.0"}') @@ -400,14 +400,14 @@ async def test_json_state_message_with_template( ], ) async def test_run_install_service( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test that install service works.""" installed_version_topic = "test/installed-version" latest_version_topic = "test/latest-version" command_topic = "test/install-command" - mqtt_mock = await mqtt_mock_entry_no_yaml_config() + mqtt_mock = await mqtt_mock_entry() async_fire_mqtt_message(hass, installed_version_topic, "1.9.0") async_fire_mqtt_message(hass, latest_version_topic, "2.0.0") @@ -429,69 +429,69 @@ async def test_run_install_service( @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_when_connection_lost( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability after MQTT disconnection.""" await help_test_availability_when_connection_lost( - hass, mqtt_mock_entry_no_yaml_config, update.DOMAIN + hass, mqtt_mock_entry, update.DOMAIN ) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_availability_without_topic( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability without defined availability topic.""" await help_test_availability_without_topic( - hass, mqtt_mock_entry_no_yaml_config, update.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, update.DOMAIN, DEFAULT_CONFIG ) async def test_default_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by default payload with defined topic.""" await help_test_default_availability_payload( - hass, mqtt_mock_entry_no_yaml_config, update.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, update.DOMAIN, DEFAULT_CONFIG ) async def test_custom_availability_payload( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test availability by custom payload with defined topic.""" await help_test_custom_availability_payload( - hass, mqtt_mock_entry_no_yaml_config, update.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, update.DOMAIN, DEFAULT_CONFIG ) async def test_setting_attribute_via_mqtt_json_message( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_via_mqtt_json_message( - hass, mqtt_mock_entry_no_yaml_config, update.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, update.DOMAIN, DEFAULT_CONFIG ) async def test_setting_attribute_with_template( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_with_template( - hass, mqtt_mock_entry_no_yaml_config, update.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, update.DOMAIN, DEFAULT_CONFIG ) async def test_update_with_json_attrs_not_dict( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_not_dict( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, update.DOMAIN, DEFAULT_CONFIG, @@ -500,13 +500,13 @@ async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_bad_json( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test attributes get extracted from a JSON result.""" await help_test_update_with_json_attrs_bad_json( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, update.DOMAIN, DEFAULT_CONFIG, @@ -515,13 +515,13 @@ async def test_update_with_json_attrs_bad_json( async def test_discovery_update_attr( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered MQTTAttributes.""" await help_test_discovery_update_attr( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, update.DOMAIN, DEFAULT_CONFIG, @@ -552,27 +552,27 @@ async def test_discovery_update_attr( ], ) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one update per unique_id.""" - await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, update.DOMAIN) + await help_test_unique_id(hass, mqtt_mock_entry, update.DOMAIN) async def test_discovery_removal_update( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test removal of discovered update.""" data = json.dumps(DEFAULT_CONFIG[mqtt.DOMAIN][update.DOMAIN]) await help_test_discovery_removal( - hass, mqtt_mock_entry_no_yaml_config, caplog, update.DOMAIN, data + hass, mqtt_mock_entry, caplog, update.DOMAIN, data ) async def test_discovery_update_update( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered update.""" @@ -588,13 +588,13 @@ async def test_discovery_update_update( } await help_test_discovery_update( - hass, mqtt_mock_entry_no_yaml_config, caplog, update.DOMAIN, config1, config2 + hass, mqtt_mock_entry, caplog, update.DOMAIN, config1, config2 ) async def test_discovery_update_unchanged_update( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered update.""" @@ -604,7 +604,7 @@ async def test_discovery_update_unchanged_update( ) as discovery_update: await help_test_discovery_update_unchanged( hass, - mqtt_mock_entry_no_yaml_config, + mqtt_mock_entry, caplog, update.DOMAIN, data1, @@ -615,7 +615,7 @@ async def test_discovery_update_unchanged_update( @pytest.mark.no_fail_on_log_exception async def test_discovery_broken( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: """Test handling of bad discovery message.""" @@ -623,74 +623,74 @@ async def test_discovery_broken( data2 = '{ "name": "Milk", "state_topic": "installed-topic", "latest_version_topic": "latest-topic" }' await help_test_discovery_broken( - hass, mqtt_mock_entry_no_yaml_config, caplog, update.DOMAIN, data1, data2 + hass, mqtt_mock_entry, caplog, update.DOMAIN, data1, data2 ) async def test_entity_device_info_with_connection( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT update device registry integration.""" await help_test_entity_device_info_with_connection( - hass, mqtt_mock_entry_no_yaml_config, update.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, update.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_with_identifier( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT update device registry integration.""" await help_test_entity_device_info_with_identifier( - hass, mqtt_mock_entry_no_yaml_config, update.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, update.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry update.""" await help_test_entity_device_info_update( - hass, mqtt_mock_entry_no_yaml_config, update.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, update.DOMAIN, DEFAULT_CONFIG ) async def test_entity_device_info_remove( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test device registry remove.""" await help_test_entity_device_info_remove( - hass, mqtt_mock_entry_no_yaml_config, update.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, update.DOMAIN, DEFAULT_CONFIG ) async def test_entity_id_update_discovery_update( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test MQTT discovery update when entity_id is updated.""" await help_test_entity_id_update_discovery_update( - hass, mqtt_mock_entry_no_yaml_config, update.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry, update.DOMAIN, DEFAULT_CONFIG ) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_setup_manual_entity_from_yaml( - hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator ) -> None: """Test setup manual configured MQTT entity.""" - await mqtt_mock_entry_no_yaml_config() + await mqtt_mock_entry() platform = update.DOMAIN assert hass.states.get(f"{platform}.test") async def test_unload_entry( hass: HomeAssistant, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> None: """Test unloading the config entry.""" domain = update.DOMAIN config = DEFAULT_CONFIG await help_test_unload_config_entry_with_platform( - hass, mqtt_mock_entry_no_yaml_config, domain, config + hass, mqtt_mock_entry, domain, config ) diff --git a/tests/conftest.py b/tests/conftest.py index 68a5b0977d4..49cd73f504a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -906,11 +906,11 @@ async def mqtt_mock( mock_hass_config: None, mqtt_client_mock: MqttMockPahoClient, mqtt_config_entry_data: dict[str, Any] | None, - mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry: MqttMockHAClientGenerator, ) -> AsyncGenerator[MqttMockHAClient, None]: """Fixture to mock MQTT component.""" with patch("homeassistant.components.mqtt.PLATFORMS", []): - return await mqtt_mock_entry_no_yaml_config() + return await mqtt_mock_entry() @asynccontextmanager @@ -1043,12 +1043,12 @@ def mock_hass_config_yaml( @pytest.fixture -async def mqtt_mock_entry_no_yaml_config( +async def mqtt_mock_entry( hass: HomeAssistant, mqtt_client_mock: MqttMockPahoClient, mqtt_config_entry_data: dict[str, Any] | None, ) -> AsyncGenerator[MqttMockHAClientGenerator, None]: - """Set up an MQTT config entry without MQTT yaml config.""" + """Set up an MQTT config entry.""" async def _async_setup_config_entry( hass: HomeAssistant, entry: ConfigEntry @@ -1068,30 +1068,6 @@ async def mqtt_mock_entry_no_yaml_config( yield _setup_mqtt_entry -@pytest.fixture -async def mqtt_mock_entry_with_yaml_config( - hass: HomeAssistant, - mqtt_client_mock: MqttMockPahoClient, - mqtt_config_entry_data: dict[str, Any] | None, -) -> AsyncGenerator[MqttMockHAClientGenerator, None]: - """Set up an MQTT config entry with MQTT yaml config.""" - - async def _async_do_not_setup_config_entry( - hass: HomeAssistant, entry: ConfigEntry - ) -> bool: - """Do nothing.""" - return True - - async def _setup_mqtt_entry() -> MqttMockHAClient: - """Set up the MQTT config entry.""" - return await mqtt_mock_entry(_async_do_not_setup_config_entry) - - async with _mqtt_mock_entry( - hass, mqtt_client_mock, mqtt_config_entry_data - ) as mqtt_mock_entry: - yield _setup_mqtt_entry - - @pytest.fixture(autouse=True) def mock_network() -> Generator[None, None, None]: """Mock network."""