Rename MQTT entry mock and cleanup (#91223)

Rename to mqtt_mock_entry and cleanup
This commit is contained in:
Jan Bouwhuis 2023-04-12 09:43:03 +02:00 committed by GitHub
parent b7cc42d135
commit bb15923968
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 2275 additions and 2322 deletions

View File

@ -135,8 +135,7 @@ _TEST_FIXTURES: dict[str, list[str] | str] = {
"mock_zeroconf": "None", "mock_zeroconf": "None",
"mqtt_client_mock": "MqttMockPahoClient", "mqtt_client_mock": "MqttMockPahoClient",
"mqtt_mock": "MqttMockHAClient", "mqtt_mock": "MqttMockHAClient",
"mqtt_mock_entry_no_yaml_config": "MqttMockHAClientGenerator", "mqtt_mock_entry": "MqttMockHAClientGenerator",
"mqtt_mock_entry_with_yaml_config": "MqttMockHAClientGenerator",
"recorder_db_url": "str", "recorder_db_url": "str",
"recorder_mock": "Recorder", "recorder_mock": "Recorder",
"requests_mock": "requests_mock.Mocker", "requests_mock": "requests_mock.Mocker",

View File

@ -178,10 +178,10 @@ async def test_fail_setup_without_state_or_command_topic(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_update_state_via_state_topic( async def test_update_state_via_state_topic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test updating with via state topic.""" """Test updating with via state topic."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
await hass.async_block_till_done() await hass.async_block_till_done()
entity_id = "alarm_control_panel.test" 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]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_ignore_update_state_if_unknown_via_state_topic( 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: ) -> None:
"""Test ignoring updates via state topic.""" """Test ignoring updates via state topic."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
entity_id = "alarm_control_panel.test" 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( async def test_publish_mqtt_no_code(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
service, service,
payload, payload,
) -> None: ) -> None:
"""Test publishing of MQTT messages when no code is configured.""" """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( await hass.services.async_call(
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
@ -264,12 +264,12 @@ async def test_publish_mqtt_no_code(
) )
async def test_publish_mqtt_with_code( async def test_publish_mqtt_with_code(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
service, service,
payload, payload,
) -> None: ) -> None:
"""Test publishing of MQTT messages when code is configured.""" """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 call_count = mqtt_mock.async_publish.call_count
# No code provided, should not publish # 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( async def test_publish_mqtt_with_remote_code(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
service, service,
payload, payload,
) -> None: ) -> None:
"""Test publishing of MQTT messages when remode code is configured.""" """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 call_count = mqtt_mock.async_publish.call_count
# No code provided, should not publish # 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( async def test_publish_mqtt_with_remote_code_text(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
service: str, service: str,
payload: str, payload: str,
) -> None: ) -> None:
"""Test publishing of MQTT messages when remote text code is configured.""" """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 call_count = mqtt_mock.async_publish.call_count
# No code provided, should not publish # 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( async def test_publish_mqtt_with_code_required_false(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
service: str, service: str,
payload: str, payload: str,
) -> None: ) -> None:
@ -469,7 +469,7 @@ async def test_publish_mqtt_with_code_required_false(
code_arm_required = False / code_disarm_required = False / code_arm_required = False / code_disarm_required = False /
code_trigger_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 # No code provided, should publish
await hass.services.async_call( 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( async def test_disarm_publishes_mqtt_with_template(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test publishing of MQTT messages while disarmed. """Test publishing of MQTT messages while disarmed.
When command_template set to output json 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") await common.async_alarm_disarm(hass, "0123")
mqtt_mock.async_publish.assert_called_once_with( 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( 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: ) -> None:
"""Test updating with template_value via state topic.""" """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") state = hass.states.get("alarm_control_panel.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -576,10 +576,10 @@ async def test_update_state_via_state_topic_template(
], ],
) )
async def test_attributes_code_number( async def test_attributes_code_number(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test attributes which are not supported by the vacuum.""" """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") state = hass.states.get("alarm_control_panel.test")
assert ( assert (
@ -599,10 +599,10 @@ async def test_attributes_code_number(
], ],
) )
async def test_attributes_remote_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: ) -> None:
"""Test attributes which are not supported by the vacuum.""" """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") state = hass.states.get("alarm_control_panel.test")
assert ( assert (
@ -620,10 +620,10 @@ async def test_attributes_remote_code_number(
], ],
) )
async def test_attributes_code_text( async def test_attributes_code_text(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test attributes which are not supported by the vacuum.""" """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") state = hass.states.get("alarm_control_panel.test")
assert ( assert (
@ -634,70 +634,70 @@ async def test_attributes_code_text(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_CODE]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_CODE])
async def test_availability_when_connection_lost( async def test_availability_when_connection_lost(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_no_yaml_config, alarm_control_panel.DOMAIN hass, mqtt_mock_entry, alarm_control_panel.DOMAIN
) )
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_CODE]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_CODE])
async def test_availability_without_topic( async def test_availability_without_topic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
DEFAULT_CONFIG_CODE, DEFAULT_CONFIG_CODE,
) )
async def test_default_availability_payload( async def test_default_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
await help_test_default_availability_payload( await help_test_default_availability_payload(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
DEFAULT_CONFIG_CODE, DEFAULT_CONFIG_CODE,
) )
async def test_custom_availability_payload( async def test_custom_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by custom payload with defined topic.""" """Test availability by custom payload with defined topic."""
await help_test_custom_availability_payload( await help_test_custom_availability_payload(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
) )
async def test_setting_attribute_via_mqtt_json_message( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message( await help_test_setting_attribute_via_mqtt_json_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
) )
async def test_setting_blocked_attribute_via_mqtt_json_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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_blocked_attribute_via_mqtt_json_message( await help_test_setting_blocked_attribute_via_mqtt_json_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
MQTT_ALARM_ATTRIBUTES_BLOCKED, 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( async def test_setting_attribute_with_template(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template( await help_test_setting_attribute_with_template(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
) )
@ -718,13 +718,13 @@ async def test_setting_attribute_with_template(
async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_not_dict(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_not_dict( await help_test_update_with_json_attrs_not_dict(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -733,13 +733,13 @@ async def test_update_with_json_attrs_not_dict(
async def test_update_with_json_attrs_bad_json( async def test_update_with_json_attrs_bad_json(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_json( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -748,13 +748,13 @@ async def test_update_with_json_attrs_bad_json(
async def test_discovery_update_attr( async def test_discovery_update_attr(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered MQTTAttributes.""" """Test update of discovered MQTTAttributes."""
await help_test_discovery_update_attr( await help_test_discovery_update_attr(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -785,29 +785,27 @@ async def test_discovery_update_attr(
], ],
) )
async def test_unique_id( async def test_unique_id(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test unique id option only creates one alarm per unique_id.""" """Test unique id option only creates one alarm per unique_id."""
await help_test_unique_id( await help_test_unique_id(hass, mqtt_mock_entry, alarm_control_panel.DOMAIN)
hass, mqtt_mock_entry_no_yaml_config, alarm_control_panel.DOMAIN
)
async def test_discovery_removal_alarm( async def test_discovery_removal_alarm(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test removal of discovered alarm_control_panel.""" """Test removal of discovered alarm_control_panel."""
data = json.dumps(DEFAULT_CONFIG[mqtt.DOMAIN][alarm_control_panel.DOMAIN]) data = json.dumps(DEFAULT_CONFIG[mqtt.DOMAIN][alarm_control_panel.DOMAIN])
await help_test_discovery_removal( await help_test_discovery_removal(
hass, mqtt_mock_entry_no_yaml_config, caplog, alarm_control_panel.DOMAIN, data hass, mqtt_mock_entry, caplog, alarm_control_panel.DOMAIN, data
) )
async def test_discovery_update_alarm_topic_and_template( async def test_discovery_update_alarm_topic_and_template(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered alarm_control_panel.""" """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( await help_test_discovery_update(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
config1, config1,
@ -844,7 +842,7 @@ async def test_discovery_update_alarm_topic_and_template(
async def test_discovery_update_alarm_template( async def test_discovery_update_alarm_template(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered alarm_control_panel.""" """Test update of discovered alarm_control_panel."""
@ -867,7 +865,7 @@ async def test_discovery_update_alarm_template(
await help_test_discovery_update( await help_test_discovery_update(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
config1, config1,
@ -879,7 +877,7 @@ async def test_discovery_update_alarm_template(
async def test_discovery_update_unchanged_alarm( async def test_discovery_update_unchanged_alarm(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered alarm_control_panel.""" """Test update of discovered alarm_control_panel."""
@ -892,7 +890,7 @@ async def test_discovery_update_unchanged_alarm(
) as discovery_update: ) as discovery_update:
await help_test_discovery_update_unchanged( await help_test_discovery_update_unchanged(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
data1, data1,
@ -903,7 +901,7 @@ async def test_discovery_update_unchanged_alarm(
@pytest.mark.no_fail_on_log_exception @pytest.mark.no_fail_on_log_exception
async def test_discovery_broken( async def test_discovery_broken(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test handling of bad discovery message.""" """Test handling of bad discovery message."""
@ -915,7 +913,7 @@ async def test_discovery_broken(
) )
await help_test_discovery_broken( await help_test_discovery_broken(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
data1, data1,
@ -932,14 +930,14 @@ async def test_discovery_broken(
) )
async def test_encoding_subscribable_topics( async def test_encoding_subscribable_topics(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
topic: str, topic: str,
value: str, value: str,
) -> None: ) -> None:
"""Test handling of incoming encoded payload.""" """Test handling of incoming encoded payload."""
await help_test_encoding_subscribable_topics( await help_test_encoding_subscribable_topics(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
DEFAULT_CONFIG[mqtt.DOMAIN][alarm_control_panel.DOMAIN], DEFAULT_CONFIG[mqtt.DOMAIN][alarm_control_panel.DOMAIN],
topic, topic,
@ -948,81 +946,81 @@ async def test_encoding_subscribable_topics(
async def test_entity_device_info_with_connection( async def test_entity_device_info_with_connection(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT alarm control panel device registry integration.""" """Test MQTT alarm control panel device registry integration."""
await help_test_entity_device_info_with_connection( await help_test_entity_device_info_with_connection(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
) )
async def test_entity_device_info_with_identifier( async def test_entity_device_info_with_identifier(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT alarm control panel device registry integration.""" """Test MQTT alarm control panel device registry integration."""
await help_test_entity_device_info_with_identifier( await help_test_entity_device_info_with_identifier(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
) )
async def test_entity_device_info_update( async def test_entity_device_info_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry update.""" """Test device registry update."""
await help_test_entity_device_info_update( await help_test_entity_device_info_update(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
) )
async def test_entity_device_info_remove( async def test_entity_device_info_remove(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry remove.""" """Test device registry remove."""
await help_test_entity_device_info_remove( await help_test_entity_device_info_remove(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
) )
async def test_entity_id_update_subscriptions( async def test_entity_id_update_subscriptions(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT subscriptions are managed when entity_id is updated.""" """Test MQTT subscriptions are managed when entity_id is updated."""
await help_test_entity_id_update_subscriptions( await help_test_entity_id_update_subscriptions(
hass, mqtt_mock_entry_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( async def test_entity_id_update_discovery_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT discovery update when entity_id is updated.""" """Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update( await help_test_entity_id_update_discovery_update(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
) )
async def test_entity_debug_info_message( async def test_entity_debug_info_message(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT debug info.""" """Test MQTT debug info."""
await help_test_entity_debug_info_message( await help_test_entity_debug_info_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
alarm_control_panel.DOMAIN, alarm_control_panel.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
alarm_control_panel.SERVICE_ALARM_DISARM, alarm_control_panel.SERVICE_ALARM_DISARM,
@ -1055,7 +1053,7 @@ async def test_entity_debug_info_message(
) )
async def test_publishing_with_custom_encoding( async def test_publishing_with_custom_encoding(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
service: str, service: str,
topic: str, topic: str,
@ -1071,7 +1069,7 @@ async def test_publishing_with_custom_encoding(
await help_test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
domain, domain,
config, config,
@ -1097,21 +1095,21 @@ async def test_reloadable(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_setup_manual_entity_from_yaml( async def test_setup_manual_entity_from_yaml(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
platform = alarm_control_panel.DOMAIN platform = alarm_control_panel.DOMAIN
assert hass.states.get(f"{platform}.test") assert hass.states.get(f"{platform}.test")
async def test_unload_entry( async def test_unload_entry(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = alarm_control_panel.DOMAIN domain = alarm_control_panel.DOMAIN
config = DEFAULT_CONFIG config = DEFAULT_CONFIG
await help_test_unload_config_entry_with_platform( await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_no_yaml_config, domain, config hass, mqtt_mock_entry, domain, config
) )

View File

@ -93,11 +93,11 @@ def binary_sensor_platform_only():
) )
async def test_setting_sensor_value_expires_availability_topic( async def test_setting_sensor_value_expires_availability_topic(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test the expiration of the value.""" """Test the expiration of the value."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get("binary_sensor.test") state = hass.states.get("binary_sensor.test")
assert state.state == STATE_UNAVAILABLE 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( async def test_setting_sensor_value_expires(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test the expiration of the value.""" """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 should be unavailable since expire_after is defined and > 0
state = hass.states.get("binary_sensor.test") 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( async def test_expiration_on_discovery_and_discovery_update_of_binary_sensor(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test that binary_sensor with expire_after set behaves correctly on discovery and discovery update.""" """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 = { config = {
"name": "Test", "name": "Test",
"state_topic": "test-topic", "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( 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: ) -> None:
"""Test the setting of the value via MQTT.""" """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") 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( async def test_invalid_sensor_value_via_mqtt_message(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test the setting of the value via MQTT.""" """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") 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( 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: ) -> None:
"""Test the setting of the value via MQTT.""" """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") state = hass.states.get("binary_sensor.test")
assert state.state == STATE_UNKNOWN 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( async def test_setting_sensor_value_via_mqtt_message_and_template2(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test the setting of the value via MQTT.""" """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") state = hass.states.get("binary_sensor.test")
assert state.state == STATE_UNKNOWN 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( async def test_setting_sensor_value_via_mqtt_message_and_template_and_raw_state_encoding(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test processing a raw value via MQTT.""" """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") state = hass.states.get("binary_sensor.test")
assert state.state == STATE_UNKNOWN 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( 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: ) -> None:
"""Test the setting of the value via MQTT.""" """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") state = hass.states.get("binary_sensor.test")
assert state.state == STATE_UNKNOWN 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( async def test_valid_device_class(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the setting of a valid sensor class.""" """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") state = hass.states.get("binary_sensor.test")
assert state.attributes.get("device_class") == "motion" assert state.attributes.get("device_class") == "motion"
@ -545,49 +545,49 @@ async def test_valid_device_class(
async def test_invalid_device_class( async def test_invalid_device_class(
hass: HomeAssistant, hass: HomeAssistant,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test the setting of an invalid sensor class.""" """Test the setting of an invalid sensor class."""
with pytest.raises(AssertionError): 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 assert "Invalid config for [mqtt]: expected BinarySensorDeviceClass" in caplog.text
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_availability_when_connection_lost( async def test_availability_when_connection_lost(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_no_yaml_config, binary_sensor.DOMAIN hass, mqtt_mock_entry, binary_sensor.DOMAIN
) )
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_availability_without_topic( async def test_availability_without_topic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_no_yaml_config, binary_sensor.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, binary_sensor.DOMAIN, DEFAULT_CONFIG
) )
async def test_default_availability_payload( async def test_default_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
await help_test_default_availability_payload( await help_test_default_availability_payload(
hass, mqtt_mock_entry_no_yaml_config, binary_sensor.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, binary_sensor.DOMAIN, DEFAULT_CONFIG
) )
async def test_custom_availability_payload( async def test_custom_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by custom payload with defined topic.""" """Test availability by custom payload with defined topic."""
await help_test_custom_availability_payload( await help_test_custom_availability_payload(
hass, mqtt_mock_entry_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( async def test_force_update_disabled(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test force update option.""" """Test force update option."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
events = [] events = []
@ -647,10 +647,10 @@ async def test_force_update_disabled(
], ],
) )
async def test_force_update_enabled( async def test_force_update_enabled(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test force update option.""" """Test force update option."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
events = [] events = []
@ -688,10 +688,10 @@ async def test_force_update_enabled(
], ],
) )
async def test_off_delay( async def test_off_delay(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test off_delay option.""" """Test off_delay option."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
events = [] events = []
@ -722,21 +722,21 @@ async def test_off_delay(
async def test_setting_attribute_via_mqtt_json_message( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message( await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_no_yaml_config, binary_sensor.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, binary_sensor.DOMAIN, DEFAULT_CONFIG
) )
async def test_setting_attribute_with_template( async def test_setting_attribute_with_template(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template( await help_test_setting_attribute_with_template(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
binary_sensor.DOMAIN, binary_sensor.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
) )
@ -744,13 +744,13 @@ async def test_setting_attribute_with_template(
async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_not_dict(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_not_dict( await help_test_update_with_json_attrs_not_dict(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
binary_sensor.DOMAIN, binary_sensor.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -759,13 +759,13 @@ async def test_update_with_json_attrs_not_dict(
async def test_update_with_json_attrs_bad_json( async def test_update_with_json_attrs_bad_json(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_json( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
binary_sensor.DOMAIN, binary_sensor.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -774,13 +774,13 @@ async def test_update_with_json_attrs_bad_json(
async def test_discovery_update_attr( async def test_discovery_update_attr(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered MQTTAttributes.""" """Test update of discovered MQTTAttributes."""
await help_test_discovery_update_attr( await help_test_discovery_update_attr(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
binary_sensor.DOMAIN, binary_sensor.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -809,29 +809,27 @@ async def test_discovery_update_attr(
], ],
) )
async def test_unique_id( async def test_unique_id(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test unique id option only creates one sensor per unique_id.""" """Test unique id option only creates one sensor per unique_id."""
await help_test_unique_id( await help_test_unique_id(hass, mqtt_mock_entry, binary_sensor.DOMAIN)
hass, mqtt_mock_entry_no_yaml_config, binary_sensor.DOMAIN
)
async def test_discovery_removal_binary_sensor( async def test_discovery_removal_binary_sensor(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test removal of discovered binary_sensor.""" """Test removal of discovered binary_sensor."""
data = json.dumps(DEFAULT_CONFIG[mqtt.DOMAIN][binary_sensor.DOMAIN]) data = json.dumps(DEFAULT_CONFIG[mqtt.DOMAIN][binary_sensor.DOMAIN])
await help_test_discovery_removal( await help_test_discovery_removal(
hass, mqtt_mock_entry_no_yaml_config, caplog, binary_sensor.DOMAIN, data hass, mqtt_mock_entry, caplog, binary_sensor.DOMAIN, data
) )
async def test_discovery_update_binary_sensor_topic_template( async def test_discovery_update_binary_sensor_topic_template(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered binary_sensor.""" """Test update of discovered binary_sensor."""
@ -858,7 +856,7 @@ async def test_discovery_update_binary_sensor_topic_template(
await help_test_discovery_update( await help_test_discovery_update(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
binary_sensor.DOMAIN, binary_sensor.DOMAIN,
config1, config1,
@ -870,7 +868,7 @@ async def test_discovery_update_binary_sensor_topic_template(
async def test_discovery_update_binary_sensor_template( async def test_discovery_update_binary_sensor_template(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered binary_sensor.""" """Test update of discovered binary_sensor."""
@ -895,7 +893,7 @@ async def test_discovery_update_binary_sensor_template(
await help_test_discovery_update( await help_test_discovery_update(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
binary_sensor.DOMAIN, binary_sensor.DOMAIN,
config1, config1,
@ -920,7 +918,7 @@ async def test_discovery_update_binary_sensor_template(
) )
async def test_encoding_subscribable_topics( async def test_encoding_subscribable_topics(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
topic: str, topic: str,
value: str, value: str,
attribute: str | None, attribute: str | None,
@ -929,7 +927,7 @@ async def test_encoding_subscribable_topics(
"""Test handling of incoming encoded payload.""" """Test handling of incoming encoded payload."""
await help_test_encoding_subscribable_topics( await help_test_encoding_subscribable_topics(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
binary_sensor.DOMAIN, binary_sensor.DOMAIN,
DEFAULT_CONFIG[mqtt.DOMAIN][binary_sensor.DOMAIN], DEFAULT_CONFIG[mqtt.DOMAIN][binary_sensor.DOMAIN],
topic, topic,
@ -941,7 +939,7 @@ async def test_encoding_subscribable_topics(
async def test_discovery_update_unchanged_binary_sensor( async def test_discovery_update_unchanged_binary_sensor(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered binary_sensor.""" """Test update of discovered binary_sensor."""
@ -954,7 +952,7 @@ async def test_discovery_update_unchanged_binary_sensor(
) as discovery_update: ) as discovery_update:
await help_test_discovery_update_unchanged( await help_test_discovery_update_unchanged(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
binary_sensor.DOMAIN, binary_sensor.DOMAIN,
data1, data1,
@ -965,7 +963,7 @@ async def test_discovery_update_unchanged_binary_sensor(
@pytest.mark.no_fail_on_log_exception @pytest.mark.no_fail_on_log_exception
async def test_discovery_broken( async def test_discovery_broken(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test handling of bad discovery message.""" """Test handling of bad discovery message."""
@ -973,7 +971,7 @@ async def test_discovery_broken(
data2 = '{ "name": "Milk",' ' "state_topic": "test_topic" }' data2 = '{ "name": "Milk",' ' "state_topic": "test_topic" }'
await help_test_discovery_broken( await help_test_discovery_broken(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
binary_sensor.DOMAIN, binary_sensor.DOMAIN,
data1, data1,
@ -982,81 +980,81 @@ async def test_discovery_broken(
async def test_entity_device_info_with_connection( async def test_entity_device_info_with_connection(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT binary sensor device registry integration.""" """Test MQTT binary sensor device registry integration."""
await help_test_entity_device_info_with_connection( await help_test_entity_device_info_with_connection(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
binary_sensor.DOMAIN, binary_sensor.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
) )
async def test_entity_device_info_with_identifier( async def test_entity_device_info_with_identifier(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT binary sensor device registry integration.""" """Test MQTT binary sensor device registry integration."""
await help_test_entity_device_info_with_identifier( await help_test_entity_device_info_with_identifier(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
binary_sensor.DOMAIN, binary_sensor.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
) )
async def test_entity_device_info_update( async def test_entity_device_info_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry update.""" """Test device registry update."""
await help_test_entity_device_info_update( await help_test_entity_device_info_update(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
binary_sensor.DOMAIN, binary_sensor.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
) )
async def test_entity_device_info_remove( async def test_entity_device_info_remove(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry remove.""" """Test device registry remove."""
await help_test_entity_device_info_remove( await help_test_entity_device_info_remove(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
binary_sensor.DOMAIN, binary_sensor.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
) )
async def test_entity_id_update_subscriptions( async def test_entity_id_update_subscriptions(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT subscriptions are managed when entity_id is updated.""" """Test MQTT subscriptions are managed when entity_id is updated."""
await help_test_entity_id_update_subscriptions( await help_test_entity_id_update_subscriptions(
hass, mqtt_mock_entry_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( async def test_entity_id_update_discovery_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT discovery update when entity_id is updated.""" """Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update( await help_test_entity_id_update_discovery_update(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
binary_sensor.DOMAIN, binary_sensor.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
) )
async def test_entity_debug_info_message( async def test_entity_debug_info_message(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT debug info.""" """Test MQTT debug info."""
await help_test_entity_debug_info_message( await help_test_entity_debug_info_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
binary_sensor.DOMAIN, binary_sensor.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
None, None,
@ -1108,7 +1106,7 @@ async def test_reloadable(
) )
async def test_cleanup_triggers_and_restoring_state( async def test_cleanup_triggers_and_restoring_state(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
tmp_path: Path, tmp_path: Path,
freezer: FrozenDateTimeFactory, freezer: FrozenDateTimeFactory,
@ -1121,7 +1119,7 @@ async def test_cleanup_triggers_and_restoring_state(
"""Test cleanup old triggers at reloading and restoring the state.""" """Test cleanup old triggers at reloading and restoring the state."""
freezer.move_to("2022-02-02 12:01:00+01:00") 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) async_fire_mqtt_message(hass, "test-topic1", payload1)
state = hass.states.get("binary_sensor.test1") 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( async def test_skip_restoring_state_with_over_due_expire_trigger(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
freezer: FrozenDateTimeFactory, freezer: FrozenDateTimeFactory,
) -> None: ) -> None:
"""Test restoring a state with over due expire timer.""" """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,)) mock_restore_cache(hass, (fake_state,))
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get("binary_sensor.test3") state = hass.states.get("binary_sensor.test3")
assert state.state == STATE_UNAVAILABLE assert state.state == STATE_UNAVAILABLE
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_setup_manual_entity_from_yaml( async def test_setup_manual_entity_from_yaml(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
platform = binary_sensor.DOMAIN platform = binary_sensor.DOMAIN
assert hass.states.get(f"{platform}.test") assert hass.states.get(f"{platform}.test")
async def test_unload_entry( async def test_unload_entry(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = binary_sensor.DOMAIN domain = binary_sensor.DOMAIN
config = DEFAULT_CONFIG config = DEFAULT_CONFIG
await help_test_unload_config_entry_with_platform( await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_no_yaml_config, domain, config hass, mqtt_mock_entry, domain, config
) )

View File

@ -73,10 +73,10 @@ def button_platform_only():
], ],
) )
async def test_sending_mqtt_commands( async def test_sending_mqtt_commands(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the sending MQTT commands.""" """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") state = hass.states.get("button.test_button")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -113,10 +113,10 @@ async def test_sending_mqtt_commands(
], ],
) )
async def test_command_template( async def test_command_template(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the sending of MQTT commands through a command template.""" """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") state = hass.states.get("button.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -137,26 +137,26 @@ async def test_command_template(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_availability_when_connection_lost( async def test_availability_when_connection_lost(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN hass, mqtt_mock_entry, button.DOMAIN
) )
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_availability_without_topic( async def test_availability_without_topic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, button.DOMAIN, DEFAULT_CONFIG
) )
async def test_default_availability_payload( async def test_default_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
config = { config = {
@ -170,7 +170,7 @@ async def test_default_availability_payload(
} }
await help_test_default_availability_payload( await help_test_default_availability_payload(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
button.DOMAIN, button.DOMAIN,
config, config,
True, True,
@ -180,7 +180,7 @@ async def test_default_availability_payload(
async def test_custom_availability_payload( async def test_custom_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by custom payload with defined topic.""" """Test availability by custom payload with defined topic."""
config = { config = {
@ -195,7 +195,7 @@ async def test_custom_availability_payload(
await help_test_custom_availability_payload( await help_test_custom_availability_payload(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
button.DOMAIN, button.DOMAIN,
config, config,
True, True,
@ -205,41 +205,41 @@ async def test_custom_availability_payload(
async def test_setting_attribute_via_mqtt_json_message( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message( await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_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( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_blocked_attribute_via_mqtt_json_message( await help_test_setting_blocked_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG, None hass, mqtt_mock_entry, button.DOMAIN, DEFAULT_CONFIG, None
) )
async def test_setting_attribute_with_template( async def test_setting_attribute_with_template(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template( await help_test_setting_attribute_with_template(
hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, button.DOMAIN, DEFAULT_CONFIG
) )
async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_not_dict(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_not_dict( await help_test_update_with_json_attrs_not_dict(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
button.DOMAIN, button.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -248,13 +248,13 @@ async def test_update_with_json_attrs_not_dict(
async def test_update_with_json_attrs_bad_json( async def test_update_with_json_attrs_bad_json(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_json( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
button.DOMAIN, button.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -263,13 +263,13 @@ async def test_update_with_json_attrs_bad_json(
async def test_discovery_update_attr( async def test_discovery_update_attr(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered MQTTAttributes.""" """Test update of discovered MQTTAttributes."""
await help_test_discovery_update_attr( await help_test_discovery_update_attr(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
button.DOMAIN, button.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -298,27 +298,27 @@ async def test_discovery_update_attr(
], ],
) )
async def test_unique_id( async def test_unique_id(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test unique id option only creates one button per unique_id.""" """Test unique id option only creates one button per unique_id."""
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( async def test_discovery_removal_button(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test removal of discovered button.""" """Test removal of discovered button."""
data = '{ "name": "test", "command_topic": "test_topic" }' data = '{ "name": "test", "command_topic": "test_topic" }'
await help_test_discovery_removal( 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( async def test_discovery_update_button(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered button.""" """Test update of discovered button."""
@ -329,7 +329,7 @@ async def test_discovery_update_button(
await help_test_discovery_update( await help_test_discovery_update(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
button.DOMAIN, button.DOMAIN,
config1, config1,
@ -339,7 +339,7 @@ async def test_discovery_update_button(
async def test_discovery_update_unchanged_button( async def test_discovery_update_unchanged_button(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered button.""" """Test update of discovered button."""
@ -353,7 +353,7 @@ async def test_discovery_update_unchanged_button(
) as discovery_update: ) as discovery_update:
await help_test_discovery_update_unchanged( await help_test_discovery_update_unchanged(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
button.DOMAIN, button.DOMAIN,
data1, data1,
@ -364,69 +364,69 @@ async def test_discovery_update_unchanged_button(
@pytest.mark.no_fail_on_log_exception @pytest.mark.no_fail_on_log_exception
async def test_discovery_broken( async def test_discovery_broken(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test handling of bad discovery message.""" """Test handling of bad discovery message."""
data1 = '{ "name": "Beer" }' data1 = '{ "name": "Beer" }'
data2 = '{ "name": "Milk", "command_topic": "test_topic" }' data2 = '{ "name": "Milk", "command_topic": "test_topic" }'
await help_test_discovery_broken( 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( async def test_entity_device_info_with_connection(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT button device registry integration.""" """Test MQTT button device registry integration."""
await help_test_entity_device_info_with_connection( await help_test_entity_device_info_with_connection(
hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, button.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_with_identifier( async def test_entity_device_info_with_identifier(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT button device registry integration.""" """Test MQTT button device registry integration."""
await help_test_entity_device_info_with_identifier( await help_test_entity_device_info_with_identifier(
hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, button.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_update( async def test_entity_device_info_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry update.""" """Test device registry update."""
await help_test_entity_device_info_update( await help_test_entity_device_info_update(
hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, button.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_remove( async def test_entity_device_info_remove(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry remove.""" """Test device registry remove."""
await help_test_entity_device_info_remove( await help_test_entity_device_info_remove(
hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, button.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_discovery_update( async def test_entity_id_update_discovery_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT discovery update when entity_id is updated.""" """Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update( await help_test_entity_id_update_discovery_update(
hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, button.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_debug_info_message( async def test_entity_debug_info_message(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT debug info.""" """Test MQTT debug info."""
await help_test_entity_debug_info_message( await help_test_entity_debug_info_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
button.DOMAIN, button.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
button.SERVICE_PRESS, button.SERVICE_PRESS,
@ -450,11 +450,11 @@ async def test_entity_debug_info_message(
], ],
) )
async def test_invalid_device_class( async def test_invalid_device_class(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device_class option with invalid value.""" """Test device_class option with invalid value."""
with pytest.raises(AssertionError): with pytest.raises(AssertionError):
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -483,10 +483,10 @@ async def test_invalid_device_class(
], ],
) )
async def test_valid_device_class( async def test_valid_device_class(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device_class option with valid values.""" """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") state = hass.states.get("button.test_1")
assert state.attributes["device_class"] == button.ButtonDeviceClass.UPDATE 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( async def test_publishing_with_custom_encoding(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
service: str, service: str,
topic: str, topic: str,
@ -518,7 +518,7 @@ async def test_publishing_with_custom_encoding(
await help_test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
domain, domain,
config, config,
@ -542,21 +542,21 @@ async def test_reloadable(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_setup_manual_entity_from_yaml( async def test_setup_manual_entity_from_yaml(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
platform = button.DOMAIN platform = button.DOMAIN
assert hass.states.get(f"{platform}.test") assert hass.states.get(f"{platform}.test")
async def test_unload_entry( async def test_unload_entry(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = button.DOMAIN domain = button.DOMAIN
config = DEFAULT_CONFIG config = DEFAULT_CONFIG
await help_test_unload_config_entry_with_platform( await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_no_yaml_config, domain, config hass, mqtt_mock_entry, domain, config
) )

View File

@ -62,11 +62,11 @@ def camera_platform_only():
async def test_run_camera_setup( async def test_run_camera_setup(
hass: HomeAssistant, hass: HomeAssistant,
hass_client_no_auth: ClientSessionGenerator, hass_client_no_auth: ClientSessionGenerator,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test that it fetches the given payload.""" """Test that it fetches the given payload."""
topic = "test/camera" topic = "test/camera"
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
url = hass.states.get("camera.test_camera").attributes["entity_picture"] 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( async def test_run_camera_b64_encoded(
hass: HomeAssistant, hass: HomeAssistant,
hass_client_no_auth: ClientSessionGenerator, hass_client_no_auth: ClientSessionGenerator,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test that it fetches the given encoded payload.""" """Test that it fetches the given encoded payload."""
topic = "test/camera" topic = "test/camera"
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
url = hass.states.get("camera.test_camera").attributes["entity_picture"] 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( async def test_camera_b64_encoded_with_availability(
hass: HomeAssistant, hass: HomeAssistant,
hass_client_no_auth: ClientSessionGenerator, hass_client_no_auth: ClientSessionGenerator,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test availability works if b64 encoding is turned on.""" """Test availability works if b64 encoding is turned on."""
topic = "test/camera" topic = "test/camera"
topic_availability = "test/camera_availability" topic_availability = "test/camera_availability"
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
# Make sure we are available # Make sure we are available
async_fire_mqtt_message(hass, topic_availability, "online") 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]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_availability_when_connection_lost( async def test_availability_when_connection_lost(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN hass, mqtt_mock_entry, camera.DOMAIN
) )
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_availability_without_topic( async def test_availability_without_topic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, camera.DOMAIN, DEFAULT_CONFIG
) )
async def test_default_availability_payload( async def test_default_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
await help_test_default_availability_payload( await help_test_default_availability_payload(
hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, camera.DOMAIN, DEFAULT_CONFIG
) )
async def test_custom_availability_payload( async def test_custom_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by custom payload with defined topic.""" """Test availability by custom payload with defined topic."""
await help_test_custom_availability_payload( await help_test_custom_availability_payload(
hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, camera.DOMAIN, DEFAULT_CONFIG
) )
async def test_setting_attribute_via_mqtt_json_message( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message( await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_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( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_blocked_attribute_via_mqtt_json_message( await help_test_setting_blocked_attribute_via_mqtt_json_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
camera.DOMAIN, camera.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
MQTT_CAMERA_ATTRIBUTES_BLOCKED, 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( async def test_setting_attribute_with_template(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template( await help_test_setting_attribute_with_template(
hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, camera.DOMAIN, DEFAULT_CONFIG
) )
async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_not_dict(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_not_dict( await help_test_update_with_json_attrs_not_dict(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
camera.DOMAIN, camera.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -239,13 +239,13 @@ async def test_update_with_json_attrs_not_dict(
async def test_update_with_json_attrs_bad_json( async def test_update_with_json_attrs_bad_json(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_json( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
camera.DOMAIN, camera.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -254,13 +254,13 @@ async def test_update_with_json_attrs_bad_json(
async def test_discovery_update_attr( async def test_discovery_update_attr(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered MQTTAttributes.""" """Test update of discovered MQTTAttributes."""
await help_test_discovery_update_attr( await help_test_discovery_update_attr(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
camera.DOMAIN, camera.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -289,27 +289,27 @@ async def test_discovery_update_attr(
], ],
) )
async def test_unique_id( async def test_unique_id(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test unique id option only creates one camera per unique_id.""" """Test unique id option only creates one camera per unique_id."""
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( async def test_discovery_removal_camera(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test removal of discovered camera.""" """Test removal of discovered camera."""
data = json.dumps(DEFAULT_CONFIG[mqtt.DOMAIN][camera.DOMAIN]) data = json.dumps(DEFAULT_CONFIG[mqtt.DOMAIN][camera.DOMAIN])
await help_test_discovery_removal( await help_test_discovery_removal(
hass, mqtt_mock_entry_no_yaml_config, caplog, camera.DOMAIN, data hass, mqtt_mock_entry, caplog, camera.DOMAIN, data
) )
async def test_discovery_update_camera( async def test_discovery_update_camera(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered camera.""" """Test update of discovered camera."""
@ -317,13 +317,13 @@ async def test_discovery_update_camera(
config2 = {"name": "Milk", "topic": "test_topic"} config2 = {"name": "Milk", "topic": "test_topic"}
await help_test_discovery_update( 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( async def test_discovery_update_unchanged_camera(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered camera.""" """Test update of discovered camera."""
@ -333,7 +333,7 @@ async def test_discovery_update_unchanged_camera(
) as discovery_update: ) as discovery_update:
await help_test_discovery_update_unchanged( await help_test_discovery_update_unchanged(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
camera.DOMAIN, camera.DOMAIN,
data1, data1,
@ -344,7 +344,7 @@ async def test_discovery_update_unchanged_camera(
@pytest.mark.no_fail_on_log_exception @pytest.mark.no_fail_on_log_exception
async def test_discovery_broken( async def test_discovery_broken(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test handling of bad discovery message.""" """Test handling of bad discovery message."""
@ -352,53 +352,53 @@ async def test_discovery_broken(
data2 = '{ "name": "Milk", "topic": "test_topic"}' data2 = '{ "name": "Milk", "topic": "test_topic"}'
await help_test_discovery_broken( 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( async def test_entity_device_info_with_connection(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT camera device registry integration.""" """Test MQTT camera device registry integration."""
await help_test_entity_device_info_with_connection( await help_test_entity_device_info_with_connection(
hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, camera.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_with_identifier( async def test_entity_device_info_with_identifier(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT camera device registry integration.""" """Test MQTT camera device registry integration."""
await help_test_entity_device_info_with_identifier( await help_test_entity_device_info_with_identifier(
hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, camera.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_update( async def test_entity_device_info_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry update.""" """Test device registry update."""
await help_test_entity_device_info_update( await help_test_entity_device_info_update(
hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, camera.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_remove( async def test_entity_device_info_remove(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry remove.""" """Test device registry remove."""
await help_test_entity_device_info_remove( await help_test_entity_device_info_remove(
hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, camera.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_subscriptions( async def test_entity_id_update_subscriptions(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT subscriptions are managed when entity_id is updated.""" """Test MQTT subscriptions are managed when entity_id is updated."""
await help_test_entity_id_update_subscriptions( await help_test_entity_id_update_subscriptions(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
camera.DOMAIN, camera.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
["test_topic"], ["test_topic"],
@ -406,21 +406,21 @@ async def test_entity_id_update_subscriptions(
async def test_entity_id_update_discovery_update( async def test_entity_id_update_discovery_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT discovery update when entity_id is updated.""" """Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update( await help_test_entity_id_update_discovery_update(
hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, camera.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_debug_info_message( async def test_entity_debug_info_message(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT debug info.""" """Test MQTT debug info."""
await help_test_entity_debug_info_message( await help_test_entity_debug_info_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
camera.DOMAIN, camera.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
None, None,
@ -441,21 +441,21 @@ async def test_reloadable(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_setup_manual_entity_from_yaml( async def test_setup_manual_entity_from_yaml(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
platform = camera.DOMAIN platform = camera.DOMAIN
assert hass.states.get(f"{platform}.test") assert hass.states.get(f"{platform}.test")
async def test_unload_entry( async def test_unload_entry(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = camera.DOMAIN domain = camera.DOMAIN
config = DEFAULT_CONFIG config = DEFAULT_CONFIG
await help_test_unload_config_entry_with_platform( await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_no_yaml_config, domain, config hass, mqtt_mock_entry, domain, config
) )

View File

@ -104,10 +104,10 @@ def climate_platform_only():
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_setup_params( async def test_setup_params(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the initial parameters.""" """Test the initial parameters."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get(ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("temperature") == 21 assert state.attributes.get("temperature") == 21
@ -133,11 +133,11 @@ async def test_setup_params(
async def test_preset_none_in_preset_modes( async def test_preset_none_in_preset_modes(
hass: HomeAssistant, hass: HomeAssistant,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test the preset mode payload reset configuration.""" """Test the preset mode payload reset configuration."""
with pytest.raises(AssertionError): 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 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]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_supported_features( async def test_supported_features(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the supported_features.""" """Test the supported_features."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get(ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE)
support = ( support = (
@ -232,10 +232,10 @@ async def test_supported_features(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_get_hvac_modes( async def test_get_hvac_modes(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test that the operation list returns the correct modes.""" """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) state = hass.states.get(ENTITY_CLIMATE)
modes = state.attributes.get("hvac_modes") modes = state.attributes.get("hvac_modes")
@ -252,14 +252,14 @@ async def test_get_hvac_modes(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_set_operation_bad_attr_and_state( async def test_set_operation_bad_attr_and_state(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test setting operation mode without required attribute. """Test setting operation mode without required attribute.
Also check the state. Also check the state.
""" """
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get(ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE)
assert state.state == "off" assert state.state == "off"
@ -275,10 +275,10 @@ async def test_set_operation_bad_attr_and_state(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_set_operation( async def test_set_operation(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setting of new operation mode.""" """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) state = hass.states.get(ENTITY_CLIMATE)
assert state.state == "off" assert state.state == "off"
@ -298,11 +298,11 @@ async def test_set_operation(
], ],
) )
async def test_set_operation_pessimistic( async def test_set_operation_pessimistic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setting operation mode in pessimistic mode.""" """Test setting operation mode in pessimistic mode."""
await hass.async_block_till_done() await hass.async_block_till_done()
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get(ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE)
assert state.state == "unknown" assert state.state == "unknown"
@ -331,10 +331,10 @@ async def test_set_operation_pessimistic(
], ],
) )
async def test_set_operation_optimistic( async def test_set_operation_optimistic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setting operation mode in optimistic mode.""" """Test setting operation mode in optimistic mode."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get(ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE)
assert state.state == "off" assert state.state == "off"
@ -364,10 +364,10 @@ async def test_set_operation_optimistic(
], ],
) )
async def test_set_operation_with_power_command( async def test_set_operation_with_power_command(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setting of new operation mode with power command enabled.""" """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) state = hass.states.get(ENTITY_CLIMATE)
assert state.state == "off" assert state.state == "off"
@ -391,11 +391,11 @@ async def test_set_operation_with_power_command(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_set_fan_mode_bad_attr( async def test_set_fan_mode_bad_attr(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test setting fan mode without required attribute.""" """Test setting fan mode without required attribute."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get(ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("fan_mode") == "low" 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( async def test_set_fan_mode_pessimistic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setting of new fan mode in pessimistic mode.""" """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) state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("fan_mode") is None 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( async def test_set_fan_mode_optimistic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setting of new fan mode in optimistic mode.""" """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) state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("fan_mode") == "low" 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]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_set_fan_mode( async def test_set_fan_mode(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setting of new fan mode.""" """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) state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("fan_mode") == "low" assert state.attributes.get("fan_mode") == "low"
@ -488,11 +488,11 @@ async def test_set_fan_mode(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_set_swing_mode_bad_attr( async def test_set_swing_mode_bad_attr(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test setting swing mode without required attribute.""" """Test setting swing mode without required attribute."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get(ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("swing_mode") == "off" 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( async def test_set_swing_pessimistic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setting swing mode in pessimistic mode.""" """Test setting swing mode in pessimistic mode."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get(ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("swing_mode") is None assert state.attributes.get("swing_mode") is None
@ -546,10 +546,10 @@ async def test_set_swing_pessimistic(
], ],
) )
async def test_set_swing_optimistic( async def test_set_swing_optimistic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setting swing mode in optimistic mode.""" """Test setting swing mode in optimistic mode."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get(ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("swing_mode") == "off" assert state.attributes.get("swing_mode") == "off"
@ -569,10 +569,10 @@ async def test_set_swing_optimistic(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_set_swing( async def test_set_swing(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setting of new swing mode.""" """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) state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("swing_mode") == "off" assert state.attributes.get("swing_mode") == "off"
@ -584,10 +584,10 @@ async def test_set_swing(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_set_target_temperature( async def test_set_target_temperature(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setting the target temperature.""" """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) state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("temperature") == 21 assert state.attributes.get("temperature") == 21
@ -622,10 +622,10 @@ async def test_set_target_temperature(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_set_target_humidity( async def test_set_target_humidity(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setting the target humidity.""" """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) state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("humidity") is None assert state.attributes.get("humidity") is None
@ -647,10 +647,10 @@ async def test_set_target_humidity(
], ],
) )
async def test_set_target_temperature_pessimistic( async def test_set_target_temperature_pessimistic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setting the target temperature.""" """Test setting the target temperature."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get(ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("temperature") is None 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( async def test_set_target_temperature_optimistic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setting the target temperature optimistic.""" """Test setting the target temperature optimistic."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get(ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("temperature") == 21 assert state.attributes.get("temperature") == 21
@ -702,10 +702,10 @@ async def test_set_target_temperature_optimistic(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_set_target_temperature_low_high( async def test_set_target_temperature_low_high(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setting the low/high target temperature.""" """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( await common.async_set_temperature(
hass, target_temp_low=20, target_temp_high=23, entity_id=ENTITY_CLIMATE 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( async def test_set_target_temperature_low_highpessimistic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setting the low/high target temperature.""" """Test setting the low/high target temperature."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get(ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("target_temp_low") is None 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( 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: ) -> None:
"""Test setting the low/high target temperature optimistic.""" """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) state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("target_temp_low") == 21 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( async def test_set_target_humidity_optimistic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setting the target humidity optimistic.""" """Test setting the target humidity optimistic."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get(ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("humidity") is None 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( async def test_set_target_humidity_pessimistic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setting the target humidity.""" """Test setting the target humidity."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get(ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("humidity") is None assert state.attributes.get("humidity") is None
@ -891,10 +891,10 @@ async def test_set_target_humidity_pessimistic(
], ],
) )
async def test_receive_mqtt_temperature( async def test_receive_mqtt_temperature(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test getting the current temperature via MQTT.""" """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") async_fire_mqtt_message(hass, "current_temperature", "47")
state = hass.states.get(ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE)
@ -912,10 +912,10 @@ async def test_receive_mqtt_temperature(
], ],
) )
async def test_receive_mqtt_humidity( async def test_receive_mqtt_humidity(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test getting the current humidity via MQTT.""" """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") async_fire_mqtt_message(hass, "current_humidity", "35")
state = hass.states.get(ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE)
@ -933,10 +933,10 @@ async def test_receive_mqtt_humidity(
], ],
) )
async def test_handle_target_humidity_received( async def test_handle_target_humidity_received(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setting the target humidity via MQTT.""" """Test setting the target humidity via MQTT."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get(ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("humidity") is None 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"},))], [help_custom_config(climate.DOMAIN, DEFAULT_CONFIG, ({"action_topic": "action"},))],
) )
async def test_handle_action_received( async def test_handle_action_received(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test getting the action received via MQTT.""" """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)) # Cycle through valid modes and also check for wrong input such as "None" (str(None))
async_fire_mqtt_message(hass, "action", "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]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_set_preset_mode_optimistic( async def test_set_preset_mode_optimistic(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test setting of the preset mode.""" """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) state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("preset_mode") == "none" 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( async def test_set_preset_mode_explicit_optimistic(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test setting of the preset mode.""" """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) state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("preset_mode") == "none" 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( async def test_set_preset_mode_pessimistic(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test setting of the preset mode.""" """Test setting of the preset mode."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get(ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("preset_mode") == "none" assert state.attributes.get("preset_mode") == "none"
@ -1141,10 +1141,10 @@ async def test_set_preset_mode_pessimistic(
], ],
) )
async def test_set_aux_pessimistic( async def test_set_aux_pessimistic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setting of the aux heating in pessimistic mode.""" """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) state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("aux_heat") == "off" assert state.attributes.get("aux_heat") == "off"
@ -1168,10 +1168,10 @@ async def test_set_aux_pessimistic(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_set_aux( async def test_set_aux(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setting of the aux heating.""" """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) state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("aux_heat") == "off" assert state.attributes.get("aux_heat") == "off"
@ -1189,39 +1189,39 @@ async def test_set_aux(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_availability_when_connection_lost( async def test_availability_when_connection_lost(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN hass, mqtt_mock_entry, climate.DOMAIN
) )
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_availability_without_topic( async def test_availability_without_topic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, climate.DOMAIN, DEFAULT_CONFIG
) )
async def test_default_availability_payload( async def test_default_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
await help_test_default_availability_payload( await help_test_default_availability_payload(
hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, climate.DOMAIN, DEFAULT_CONFIG
) )
async def test_custom_availability_payload( async def test_custom_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by custom payload with defined topic.""" """Test availability by custom payload with defined topic."""
await help_test_custom_availability_payload( await help_test_custom_availability_payload(
hass, mqtt_mock_entry_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( async def test_get_target_temperature_low_high_with_templates(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test getting temperature high/low with templates.""" """Test getting temperature high/low with templates."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get(ENTITY_CLIMATE) 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( async def test_get_with_templates(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test getting various attributes with templates.""" """Test getting various attributes with templates."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
# Operation Mode # Operation Mode
state = hass.states.get(ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE)
@ -1507,11 +1507,11 @@ async def test_get_with_templates(
) )
async def test_set_and_templates( async def test_set_and_templates(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test setting various attributes with templates.""" """Test setting various attributes with templates."""
mqtt_mock = await mqtt_mock_entry_no_yaml_config() mqtt_mock = await mqtt_mock_entry()
# Fan Mode # Fan Mode
await common.async_set_fan_mode(hass, "high", ENTITY_CLIMATE) 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},))], [help_custom_config(climate.DOMAIN, DEFAULT_CONFIG, ({"min_temp": 26},))],
) )
async def test_min_temp_custom( async def test_min_temp_custom(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test a custom min temp.""" """Test a custom min temp."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get(ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE)
min_temp = state.attributes.get("min_temp") 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},))], [help_custom_config(climate.DOMAIN, DEFAULT_CONFIG, ({"max_temp": 60},))],
) )
async def test_max_temp_custom( async def test_max_temp_custom(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test a custom max temp.""" """Test a custom max temp."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get(ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE)
max_temp = state.attributes.get("max_temp") 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},))], [help_custom_config(climate.DOMAIN, DEFAULT_CONFIG, ({"min_humidity": 42},))],
) )
async def test_min_humidity_custom( async def test_min_humidity_custom(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test a custom min humidity.""" """Test a custom min humidity."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get(ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE)
min_humidity = state.attributes.get("min_humidity") 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},))], [help_custom_config(climate.DOMAIN, DEFAULT_CONFIG, ({"max_humidity": 58},))],
) )
async def test_max_humidity_custom( async def test_max_humidity_custom(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test a custom max humidity.""" """Test a custom max humidity."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get(ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE)
max_humidity = state.attributes.get("max_humidity") 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},))], [help_custom_config(climate.DOMAIN, DEFAULT_CONFIG, ({"temp_step": 0.01},))],
) )
async def test_temp_step_custom( async def test_temp_step_custom(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test a custom temp step.""" """Test a custom temp step."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get(ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE)
temp_step = state.attributes.get("target_temp_step") temp_step = state.attributes.get("target_temp_step")
@ -1685,10 +1685,10 @@ async def test_temp_step_custom(
], ],
) )
async def test_temperature_unit( async def test_temperature_unit(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test that setting temperature unit converts temperature values.""" """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") 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( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message( await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_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( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_blocked_attribute_via_mqtt_json_message( await help_test_setting_blocked_attribute_via_mqtt_json_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
climate.DOMAIN, climate.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
MQTT_CLIMATE_ATTRIBUTES_BLOCKED, 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( async def test_setting_attribute_with_template(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template( await help_test_setting_attribute_with_template(
hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, climate.DOMAIN, DEFAULT_CONFIG
) )
async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_not_dict(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_not_dict( await help_test_update_with_json_attrs_not_dict(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
climate.DOMAIN, climate.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -1744,13 +1744,13 @@ async def test_update_with_json_attrs_not_dict(
async def test_update_with_json_attrs_bad_json( async def test_update_with_json_attrs_bad_json(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_json( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
climate.DOMAIN, climate.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -1759,13 +1759,13 @@ async def test_update_with_json_attrs_bad_json(
async def test_discovery_update_attr( async def test_discovery_update_attr(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered MQTTAttributes.""" """Test update of discovered MQTTAttributes."""
await help_test_discovery_update_attr( await help_test_discovery_update_attr(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
climate.DOMAIN, climate.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -1796,10 +1796,10 @@ async def test_discovery_update_attr(
], ],
) )
async def test_unique_id( async def test_unique_id(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test unique id option only creates one climate per unique_id.""" """Test unique id option only creates one climate per unique_id."""
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( @pytest.mark.parametrize(
@ -1822,7 +1822,7 @@ async def test_unique_id(
) )
async def test_encoding_subscribable_topics( async def test_encoding_subscribable_topics(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
topic: str, topic: str,
value: str, value: str,
attribute: str | None, attribute: str | None,
@ -1832,7 +1832,7 @@ async def test_encoding_subscribable_topics(
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][climate.DOMAIN]) config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][climate.DOMAIN])
await help_test_encoding_subscribable_topics( await help_test_encoding_subscribable_topics(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
climate.DOMAIN, climate.DOMAIN,
config, config,
topic, topic,
@ -1844,32 +1844,32 @@ async def test_encoding_subscribable_topics(
async def test_discovery_removal_climate( async def test_discovery_removal_climate(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test removal of discovered climate.""" """Test removal of discovered climate."""
data = json.dumps(DEFAULT_CONFIG[mqtt.DOMAIN][climate.DOMAIN]) data = json.dumps(DEFAULT_CONFIG[mqtt.DOMAIN][climate.DOMAIN])
await help_test_discovery_removal( await help_test_discovery_removal(
hass, mqtt_mock_entry_no_yaml_config, caplog, climate.DOMAIN, data hass, mqtt_mock_entry, caplog, climate.DOMAIN, data
) )
async def test_discovery_update_climate( async def test_discovery_update_climate(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered climate.""" """Test update of discovered climate."""
config1 = {"name": "Beer"} config1 = {"name": "Beer"}
config2 = {"name": "Milk"} config2 = {"name": "Milk"}
await help_test_discovery_update( 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( async def test_discovery_update_unchanged_climate(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered climate.""" """Test update of discovered climate."""
@ -1879,7 +1879,7 @@ async def test_discovery_update_unchanged_climate(
) as discovery_update: ) as discovery_update:
await help_test_discovery_update_unchanged( await help_test_discovery_update_unchanged(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
climate.DOMAIN, climate.DOMAIN,
data1, data1,
@ -1890,55 +1890,55 @@ async def test_discovery_update_unchanged_climate(
@pytest.mark.no_fail_on_log_exception @pytest.mark.no_fail_on_log_exception
async def test_discovery_broken( async def test_discovery_broken(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test handling of bad discovery message.""" """Test handling of bad discovery message."""
data1 = '{ "name": "Beer", "power_command_topic": "test_topic#" }' data1 = '{ "name": "Beer", "power_command_topic": "test_topic#" }'
data2 = '{ "name": "Milk", "power_command_topic": "test_topic" }' data2 = '{ "name": "Milk", "power_command_topic": "test_topic" }'
await help_test_discovery_broken( 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( async def test_entity_device_info_with_connection(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT climate device registry integration.""" """Test MQTT climate device registry integration."""
await help_test_entity_device_info_with_connection( await help_test_entity_device_info_with_connection(
hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, climate.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_with_identifier( async def test_entity_device_info_with_identifier(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT climate device registry integration.""" """Test MQTT climate device registry integration."""
await help_test_entity_device_info_with_identifier( await help_test_entity_device_info_with_identifier(
hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, climate.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_update( async def test_entity_device_info_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry update.""" """Test device registry update."""
await help_test_entity_device_info_update( await help_test_entity_device_info_update(
hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, climate.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_remove( async def test_entity_device_info_remove(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry remove.""" """Test device registry remove."""
await help_test_entity_device_info_remove( await help_test_entity_device_info_remove(
hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, climate.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_subscriptions( async def test_entity_id_update_subscriptions(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT subscriptions are managed when entity_id is updated.""" """Test MQTT subscriptions are managed when entity_id is updated."""
config = { config = {
@ -1952,7 +1952,7 @@ async def test_entity_id_update_subscriptions(
} }
await help_test_entity_id_update_subscriptions( await help_test_entity_id_update_subscriptions(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
climate.DOMAIN, climate.DOMAIN,
config, config,
["test-topic", "avty-topic"], ["test-topic", "avty-topic"],
@ -1960,16 +1960,16 @@ async def test_entity_id_update_subscriptions(
async def test_entity_id_update_discovery_update( async def test_entity_id_update_discovery_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT discovery update when entity_id is updated.""" """Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update( await help_test_entity_id_update_discovery_update(
hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, climate.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_debug_info_message( async def test_entity_debug_info_message(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT debug info.""" """Test MQTT debug info."""
config = { config = {
@ -1983,7 +1983,7 @@ async def test_entity_debug_info_message(
} }
await help_test_entity_debug_info_message( await help_test_entity_debug_info_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
climate.DOMAIN, climate.DOMAIN,
config, config,
climate.SERVICE_TURN_ON, climate.SERVICE_TURN_ON,
@ -1995,10 +1995,10 @@ async def test_entity_debug_info_message(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_precision_default( async def test_precision_default(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test that setting precision to tenths works as intended.""" """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( await common.async_set_temperature(
hass, temperature=23.67, entity_id=ENTITY_CLIMATE 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},))], [help_custom_config(climate.DOMAIN, DEFAULT_CONFIG, ({"precision": 0.5},))],
) )
async def test_precision_halves( async def test_precision_halves(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test that setting precision to halves works as intended.""" """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( await common.async_set_temperature(
hass, temperature=23.67, entity_id=ENTITY_CLIMATE 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},))], [help_custom_config(climate.DOMAIN, DEFAULT_CONFIG, ({"precision": 1.0},))],
) )
async def test_precision_whole( async def test_precision_whole(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test that setting precision to whole works as intended.""" """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( await common.async_set_temperature(
hass, temperature=23.67, entity_id=ENTITY_CLIMATE hass, temperature=23.67, entity_id=ENTITY_CLIMATE
@ -2129,7 +2129,7 @@ async def test_precision_whole(
) )
async def test_publishing_with_custom_encoding( async def test_publishing_with_custom_encoding(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
service: str, service: str,
topic: str, topic: str,
@ -2146,7 +2146,7 @@ async def test_publishing_with_custom_encoding(
await help_test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
domain, domain,
config, config,
@ -2224,15 +2224,15 @@ async def test_publishing_with_custom_encoding(
) )
async def test_humidity_configuration_validity( async def test_humidity_configuration_validity(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
valid: bool, valid: bool,
) -> None: ) -> None:
"""Test the validity of humidity configurations.""" """Test the validity of humidity configurations."""
if valid: if valid:
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
return return
with pytest.raises(AssertionError): with pytest.raises(AssertionError):
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
async def test_reloadable( async def test_reloadable(
@ -2247,21 +2247,21 @@ async def test_reloadable(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_setup_manual_entity_from_yaml( async def test_setup_manual_entity_from_yaml(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
platform = climate.DOMAIN platform = climate.DOMAIN
assert hass.states.get(f"{platform}.test") assert hass.states.get(f"{platform}.test")
async def test_unload_entry( async def test_unload_entry(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = climate.DOMAIN domain = climate.DOMAIN
config = DEFAULT_CONFIG config = DEFAULT_CONFIG
await help_test_unload_config_entry_with_platform( await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_no_yaml_config, domain, config hass, mqtt_mock_entry, domain, config
) )

View File

@ -145,11 +145,11 @@ def help_custom_config(
async def help_test_availability_when_connection_lost( async def help_test_availability_when_connection_lost(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
domain: str, domain: str,
) -> None: ) -> None:
"""Test availability after MQTT disconnection.""" """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() await hass.async_block_till_done()
state = hass.states.get(f"{domain}.test") 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( async def help_test_availability_without_topic(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
domain: str, domain: str,
config: ConfigType, config: ConfigType,
) -> None: ) -> None:
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
assert "availability_topic" not in config[mqtt.DOMAIN][domain] 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() await hass.async_block_till_done()
state = hass.states.get(f"{domain}.test") 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( async def help_test_default_availability_list_payload(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
domain: str, domain: str,
config: ConfigType, config: ConfigType,
no_assumed_state: bool = False, no_assumed_state: bool = False,
@ -243,7 +243,7 @@ async def help_test_default_availability_list_payload(
{"topic": "availability-topic1"}, {"topic": "availability-topic1"},
{"topic": "availability-topic2"}, {"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") state = hass.states.get(f"{domain}.test")
assert state and state.state == STATE_UNAVAILABLE 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( async def help_test_default_availability_list_payload_all(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
domain: str, domain: str,
config: ConfigType, config: ConfigType,
no_assumed_state: bool = False, no_assumed_state: bool = False,
@ -304,7 +304,7 @@ async def help_test_default_availability_list_payload_all(
{"topic": "availability-topic1"}, {"topic": "availability-topic1"},
{"topic": "availability-topic2"}, {"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") state = hass.states.get(f"{domain}.test")
assert state and state.state == STATE_UNAVAILABLE 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( async def help_test_default_availability_list_payload_any(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
domain: str, domain: str,
config: ConfigType, config: ConfigType,
no_assumed_state: bool = False, no_assumed_state: bool = False,
@ -366,7 +366,7 @@ async def help_test_default_availability_list_payload_any(
{"topic": "availability-topic1"}, {"topic": "availability-topic1"},
{"topic": "availability-topic2"}, {"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") state = hass.states.get(f"{domain}.test")
assert state and state.state == STATE_UNAVAILABLE 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( async def help_test_custom_availability_payload(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
domain: str, domain: str,
config: ConfigType, config: ConfigType,
no_assumed_state: bool = False, 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]["availability_topic"] = "availability-topic"
config[mqtt.DOMAIN][domain]["payload_available"] = "good" config[mqtt.DOMAIN][domain]["payload_available"] = "good"
config[mqtt.DOMAIN][domain]["payload_not_available"] = "nogood" 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") state = hass.states.get(f"{domain}.test")
assert state and state.state == STATE_UNAVAILABLE 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( async def help_test_discovery_update_availability(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
domain: str, domain: str,
config: ConfigType, config: ConfigType,
) -> None: ) -> None:
@ -484,7 +484,7 @@ async def help_test_discovery_update_availability(
This is a test helper for the MQTTAvailability mixin. 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 # Add availability settings to config
config1 = copy.deepcopy(config) config1 = copy.deepcopy(config)
config1[mqtt.DOMAIN][domain]["availability_topic"] = "availability-topic1" 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( async def help_test_setting_attribute_via_mqtt_json_message(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
domain: str, domain: str,
config: ConfigType, config: ConfigType,
) -> None: ) -> None:
@ -565,7 +565,7 @@ async def help_test_setting_attribute_via_mqtt_json_message(
# Add JSON attributes settings to config # Add JSON attributes settings to config
config = copy.deepcopy(config) config = copy.deepcopy(config)
config[mqtt.DOMAIN][domain]["json_attributes_topic"] = "attr-topic" 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" }') async_fire_mqtt_message(hass, "attr-topic", '{ "val": "100" }')
state = hass.states.get(f"{domain}.test") 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( async def help_test_setting_blocked_attribute_via_mqtt_json_message(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
domain: str, domain: str,
config: ConfigType, config: ConfigType,
extra_blocked_attributes: frozenset[str] | None, 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. 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 []) extra_blocked_attribute_list = list(extra_blocked_attributes or [])
# Add JSON attributes settings to config # 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( async def help_test_setting_attribute_with_template(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
domain: str, domain: str,
config: ConfigType, config: ConfigType,
) -> None: ) -> None:
@ -622,7 +622,7 @@ async def help_test_setting_attribute_with_template(
config[mqtt.DOMAIN][domain][ config[mqtt.DOMAIN][domain][
"json_attributes_template" "json_attributes_template"
] = "{{ value_json['Timer1'] | tojson }}" ] = "{{ 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( async_fire_mqtt_message(
hass, "attr-topic", json.dumps({"Timer1": {"Arm": 0, "Time": "22:18"}}) 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( async def help_test_update_with_json_attrs_not_dict(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
domain: str, domain: str,
config: ConfigType, config: ConfigType,
@ -648,7 +648,7 @@ async def help_test_update_with_json_attrs_not_dict(
# Add JSON attributes settings to config # Add JSON attributes settings to config
config = copy.deepcopy(config) config = copy.deepcopy(config)
config[mqtt.DOMAIN][domain]["json_attributes_topic"] = "attr-topic" 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"]') async_fire_mqtt_message(hass, "attr-topic", '[ "list", "of", "things"]')
state = hass.states.get(f"{domain}.test") 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( async def help_test_update_with_json_attrs_bad_json(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
domain: str, domain: str,
config: ConfigType, config: ConfigType,
@ -671,7 +671,7 @@ async def help_test_update_with_json_attrs_bad_json(
# Add JSON attributes settings to config # Add JSON attributes settings to config
config = copy.deepcopy(config) config = copy.deepcopy(config)
config[mqtt.DOMAIN][domain]["json_attributes_topic"] = "attr-topic" 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") 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( async def help_test_discovery_update_attr(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
domain: str, domain: str,
config: ConfigType, config: ConfigType,
@ -691,7 +691,7 @@ async def help_test_discovery_update_attr(
This is a test helper for the MqttAttributes mixin. 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 # Add JSON attributes settings to config
config1 = copy.deepcopy(config) config1 = copy.deepcopy(config)
config1[mqtt.DOMAIN][domain]["json_attributes_topic"] = "attr-topic1" 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( async def help_test_unique_id(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
domain: str, domain: str,
) -> None: ) -> None:
"""Test unique id option only creates one entity per unique_id.""" """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() await hass.async_block_till_done()
assert len(hass.states.async_entity_ids(domain)) == 1 assert len(hass.states.async_entity_ids(domain)) == 1
async def help_test_discovery_removal( async def help_test_discovery_removal(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
domain: str, domain: str,
data: str, data: str,
@ -743,7 +743,7 @@ async def help_test_discovery_removal(
This is a test helper for the MqttDiscoveryUpdate mixin. 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) async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data)
await hass.async_block_till_done() await hass.async_block_till_done()
@ -760,7 +760,7 @@ async def help_test_discovery_removal(
async def help_test_discovery_update( async def help_test_discovery_update(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog, caplog,
domain, domain,
discovery_config1: DiscoveryInfoType, discovery_config1: DiscoveryInfoType,
@ -772,7 +772,7 @@ async def help_test_discovery_update(
This is a test helper for the MqttDiscoveryUpdate mixin. 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 # Add some future configuration to the configurations
config1 = copy.deepcopy(discovery_config1) config1 = copy.deepcopy(discovery_config1)
config1["some_future_option_1"] = "future_option_1" 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( async def help_test_discovery_update_unchanged(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
domain: str, domain: str,
data1: str, data1: str,
@ -835,7 +835,7 @@ async def help_test_discovery_update_unchanged(
This is a test helper for the MqttDiscoveryUpdate mixin. 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) async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data1)
await hass.async_block_till_done() await hass.async_block_till_done()
@ -851,14 +851,14 @@ async def help_test_discovery_update_unchanged(
async def help_test_discovery_broken( async def help_test_discovery_broken(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
domain: str, domain: str,
data1: str, data1: str,
data2: str, data2: str,
) -> None: ) -> None:
"""Test handling of bad discovery message.""" """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) async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data1)
await hass.async_block_till_done() await hass.async_block_till_done()
@ -877,7 +877,7 @@ async def help_test_discovery_broken(
async def help_test_encoding_subscribable_topics( async def help_test_encoding_subscribable_topics(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
domain: str, domain: str,
config: ConfigType, config: ConfigType,
topic: str, 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_utf8 = init_payload[1].encode("utf-8")
init_payload_value_utf16 = init_payload[1].encode("utf-16") init_payload_value_utf16 = init_payload[1].encode("utf-16")
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
async_fire_mqtt_message( async_fire_mqtt_message(
hass, f"homeassistant/{domain}/item1/config", json.dumps(config1) 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( async def help_test_entity_device_info_with_identifier(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
domain: str, domain: str,
config: ConfigType, config: ConfigType,
) -> None: ) -> None:
@ -1020,7 +1020,7 @@ async def help_test_entity_device_info_with_identifier(
This is a test helper for the MqttDiscoveryUpdate mixin. 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 # Add device settings to config
config = copy.deepcopy(config[mqtt.DOMAIN][domain]) config = copy.deepcopy(config[mqtt.DOMAIN][domain])
config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID) config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID)
@ -1046,7 +1046,7 @@ async def help_test_entity_device_info_with_identifier(
async def help_test_entity_device_info_with_connection( async def help_test_entity_device_info_with_connection(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
domain: str, domain: str,
config: ConfigType, config: ConfigType,
) -> None: ) -> None:
@ -1054,7 +1054,7 @@ async def help_test_entity_device_info_with_connection(
This is a test helper for the MqttDiscoveryUpdate mixin. 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 # Add device settings to config
config = copy.deepcopy(config[mqtt.DOMAIN][domain]) config = copy.deepcopy(config[mqtt.DOMAIN][domain])
config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_MAC) config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_MAC)
@ -1082,12 +1082,12 @@ async def help_test_entity_device_info_with_connection(
async def help_test_entity_device_info_remove( async def help_test_entity_device_info_remove(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
domain: str, domain: str,
config: ConfigType, config: ConfigType,
) -> None: ) -> None:
"""Test device registry remove.""" """Test device registry remove."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
# Add device settings to config # Add device settings to config
config = copy.deepcopy(config[mqtt.DOMAIN][domain]) config = copy.deepcopy(config[mqtt.DOMAIN][domain])
config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID) config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID)
@ -1114,7 +1114,7 @@ async def help_test_entity_device_info_remove(
async def help_test_entity_device_info_update( async def help_test_entity_device_info_update(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
domain: str, domain: str,
config: ConfigType, config: ConfigType,
) -> None: ) -> None:
@ -1122,7 +1122,7 @@ async def help_test_entity_device_info_update(
This is a test helper for the MqttDiscoveryUpdate mixin. 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 # Add device settings to config
config = copy.deepcopy(config[mqtt.DOMAIN][domain]) config = copy.deepcopy(config[mqtt.DOMAIN][domain])
config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID) config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID)
@ -1150,7 +1150,7 @@ async def help_test_entity_device_info_update(
async def help_test_entity_id_update_subscriptions( async def help_test_entity_id_update_subscriptions(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
domain: str, domain: str,
config: ConfigType, config: ConfigType,
topics: list[str] | None = None, topics: list[str] | None = None,
@ -1169,7 +1169,7 @@ async def help_test_entity_id_update_subscriptions(
entity_registry = er.async_get(hass) entity_registry = er.async_get(hass)
mqtt_mock = await help_setup_component( 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 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( async def help_test_entity_id_update_discovery_update(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
domain: str, domain: str,
config: ConfigType, config: ConfigType,
topic: str | None = None, topic: str | None = None,
) -> None: ) -> None:
"""Test MQTT discovery update after entity_id is updated.""" """Test MQTT discovery update after entity_id is updated."""
# Add unique_id to config # Add unique_id to config
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
config = copy.deepcopy(config) config = copy.deepcopy(config)
config[mqtt.DOMAIN][domain]["unique_id"] = "TOTALLY_UNIQUE" 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( async def help_test_entity_debug_info(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
domain: str, domain: str,
config: ConfigType, config: ConfigType,
) -> None: ) -> None:
@ -1251,7 +1251,7 @@ async def help_test_entity_debug_info(
This is a test helper for MQTT 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 # Add device settings to config
config = copy.deepcopy(config[mqtt.DOMAIN][domain]) config = copy.deepcopy(config[mqtt.DOMAIN][domain])
config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID) config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID)
@ -1284,7 +1284,7 @@ async def help_test_entity_debug_info(
async def help_test_entity_debug_info_max_messages( async def help_test_entity_debug_info_max_messages(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
domain: str, domain: str,
config: ConfigType, config: ConfigType,
) -> None: ) -> None:
@ -1292,7 +1292,7 @@ async def help_test_entity_debug_info_max_messages(
This is a test helper for MQTT 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 # Add device settings to config
config = copy.deepcopy(config[mqtt.DOMAIN][domain]) config = copy.deepcopy(config[mqtt.DOMAIN][domain])
config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID) config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID)
@ -1342,7 +1342,7 @@ async def help_test_entity_debug_info_max_messages(
async def help_test_entity_debug_info_message( async def help_test_entity_debug_info_message(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
domain: str, domain: str,
config: ConfigType, config: ConfigType,
service: str, service: str,
@ -1357,7 +1357,7 @@ async def help_test_entity_debug_info_message(
This is a test helper for MQTT debug_info. This is a test helper for MQTT debug_info.
""" """
# Add device settings to config # Add device settings to config
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
config = copy.deepcopy(config[mqtt.DOMAIN][domain]) config = copy.deepcopy(config[mqtt.DOMAIN][domain])
config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID) config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID)
config["unique_id"] = "veryunique" config["unique_id"] = "veryunique"
@ -1454,7 +1454,7 @@ async def help_test_entity_debug_info_message(
async def help_test_entity_debug_info_remove( async def help_test_entity_debug_info_remove(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
domain: str, domain: str,
config: ConfigType, config: ConfigType,
) -> None: ) -> None:
@ -1462,7 +1462,7 @@ async def help_test_entity_debug_info_remove(
This is a test helper for MQTT 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 # Add device settings to config
config = copy.deepcopy(config[mqtt.DOMAIN][domain]) config = copy.deepcopy(config[mqtt.DOMAIN][domain])
config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID) config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID)
@ -1504,7 +1504,7 @@ async def help_test_entity_debug_info_remove(
async def help_test_entity_debug_info_update_entity_id( async def help_test_entity_debug_info_update_entity_id(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
domain: str, domain: str,
config: ConfigType, config: ConfigType,
) -> None: ) -> None:
@ -1512,7 +1512,7 @@ async def help_test_entity_debug_info_update_entity_id(
This is a test helper for MQTT 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 # Add device settings to config
config = copy.deepcopy(config[mqtt.DOMAIN][domain]) config = copy.deepcopy(config[mqtt.DOMAIN][domain])
config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID) config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID)
@ -1566,12 +1566,12 @@ async def help_test_entity_debug_info_update_entity_id(
async def help_test_entity_disabled_by_default( async def help_test_entity_disabled_by_default(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
domain: str, domain: str,
config: ConfigType, config: ConfigType,
) -> None: ) -> None:
"""Test device registry remove.""" """Test device registry remove."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
# Add device settings to config # Add device settings to config
config = copy.deepcopy(config[mqtt.DOMAIN][domain]) config = copy.deepcopy(config[mqtt.DOMAIN][domain])
config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID) config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID)
@ -1608,12 +1608,12 @@ async def help_test_entity_disabled_by_default(
async def help_test_entity_category( async def help_test_entity_category(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
domain: str, domain: str,
config: ConfigType, config: ConfigType,
) -> None: ) -> None:
"""Test device registry remove.""" """Test device registry remove."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
# Add device settings to config # Add device settings to config
config = copy.deepcopy(config[mqtt.DOMAIN][domain]) config = copy.deepcopy(config[mqtt.DOMAIN][domain])
config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID) config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID)
@ -1655,7 +1655,7 @@ async def help_test_entity_category(
async def help_test_publishing_with_custom_encoding( async def help_test_publishing_with_custom_encoding(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
domain: str, domain: str,
config: ConfigType, config: ConfigType,
@ -1700,7 +1700,7 @@ async def help_test_publishing_with_custom_encoding(
service_data[test_id].update(parameters) service_data[test_id].update(parameters)
# setup test entities using discovery # setup test entities using discovery
mqtt_mock = await mqtt_mock_entry_no_yaml_config() mqtt_mock = await mqtt_mock_entry()
item: int = 0 item: int = 0
for component_config in setup_config: for component_config in setup_config:
conf = json.dumps(component_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( async def help_test_unload_config_entry_with_platform(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
domain: str, domain: str,
config: dict[str, dict[str, Any]], config: dict[str, dict[str, Any]],
) -> None: ) -> None:
@ -1879,7 +1879,7 @@ async def help_test_unload_config_entry_with_platform(
config_name = config_setup config_name = config_setup
with patch("homeassistant.config.load_yaml_config_file", return_value=config_name): 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 # prepare setup through discovery
discovery_setup = copy.deepcopy(config[mqtt.DOMAIN][domain]) discovery_setup = copy.deepcopy(config[mqtt.DOMAIN][domain])

View File

@ -443,14 +443,14 @@ async def test_hassio_cannot_connect(
async def test_option_flow( async def test_option_flow(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
mock_try_connection: MagicMock, mock_try_connection: MagicMock,
) -> None: ) -> None:
"""Test config flow options.""" """Test config flow options."""
with patch( with patch(
"homeassistant.config.async_hass_config_yaml", AsyncMock(return_value={}) "homeassistant.config.async_hass_config_yaml", AsyncMock(return_value={})
) as yaml_mock: ) as yaml_mock:
mqtt_mock = await mqtt_mock_entry_no_yaml_config() mqtt_mock = await mqtt_mock_entry()
mock_try_connection.return_value = True mock_try_connection.return_value = True
config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0] config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0]
config_entry.data = { config_entry.data = {
@ -540,7 +540,7 @@ async def test_option_flow(
) )
async def test_bad_certificate( async def test_bad_certificate(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
mock_try_connection_success: MqttMockPahoClient, mock_try_connection_success: MqttMockPahoClient,
mock_ssl_context: dict[str, MagicMock], mock_ssl_context: dict[str, MagicMock],
mock_process_uploaded_file: 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 # Client key file without client cert, client cert without key file
test_input.pop(mqtt.CONF_CLIENT_KEY) 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 mock_try_connection.return_value = True
config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0] config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0]
# Add at least one advanced option to get the full form # 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( async def test_keepalive_validation(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
mock_try_connection: MagicMock, mock_try_connection: MagicMock,
mock_reload_after_entry_update: MagicMock, mock_reload_after_entry_update: MagicMock,
input_value: str, input_value: str,
@ -650,7 +650,7 @@ async def test_keepalive_validation(
mqtt.CONF_KEEPALIVE: input_value, 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 mock_try_connection.return_value = True
config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0] config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0]
# Add at least one advanced option to get the full form # 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( async def test_disable_birth_will(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
mock_try_connection: MagicMock, mock_try_connection: MagicMock,
mock_reload_after_entry_update: MagicMock, mock_reload_after_entry_update: MagicMock,
) -> None: ) -> None:
"""Test disabling birth and will.""" """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 mock_try_connection.return_value = True
config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0] config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0]
config_entry.data = { config_entry.data = {
@ -753,12 +753,12 @@ async def test_disable_birth_will(
async def test_invalid_discovery_prefix( async def test_invalid_discovery_prefix(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
mock_try_connection: MagicMock, mock_try_connection: MagicMock,
mock_reload_after_entry_update: MagicMock, mock_reload_after_entry_update: MagicMock,
) -> None: ) -> None:
"""Test setting an invalid discovery prefix.""" """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 mock_try_connection.return_value = True
config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0] config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0]
config_entry.data = { config_entry.data = {
@ -832,12 +832,12 @@ def get_suggested(schema: vol.Schema, key: str) -> Any:
async def test_option_flow_default_suggested_values( async def test_option_flow_default_suggested_values(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
mock_try_connection_success: MqttMockPahoClient, mock_try_connection_success: MqttMockPahoClient,
mock_reload_after_entry_update: MagicMock, mock_reload_after_entry_update: MagicMock,
) -> None: ) -> None:
"""Test config flow options has default/suggested values.""" """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 = hass.config_entries.async_entries(mqtt.DOMAIN)[0]
config_entry.data = { config_entry.data = {
mqtt.CONF_BROKER: "test-broker", mqtt.CONF_BROKER: "test-broker",
@ -987,7 +987,7 @@ async def test_option_flow_default_suggested_values(
) )
async def test_skipping_advanced_options( async def test_skipping_advanced_options(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
mock_try_connection: MagicMock, mock_try_connection: MagicMock,
mock_reload_after_entry_update: MagicMock, mock_reload_after_entry_update: MagicMock,
advanced_options: bool, advanced_options: bool,
@ -1001,7 +1001,7 @@ async def test_skipping_advanced_options(
"advanced_options": 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 mock_try_connection.return_value = True
config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0] config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0]
# Initiate with a basic setup # Initiate with a basic setup

File diff suppressed because it is too large Load Diff

View File

@ -41,11 +41,11 @@ def device_tracker_platform_only():
async def test_discover_device_tracker( async def test_discover_device_tracker(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test discovering an MQTT device tracker component.""" """Test discovering an MQTT device tracker component."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
async_fire_mqtt_message( async_fire_mqtt_message(
hass, hass,
"homeassistant/device_tracker/bla/config", "homeassistant/device_tracker/bla/config",
@ -63,11 +63,11 @@ async def test_discover_device_tracker(
@pytest.mark.no_fail_on_log_exception @pytest.mark.no_fail_on_log_exception
async def test_discovery_broken( async def test_discovery_broken(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test handling of bad discovery message.""" """Test handling of bad discovery message."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
async_fire_mqtt_message( async_fire_mqtt_message(
hass, hass,
"homeassistant/device_tracker/bla/config", "homeassistant/device_tracker/bla/config",
@ -92,11 +92,11 @@ async def test_discovery_broken(
async def test_non_duplicate_device_tracker_discovery( async def test_non_duplicate_device_tracker_discovery(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test for a non duplicate component.""" """Test for a non duplicate component."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
async_fire_mqtt_message( async_fire_mqtt_message(
hass, hass,
"homeassistant/device_tracker/bla/config", "homeassistant/device_tracker/bla/config",
@ -120,11 +120,11 @@ async def test_non_duplicate_device_tracker_discovery(
async def test_device_tracker_removal( async def test_device_tracker_removal(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test removal of component through empty discovery message.""" """Test removal of component through empty discovery message."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
async_fire_mqtt_message( async_fire_mqtt_message(
hass, hass,
"homeassistant/device_tracker/bla/config", "homeassistant/device_tracker/bla/config",
@ -142,11 +142,11 @@ async def test_device_tracker_removal(
async def test_device_tracker_rediscover( async def test_device_tracker_rediscover(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test rediscover of removed component.""" """Test rediscover of removed component."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
async_fire_mqtt_message( async_fire_mqtt_message(
hass, hass,
"homeassistant/device_tracker/bla/config", "homeassistant/device_tracker/bla/config",
@ -173,11 +173,11 @@ async def test_device_tracker_rediscover(
async def test_duplicate_device_tracker_removal( async def test_duplicate_device_tracker_removal(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test for a non duplicate component.""" """Test for a non duplicate component."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
async_fire_mqtt_message( async_fire_mqtt_message(
hass, hass,
"homeassistant/device_tracker/bla/config", "homeassistant/device_tracker/bla/config",
@ -198,11 +198,11 @@ async def test_duplicate_device_tracker_removal(
async def test_device_tracker_discovery_update( async def test_device_tracker_discovery_update(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test for a discovery update event.""" """Test for a discovery update event."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
async_fire_mqtt_message( async_fire_mqtt_message(
hass, hass,
"homeassistant/device_tracker/bla/config", "homeassistant/device_tracker/bla/config",
@ -231,12 +231,12 @@ async def test_cleanup_device_tracker(
hass_ws_client: WebSocketGenerator, hass_ws_client: WebSocketGenerator,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry, entity_registry: er.EntityRegistry,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test discovered device is cleaned up when removed from registry.""" """Test discovered device is cleaned up when removed from registry."""
assert await async_setup_component(hass, "config", {}) assert await async_setup_component(hass, "config", {})
await hass.async_block_till_done() 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) ws_client = await hass_ws_client(hass)
async_fire_mqtt_message( async_fire_mqtt_message(
@ -291,11 +291,11 @@ async def test_cleanup_device_tracker(
async def test_setting_device_tracker_value_via_mqtt_message( async def test_setting_device_tracker_value_via_mqtt_message(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test the setting of the value via MQTT.""" """Test the setting of the value via MQTT."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
async_fire_mqtt_message( async_fire_mqtt_message(
hass, hass,
"homeassistant/device_tracker/bla/config", "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( async def test_setting_device_tracker_value_via_mqtt_message_and_template(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test the setting of the value via MQTT.""" """Test the setting of the value via MQTT."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
async_fire_mqtt_message( async_fire_mqtt_message(
hass, hass,
"homeassistant/device_tracker/bla/config", "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( async def test_setting_device_tracker_value_via_mqtt_message_and_template2(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test the setting of the value via MQTT.""" """Test the setting of the value via MQTT."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
async_fire_mqtt_message( async_fire_mqtt_message(
hass, hass,
"homeassistant/device_tracker/bla/config", "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( async def test_setting_device_tracker_location_via_mqtt_message(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test the setting of the location via MQTT.""" """Test the setting of the location via MQTT."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
async_fire_mqtt_message( async_fire_mqtt_message(
hass, hass,
"homeassistant/device_tracker/bla/config", "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( async def test_setting_device_tracker_location_via_lat_lon_message(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test the setting of the latitude and longitude via MQTT.""" """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( async_fire_mqtt_message(
hass, hass,
"homeassistant/device_tracker/bla/config", "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( async def test_setting_device_tracker_location_via_reset_message(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test the automatic inference of zones via MQTT via reset.""" """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( async_fire_mqtt_message(
hass, hass,
"homeassistant/device_tracker/bla/config", "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( async def test_setting_device_tracker_location_via_abbr_reset_message(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test the setting of reset via abbreviated names and custom payloads via MQTT.""" """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( async_fire_mqtt_message(
hass, hass,
"homeassistant/device_tracker/bla/config", "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( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_blocked_attribute_via_mqtt_json_message( await help_test_setting_blocked_attribute_via_mqtt_json_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
device_tracker.DOMAIN, device_tracker.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
None, None,
@ -603,10 +603,10 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
], ],
) )
async def test_setup_with_modern_schema( async def test_setup_with_modern_schema(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setup using the modern schema.""" """Test setup using the modern schema."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
dev_id = "jan" dev_id = "jan"
entity_id = f"{device_tracker.DOMAIN}.{dev_id}" entity_id = f"{device_tracker.DOMAIN}.{dev_id}"
assert hass.states.get(entity_id) is not None assert hass.states.get(entity_id) is not None

View File

@ -45,10 +45,10 @@ def binary_sensor_and_sensor_only():
async def test_get_triggers( async def test_get_triggers(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test we get the expected triggers from a discovered mqtt device.""" """Test we get the expected triggers from a discovered mqtt device."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
data1 = ( data1 = (
'{ "automation_type":"trigger",' '{ "automation_type":"trigger",'
' "device":{"identifiers":["0AFFD2"]},' ' "device":{"identifiers":["0AFFD2"]},'
@ -81,10 +81,10 @@ async def test_get_triggers(
async def test_get_unknown_triggers( async def test_get_unknown_triggers(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test we don't get unknown triggers.""" """Test we don't get unknown triggers."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
# Discover a sensor (without device triggers) # Discover a sensor (without device triggers)
data1 = ( data1 = (
'{ "device":{"identifiers":["0AFFD2"]},' '{ "device":{"identifiers":["0AFFD2"]},'
@ -128,10 +128,10 @@ async def test_get_unknown_triggers(
async def test_get_non_existing_triggers( async def test_get_non_existing_triggers(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test getting non existing triggers.""" """Test getting non existing triggers."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
# Discover a sensor (without device triggers) # Discover a sensor (without device triggers)
data1 = ( data1 = (
'{ "device":{"identifiers":["0AFFD2"]},' '{ "device":{"identifiers":["0AFFD2"]},'
@ -152,10 +152,10 @@ async def test_get_non_existing_triggers(
async def test_discover_bad_triggers( async def test_discover_bad_triggers(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test bad discovery message.""" """Test bad discovery message."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
# Test sending bad data # Test sending bad data
data0 = ( data0 = (
'{ "automation_type":"trigger",' '{ "automation_type":"trigger",'
@ -202,10 +202,10 @@ async def test_discover_bad_triggers(
async def test_update_remove_triggers( async def test_update_remove_triggers(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test triggers can be updated and removed.""" """Test triggers can be updated and removed."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
config1 = { config1 = {
"automation_type": "trigger", "automation_type": "trigger",
"device": {"identifiers": ["0AFFD2"]}, "device": {"identifiers": ["0AFFD2"]},
@ -272,10 +272,10 @@ async def test_if_fires_on_mqtt_message(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
calls, calls,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test triggers firing.""" """Test triggers firing."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
data1 = ( data1 = (
'{ "automation_type":"trigger",' '{ "automation_type":"trigger",'
' "device":{"identifiers":["0AFFD2"]},' ' "device":{"identifiers":["0AFFD2"]},'
@ -351,10 +351,10 @@ async def test_if_fires_on_mqtt_message_template(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
calls, calls,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test triggers firing.""" """Test triggers firing."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
data1 = ( data1 = (
'{ "automation_type":"trigger",' '{ "automation_type":"trigger",'
' "device":{"identifiers":["0AFFD2"]},' ' "device":{"identifiers":["0AFFD2"]},'
@ -432,10 +432,10 @@ async def test_if_fires_on_mqtt_message_late_discover(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
calls, calls,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test triggers firing of MQTT device triggers discovered after setup.""" """Test triggers firing of MQTT device triggers discovered after setup."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
data0 = ( data0 = (
'{ "device":{"identifiers":["0AFFD2"]},' '{ "device":{"identifiers":["0AFFD2"]},'
' "state_topic": "foobar/sensor",' ' "state_topic": "foobar/sensor",'
@ -519,10 +519,10 @@ async def test_if_fires_on_mqtt_message_after_update(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
calls, calls,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test triggers firing after update.""" """Test triggers firing after update."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
data1 = ( data1 = (
'{ "automation_type":"trigger",' '{ "automation_type":"trigger",'
' "device":{"identifiers":["0AFFD2"]},' ' "device":{"identifiers":["0AFFD2"]},'
@ -598,10 +598,10 @@ async def test_if_fires_on_mqtt_message_after_update(
async def test_no_resubscribe_same_topic( async def test_no_resubscribe_same_topic(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test subscription to topics without change.""" """Test subscription to topics without change."""
mqtt_mock = await mqtt_mock_entry_no_yaml_config() mqtt_mock = await mqtt_mock_entry()
data1 = ( data1 = (
'{ "automation_type":"trigger",' '{ "automation_type":"trigger",'
' "device":{"identifiers":["0AFFD2"]},' ' "device":{"identifiers":["0AFFD2"]},'
@ -646,10 +646,10 @@ async def test_not_fires_on_mqtt_message_after_remove_by_mqtt(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
calls, calls,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test triggers not firing after removal.""" """Test triggers not firing after removal."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
data1 = ( data1 = (
'{ "automation_type":"trigger",' '{ "automation_type":"trigger",'
' "device":{"identifiers":["0AFFD2"]},' ' "device":{"identifiers":["0AFFD2"]},'
@ -712,13 +712,13 @@ async def test_not_fires_on_mqtt_message_after_remove_from_registry(
hass_ws_client: WebSocketGenerator, hass_ws_client: WebSocketGenerator,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
calls, calls,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test triggers not firing after removal.""" """Test triggers not firing after removal."""
assert await async_setup_component(hass, "config", {}) assert await async_setup_component(hass, "config", {})
assert await async_setup_component(hass, "repairs", {}) assert await async_setup_component(hass, "repairs", {})
await hass.async_block_till_done() await hass.async_block_till_done()
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
ws_client = await hass_ws_client(hass) 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( async def test_attach_remove(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test attach and removal of trigger.""" """Test attach and removal of trigger."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
data1 = ( data1 = (
'{ "automation_type":"trigger",' '{ "automation_type":"trigger",'
' "device":{"identifiers":["0AFFD2"]},' ' "device":{"identifiers":["0AFFD2"]},'
@ -841,10 +841,10 @@ async def test_attach_remove(
async def test_attach_remove_late( async def test_attach_remove_late(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test attach and removal of trigger .""" """Test attach and removal of trigger ."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
data0 = ( data0 = (
'{ "device":{"identifiers":["0AFFD2"]},' '{ "device":{"identifiers":["0AFFD2"]},'
' "state_topic": "foobar/sensor",' ' "state_topic": "foobar/sensor",'
@ -907,10 +907,10 @@ async def test_attach_remove_late(
async def test_attach_remove_late2( async def test_attach_remove_late2(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test attach and removal of trigger .""" """Test attach and removal of trigger ."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
data0 = ( data0 = (
'{ "device":{"identifiers":["0AFFD2"]},' '{ "device":{"identifiers":["0AFFD2"]},'
' "state_topic": "foobar/sensor",' ' "state_topic": "foobar/sensor",'
@ -969,10 +969,10 @@ async def test_attach_remove_late2(
async def test_entity_device_info_with_connection( async def test_entity_device_info_with_connection(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT device registry integration.""" """Test MQTT device registry integration."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
registry = dr.async_get(hass) registry = dr.async_get(hass)
data = json.dumps( data = json.dumps(
@ -1007,10 +1007,10 @@ async def test_entity_device_info_with_connection(
async def test_entity_device_info_with_identifier( async def test_entity_device_info_with_identifier(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT device registry integration.""" """Test MQTT device registry integration."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
registry = dr.async_get(hass) registry = dr.async_get(hass)
data = json.dumps( data = json.dumps(
@ -1043,10 +1043,10 @@ async def test_entity_device_info_with_identifier(
async def test_entity_device_info_update( async def test_entity_device_info_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry update.""" """Test device registry update."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
registry = dr.async_get(hass) registry = dr.async_get(hass)
config = { config = {
@ -1086,10 +1086,10 @@ async def test_cleanup_trigger(
hass: HomeAssistant, hass: HomeAssistant,
hass_ws_client: WebSocketGenerator, hass_ws_client: WebSocketGenerator,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test trigger discovery topic is cleaned when device is removed from registry.""" """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", {}) assert await async_setup_component(hass, "config", {})
ws_client = await hass_ws_client(hass) ws_client = await hass_ws_client(hass)
@ -1142,10 +1142,10 @@ async def test_cleanup_trigger(
async def test_cleanup_device( async def test_cleanup_device(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test removal from device registry when trigger is removed.""" """Test removal from device registry when trigger is removed."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
config = { config = {
"automation_type": "trigger", "automation_type": "trigger",
"topic": "test-topic", "topic": "test-topic",
@ -1178,10 +1178,10 @@ async def test_cleanup_device(
async def test_cleanup_device_several_triggers( async def test_cleanup_device_several_triggers(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test removal from device registry when the last trigger is removed.""" """Test removal from device registry when the last trigger is removed."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
config1 = { config1 = {
"automation_type": "trigger", "automation_type": "trigger",
"topic": "test-topic", "topic": "test-topic",
@ -1240,13 +1240,13 @@ async def test_cleanup_device_several_triggers(
async def test_cleanup_device_with_entity1( async def test_cleanup_device_with_entity1(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test removal from device registry for device with entity. """Test removal from device registry for device with entity.
Trigger removed first, then entity. Trigger removed first, then entity.
""" """
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
config1 = { config1 = {
"automation_type": "trigger", "automation_type": "trigger",
"topic": "test-topic", "topic": "test-topic",
@ -1301,13 +1301,13 @@ async def test_cleanup_device_with_entity1(
async def test_cleanup_device_with_entity2( async def test_cleanup_device_with_entity2(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test removal from device registry for device with entity. """Test removal from device registry for device with entity.
Entity removed first, then trigger. Entity removed first, then trigger.
""" """
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
config1 = { config1 = {
"automation_type": "trigger", "automation_type": "trigger",
"topic": "test-topic", "topic": "test-topic",
@ -1360,13 +1360,13 @@ async def test_cleanup_device_with_entity2(
async def test_trigger_debug_info( async def test_trigger_debug_info(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test debug_info. """Test debug_info.
This is a test helper for MQTT 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) registry = dr.async_get(hass)
config1 = { config1 = {

View File

@ -36,10 +36,10 @@ async def test_entry_diagnostics(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
hass_client: ClientSessionGenerator, hass_client: ClientSessionGenerator,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test config entry diagnostics.""" """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] config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0]
mqtt_mock.connected = True mqtt_mock.connected = True
@ -160,10 +160,10 @@ async def test_redact_diagnostics(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
hass_client: ClientSessionGenerator, hass_client: ClientSessionGenerator,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test redacting diagnostics.""" """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 = dict(default_config)
expected_config["password"] = "**REDACTED**" expected_config["password"] = "**REDACTED**"
expected_config["username"] = "**REDACTED**" expected_config["username"] = "**REDACTED**"

View File

@ -49,10 +49,10 @@ from tests.typing import (
) )
async def test_subscribing_config_topic( async def test_subscribing_config_topic(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test setting up discovery.""" """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] entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0]
discovery_topic = "homeassistant" discovery_topic = "homeassistant"
@ -77,13 +77,13 @@ async def test_subscribing_config_topic(
) )
async def test_invalid_topic( async def test_invalid_topic(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
topic: str, topic: str,
log: bool, log: bool,
) -> None: ) -> None:
"""Test sending to invalid topic.""" """Test sending to invalid topic."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
with patch( with patch(
"homeassistant.components.mqtt.discovery.async_dispatcher_send" "homeassistant.components.mqtt.discovery.async_dispatcher_send"
) as mock_dispatcher_send: ) as mock_dispatcher_send:
@ -104,11 +104,11 @@ async def test_invalid_topic(
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR]) @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
async def test_invalid_json( async def test_invalid_json(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test sending in invalid JSON.""" """Test sending in invalid JSON."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
with patch( with patch(
"homeassistant.components.mqtt.discovery.async_dispatcher_send" "homeassistant.components.mqtt.discovery.async_dispatcher_send"
) as mock_dispatcher_send: ) as mock_dispatcher_send:
@ -124,11 +124,11 @@ async def test_invalid_json(
async def test_only_valid_components( async def test_only_valid_components(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test for a valid component.""" """Test for a valid component."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
with patch( with patch(
"homeassistant.components.mqtt.discovery.async_dispatcher_send" "homeassistant.components.mqtt.discovery.async_dispatcher_send"
) as mock_dispatcher_send: ) as mock_dispatcher_send:
@ -150,10 +150,10 @@ async def test_only_valid_components(
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR]) @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
async def test_correct_config_discovery( async def test_correct_config_discovery(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test sending in correct JSON.""" """Test sending in correct JSON."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
async_fire_mqtt_message( async_fire_mqtt_message(
hass, hass,
"homeassistant/binary_sensor/bla/config", "homeassistant/binary_sensor/bla/config",
@ -171,10 +171,10 @@ async def test_correct_config_discovery(
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.FAN]) @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.FAN])
async def test_discover_fan( async def test_discover_fan(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test discovering an MQTT fan.""" """Test discovering an MQTT fan."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
async_fire_mqtt_message( async_fire_mqtt_message(
hass, hass,
"homeassistant/fan/bla/config", "homeassistant/fan/bla/config",
@ -192,11 +192,11 @@ async def test_discover_fan(
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.CLIMATE]) @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.CLIMATE])
async def test_discover_climate( async def test_discover_climate(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test discovering an MQTT climate component.""" """Test discovering an MQTT climate component."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
data = ( data = (
'{ "name": "ClimateTest",' '{ "name": "ClimateTest",'
' "current_temperature_topic": "climate/bla/current_temp",' ' "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]) @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.ALARM_CONTROL_PANEL])
async def test_discover_alarm_control_panel( async def test_discover_alarm_control_panel(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test discovering an MQTT alarm control panel component.""" """Test discovering an MQTT alarm control panel component."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
data = ( data = (
'{ "name": "AlarmControlPanelTest",' '{ "name": "AlarmControlPanelTest",'
' "state_topic": "test_topic",' ' "state_topic": "test_topic",'
@ -385,7 +385,7 @@ async def test_discover_alarm_control_panel(
) )
async def test_discovery_with_object_id( async def test_discovery_with_object_id(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
topic: str, topic: str,
config: str, config: str,
entity_id: str, entity_id: str,
@ -393,7 +393,7 @@ async def test_discovery_with_object_id(
domain: str, domain: str,
) -> None: ) -> None:
"""Test discovering an MQTT entity with object_id.""" """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) async_fire_mqtt_message(hass, topic, config)
await hass.async_block_till_done() 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]) @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
async def test_discovery_incl_nodeid( async def test_discovery_incl_nodeid(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test sending in correct JSON with optional node_id included.""" """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( async_fire_mqtt_message(
hass, hass,
"homeassistant/binary_sensor/my_node_id/bla/config", "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]) @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
async def test_non_duplicate_discovery( async def test_non_duplicate_discovery(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test for a non duplicate component.""" """Test for a non duplicate component."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
async_fire_mqtt_message( async_fire_mqtt_message(
hass, hass,
"homeassistant/binary_sensor/bla/config", "homeassistant/binary_sensor/bla/config",
@ -459,10 +459,10 @@ async def test_non_duplicate_discovery(
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR]) @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
async def test_removal( async def test_removal(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test removal of component through empty discovery message.""" """Test removal of component through empty discovery message."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
async_fire_mqtt_message( async_fire_mqtt_message(
hass, hass,
"homeassistant/binary_sensor/bla/config", "homeassistant/binary_sensor/bla/config",
@ -481,10 +481,10 @@ async def test_removal(
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR]) @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
async def test_rediscover( async def test_rediscover(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test rediscover of removed component.""" """Test rediscover of removed component."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
async_fire_mqtt_message( async_fire_mqtt_message(
hass, hass,
"homeassistant/binary_sensor/bla/config", "homeassistant/binary_sensor/bla/config",
@ -512,10 +512,10 @@ async def test_rediscover(
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR]) @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
async def test_rapid_rediscover( async def test_rapid_rediscover(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test immediate rediscover of removed component.""" """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) events = async_capture_events(hass, EVENT_STATE_CHANGED)
async_fire_mqtt_message( async_fire_mqtt_message(
@ -565,10 +565,10 @@ async def test_rapid_rediscover(
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR]) @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
async def test_rapid_rediscover_unique( async def test_rapid_rediscover_unique(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test immediate rediscover of removed component.""" """Test immediate rediscover of removed component."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
events = [] events = []
@callback @callback
@ -628,10 +628,10 @@ async def test_rapid_rediscover_unique(
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR]) @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
async def test_rapid_reconfigure( async def test_rapid_reconfigure(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test immediate reconfigure of added component.""" """Test immediate reconfigure of added component."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
events = [] events = []
@callback @callback
@ -684,11 +684,11 @@ async def test_rapid_reconfigure(
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR]) @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
async def test_duplicate_removal( async def test_duplicate_removal(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test for a non duplicate component.""" """Test for a non duplicate component."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
async_fire_mqtt_message( async_fire_mqtt_message(
hass, hass,
"homeassistant/binary_sensor/bla/config", "homeassistant/binary_sensor/bla/config",
@ -710,10 +710,10 @@ async def test_cleanup_device(
hass_ws_client: WebSocketGenerator, hass_ws_client: WebSocketGenerator,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry, entity_registry: er.EntityRegistry,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test discvered device is cleaned up when entry removed from device.""" """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", {}) assert await async_setup_component(hass, "config", {})
ws_client = await hass_ws_client(hass) ws_client = await hass_ws_client(hass)
@ -772,10 +772,10 @@ async def test_cleanup_device_mqtt(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry, entity_registry: er.EntityRegistry,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test discvered device is cleaned up when removed through MQTT.""" """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 = ( data = (
'{ "device":{"identifiers":["0AFFD2"]},' '{ "device":{"identifiers":["0AFFD2"]},'
' "state_topic": "foobar/sensor",' ' "state_topic": "foobar/sensor",'
@ -819,12 +819,12 @@ async def test_cleanup_device_multiple_config_entries(
hass_ws_client: WebSocketGenerator, hass_ws_client: WebSocketGenerator,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry, entity_registry: er.EntityRegistry,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test discovered device is cleaned up when entry removed from device.""" """Test discovered device is cleaned up when entry removed from device."""
assert await async_setup_component(hass, "config", {}) assert await async_setup_component(hass, "config", {})
await hass.async_block_till_done() 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) ws_client = await hass_ws_client(hass)
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
@ -924,10 +924,10 @@ async def test_cleanup_device_multiple_config_entries_mqtt(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry, entity_registry: er.EntityRegistry,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test discovered device is cleaned up when removed through MQTT.""" """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 = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_registry.async_get_or_create( 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]) @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SWITCH])
async def test_discovery_expansion( async def test_discovery_expansion(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test expansion of abbreviated discovery payload.""" """Test expansion of abbreviated discovery payload."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
data = ( data = (
'{ "~": "some/base/topic",' '{ "~": "some/base/topic",'
' "name": "DiscoveryExpansionTest1",' ' "name": "DiscoveryExpansionTest1",'
@ -1071,10 +1071,10 @@ async def test_discovery_expansion(
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SWITCH]) @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SWITCH])
async def test_discovery_expansion_2( async def test_discovery_expansion_2(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test expansion of abbreviated discovery payload.""" """Test expansion of abbreviated discovery payload."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
data = ( data = (
'{ "~": "some/base/topic",' '{ "~": "some/base/topic",'
' "name": "DiscoveryExpansionTest1",' ' "name": "DiscoveryExpansionTest1",'
@ -1117,11 +1117,11 @@ async def test_discovery_expansion_2(
@pytest.mark.no_fail_on_log_exception @pytest.mark.no_fail_on_log_exception
async def test_discovery_expansion_3( async def test_discovery_expansion_3(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test expansion of broken discovery payload.""" """Test expansion of broken discovery payload."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
data = ( data = (
'{ "~": "some/base/topic",' '{ "~": "some/base/topic",'
' "name": "DiscoveryExpansionTest1",' ' "name": "DiscoveryExpansionTest1",'
@ -1153,10 +1153,10 @@ async def test_discovery_expansion_3(
async def test_discovery_expansion_without_encoding_and_value_template_1( async def test_discovery_expansion_without_encoding_and_value_template_1(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test expansion of raw availability payload with a template as list.""" """Test expansion of raw availability payload with a template as list."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
data = ( data = (
'{ "~": "some/base/topic",' '{ "~": "some/base/topic",'
' "name": "DiscoveryExpansionTest1",' ' "name": "DiscoveryExpansionTest1",'
@ -1205,10 +1205,10 @@ async def test_discovery_expansion_without_encoding_and_value_template_1(
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SWITCH]) @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SWITCH])
async def test_discovery_expansion_without_encoding_and_value_template_2( async def test_discovery_expansion_without_encoding_and_value_template_2(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test expansion of raw availability payload with a template directly.""" """Test expansion of raw availability payload with a template directly."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
data = ( data = (
'{ "~": "some/base/topic",' '{ "~": "some/base/topic",'
' "name": "DiscoveryExpansionTest1",' ' "name": "DiscoveryExpansionTest1",'
@ -1290,10 +1290,10 @@ ABBREVIATIONS_WHITE_LIST = [
async def test_missing_discover_abbreviations( async def test_missing_discover_abbreviations(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Check MQTT platforms for missing abbreviations.""" """Check MQTT platforms for missing abbreviations."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
missing = [] missing = []
regex = re.compile(r"(CONF_[a-zA-Z\d_]*) *= *[\'\"]([a-zA-Z\d_]*)[\'\"]") regex = re.compile(r"(CONF_[a-zA-Z\d_]*) *= *[\'\"]([a-zA-Z\d_]*)[\'\"]")
for fil in Path(mqtt.__file__).parent.rglob("*.py"): 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]) @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SWITCH])
async def test_no_implicit_state_topic_switch( async def test_no_implicit_state_topic_switch(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test no implicit state topic for switch.""" """Test no implicit state topic for switch."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
data = '{ "name": "Test1", "command_topic": "cmnd" }' data = '{ "name": "Test1", "command_topic": "cmnd" }'
async_fire_mqtt_message(hass, "homeassistant/switch/bla/config", data) 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( async def test_complex_discovery_topic_prefix(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Tests handling of discovery topic prefix with multiple slashes.""" """Tests handling of discovery topic prefix with multiple slashes."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
async_fire_mqtt_message( async_fire_mqtt_message(
hass, hass,
@ -1379,10 +1379,10 @@ async def test_complex_discovery_topic_prefix(
async def test_mqtt_integration_discovery_subscribe_unsubscribe( async def test_mqtt_integration_discovery_subscribe_unsubscribe(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_client_mock: MqttMockPahoClient, mqtt_client_mock: MqttMockPahoClient,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Check MQTT integration discovery subscribe and unsubscribe.""" """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) mock_entity_platform(hass, "config_flow.comp", None)
entry = hass.config_entries.async_entries("mqtt")[0] 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( async def test_mqtt_discovery_unsubscribe_once(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_client_mock: MqttMockPahoClient, mqtt_client_mock: MqttMockPahoClient,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Check MQTT integration discovery unsubscribe once.""" """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) mock_entity_platform(hass, "config_flow.comp", None)
entry = hass.config_entries.async_entries("mqtt")[0] 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]) @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SENSOR])
async def test_clear_config_topic_disabled_entity( async def test_clear_config_topic_disabled_entity(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test the discovery topic is removed when a disabled entity is removed.""" """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 # discover an entity that is not enabled by default
config = { config = {
"name": "sbfspot_12345", "name": "sbfspot_12345",
@ -1540,12 +1540,12 @@ async def test_clear_config_topic_disabled_entity(
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SENSOR]) @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SENSOR])
async def test_clean_up_registry_monitoring( async def test_clean_up_registry_monitoring(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
tmp_path: Path, tmp_path: Path,
) -> None: ) -> None:
"""Test registry monitoring hook is removed after a reload.""" """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 hooks: dict = hass.data["mqtt"].discovery_registry_hooks
# discover an entity that is not enabled by default # discover an entity that is not enabled by default
config1 = { config1 = {
@ -1595,11 +1595,11 @@ async def test_clean_up_registry_monitoring(
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SENSOR]) @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SENSOR])
async def test_unique_id_collission_has_priority( async def test_unique_id_collission_has_priority(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
entity_registry: er.EntityRegistry, entity_registry: er.EntityRegistry,
) -> None: ) -> None:
"""Test the unique_id collision detection has priority over registry disabled items.""" """Test the unique_id collision detection has priority over registry disabled items."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
config = { config = {
"name": "sbfspot_12345", "name": "sbfspot_12345",
"state_topic": "homeassistant_test/sensor/sbfspot_0/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) @pytest.mark.xfail(raises=MultipleInvalid)
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SENSOR]) @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SENSOR])
async def test_update_with_bad_config_not_breaks_discovery( 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: ) -> None:
"""Test a bad update does not break discovery.""" """Test a bad update does not break discovery."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
# discover a sensor # discover a sensor
config1 = { config1 = {
"name": "sbfspot_12345", "name": "sbfspot_12345",

View File

@ -89,11 +89,11 @@ def fan_platform_only():
async def test_fail_setup_if_no_command_topic( async def test_fail_setup_if_no_command_topic(
hass: HomeAssistant, hass: HomeAssistant,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test if command fails with command topic.""" """Test if command fails with command topic."""
with pytest.raises(AssertionError): with pytest.raises(AssertionError):
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
assert ( assert (
"Invalid config for [mqtt]: required key not provided @ data['mqtt']['fan'][0]['command_topic']" "Invalid config for [mqtt]: required key not provided @ data['mqtt']['fan'][0]['command_topic']"
in caplog.text in caplog.text
@ -138,11 +138,11 @@ async def test_fail_setup_if_no_command_topic(
) )
async def test_controlling_state_via_topic( async def test_controlling_state_via_topic(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test the controlling state via topic.""" """Test the controlling state via topic."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get("fan.test") state = hass.states.get("fan.test")
assert state.state == STATE_UNKNOWN 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( async def test_controlling_state_via_topic_with_different_speed_range(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test the controlling state via topic using an alternate speed range.""" """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") async_fire_mqtt_message(hass, "percentage-state-topic1", "100")
state = hass.states.get("fan.test1") 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( async def test_controlling_state_via_topic_no_percentage_topics(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test the controlling state via topic without percentage topics.""" """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") state = hass.states.get("fan.test")
assert state.state == STATE_UNKNOWN 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( async def test_controlling_state_via_topic_and_json_message(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test the controlling state via topic and JSON message (percentage mode).""" """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") state = hass.states.get("fan.test")
assert state.state == STATE_UNKNOWN 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( async def test_controlling_state_via_topic_and_json_message_shared_topic(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test the controlling state via topic and JSON message using a shared topic.""" """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") state = hass.states.get("fan.test")
assert state.state == STATE_UNKNOWN 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( async def test_sending_mqtt_commands_and_optimistic(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test optimistic mode without state topic.""" """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") state = hass.states.get("fan.test")
assert state.state == STATE_UNKNOWN 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( 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: ) -> None:
"""Test the controlling state via topic using an alternate speed range.""" """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) await common.async_set_percentage(hass, "fan.test1", 0)
mqtt_mock.async_publish.assert_called_once_with( 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( async def test_sending_mqtt_commands_and_optimistic_no_legacy(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test optimistic mode without state topic without legacy speed command topic.""" """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") state = hass.states.get("fan.test")
assert state.state == STATE_UNKNOWN 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_( async def test_sending_mqtt_command_templates_(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test optimistic mode without state topic without legacy speed command topic.""" """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") state = hass.states.get("fan.test")
assert state.state == STATE_UNKNOWN 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( async def test_sending_mqtt_commands_and_optimistic_no_percentage_topic(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test optimistic mode without state topic without percentage command topic.""" """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") state = hass.states.get("fan.test")
assert state.state == STATE_UNKNOWN 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( async def test_sending_mqtt_commands_and_explicit_optimistic(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test optimistic mode with state topic and turn on attributes.""" """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") state = hass.states.get("fan.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -1372,7 +1372,7 @@ async def test_sending_mqtt_commands_and_explicit_optimistic(
) )
async def test_encoding_subscribable_topics( async def test_encoding_subscribable_topics(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
topic: str, topic: str,
value: str, value: str,
attribute: str | None, attribute: str | None,
@ -1386,7 +1386,7 @@ async def test_encoding_subscribable_topics(
config[CONF_OSCILLATION_COMMAND_TOPIC] = "fan/some_oscillation_command_topic" config[CONF_OSCILLATION_COMMAND_TOPIC] = "fan/some_oscillation_command_topic"
await help_test_encoding_subscribable_topics( await help_test_encoding_subscribable_topics(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
fan.DOMAIN, fan.DOMAIN,
config, config,
topic, topic,
@ -1418,11 +1418,11 @@ async def test_encoding_subscribable_topics(
) )
async def test_attributes( async def test_attributes(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes.""" """Test attributes."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get("fan.test") state = hass.states.get("fan.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -1698,49 +1698,47 @@ async def test_attributes(
) )
async def test_supported_features( async def test_supported_features(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
name: str, name: str,
success: bool, success: bool,
features, features,
) -> None: ) -> None:
"""Test optimistic mode without state topic.""" """Test optimistic mode without state topic."""
if success: if success:
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get(f"fan.{name}") state = hass.states.get(f"fan.{name}")
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == features assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == features
return return
with pytest.raises(AssertionError): with pytest.raises(AssertionError):
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_availability_when_connection_lost( async def test_availability_when_connection_lost(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(hass, mqtt_mock_entry, fan.DOMAIN)
hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN
)
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_availability_without_topic( async def test_availability_without_topic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, fan.DOMAIN, DEFAULT_CONFIG
) )
async def test_default_availability_payload( async def test_default_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
await help_test_default_availability_payload( await help_test_default_availability_payload(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
fan.DOMAIN, fan.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
True, True,
@ -1750,12 +1748,12 @@ async def test_default_availability_payload(
async def test_custom_availability_payload( async def test_custom_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by custom payload with defined topic.""" """Test availability by custom payload with defined topic."""
await help_test_custom_availability_payload( await help_test_custom_availability_payload(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
fan.DOMAIN, fan.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
True, True,
@ -1765,21 +1763,21 @@ async def test_custom_availability_payload(
async def test_setting_attribute_via_mqtt_json_message( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message( await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_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( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_blocked_attribute_via_mqtt_json_message( await help_test_setting_blocked_attribute_via_mqtt_json_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
fan.DOMAIN, fan.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
MQTT_FAN_ATTRIBUTES_BLOCKED, 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( async def test_setting_attribute_with_template(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template( await help_test_setting_attribute_with_template(
hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, fan.DOMAIN, DEFAULT_CONFIG
) )
async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_not_dict(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_not_dict( await help_test_update_with_json_attrs_not_dict(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
fan.DOMAIN, fan.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -1812,13 +1810,13 @@ async def test_update_with_json_attrs_not_dict(
async def test_update_with_json_attrs_bad_json( async def test_update_with_json_attrs_bad_json(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_json( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
fan.DOMAIN, fan.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -1827,12 +1825,12 @@ async def test_update_with_json_attrs_bad_json(
async def test_discovery_update_attr( async def test_discovery_update_attr(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered MQTTAttributes.""" """Test update of discovered MQTTAttributes."""
await help_test_discovery_update_attr( await help_test_discovery_update_attr(
hass, mqtt_mock_entry_no_yaml_config, caplog, fan.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, caplog, fan.DOMAIN, DEFAULT_CONFIG
) )
@ -1860,40 +1858,38 @@ async def test_discovery_update_attr(
], ],
) )
async def test_unique_id( async def test_unique_id(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test unique_id option only creates one fan per id.""" """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( async def test_discovery_removal_fan(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test removal of discovered fan.""" """Test removal of discovered fan."""
data = '{ "name": "test", "command_topic": "test_topic" }' data = '{ "name": "test", "command_topic": "test_topic" }'
await help_test_discovery_removal( await help_test_discovery_removal(hass, mqtt_mock_entry, caplog, fan.DOMAIN, data)
hass, mqtt_mock_entry_no_yaml_config, caplog, fan.DOMAIN, data
)
async def test_discovery_update_fan( async def test_discovery_update_fan(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered fan.""" """Test update of discovered fan."""
config1 = {"name": "Beer", "command_topic": "test_topic"} config1 = {"name": "Beer", "command_topic": "test_topic"}
config2 = {"name": "Milk", "command_topic": "test_topic"} config2 = {"name": "Milk", "command_topic": "test_topic"}
await help_test_discovery_update( 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( async def test_discovery_update_unchanged_fan(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered fan.""" """Test update of discovered fan."""
@ -1903,7 +1899,7 @@ async def test_discovery_update_unchanged_fan(
) as discovery_update: ) as discovery_update:
await help_test_discovery_update_unchanged( await help_test_discovery_update_unchanged(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
fan.DOMAIN, fan.DOMAIN,
data1, data1,
@ -1914,7 +1910,7 @@ async def test_discovery_update_unchanged_fan(
@pytest.mark.no_fail_on_log_exception @pytest.mark.no_fail_on_log_exception
async def test_discovery_broken( async def test_discovery_broken(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test handling of bad discovery message.""" """Test handling of bad discovery message."""
@ -1922,71 +1918,71 @@ async def test_discovery_broken(
data2 = '{ "name": "Milk", "command_topic": "test_topic" }' data2 = '{ "name": "Milk", "command_topic": "test_topic" }'
await help_test_discovery_broken( 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( async def test_entity_device_info_with_connection(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT fan device registry integration.""" """Test MQTT fan device registry integration."""
await help_test_entity_device_info_with_connection( await help_test_entity_device_info_with_connection(
hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, fan.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_with_identifier( async def test_entity_device_info_with_identifier(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT fan device registry integration.""" """Test MQTT fan device registry integration."""
await help_test_entity_device_info_with_identifier( await help_test_entity_device_info_with_identifier(
hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, fan.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_update( async def test_entity_device_info_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry update.""" """Test device registry update."""
await help_test_entity_device_info_update( await help_test_entity_device_info_update(
hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, fan.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_remove( async def test_entity_device_info_remove(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry remove.""" """Test device registry remove."""
await help_test_entity_device_info_remove( await help_test_entity_device_info_remove(
hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, fan.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_subscriptions( async def test_entity_id_update_subscriptions(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT subscriptions are managed when entity_id is updated.""" """Test MQTT subscriptions are managed when entity_id is updated."""
await help_test_entity_id_update_subscriptions( await help_test_entity_id_update_subscriptions(
hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, fan.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_discovery_update( async def test_entity_id_update_discovery_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT discovery update when entity_id is updated.""" """Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update( await help_test_entity_id_update_discovery_update(
hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, fan.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_debug_info_message( async def test_entity_debug_info_message(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT debug info.""" """Test MQTT debug info."""
await help_test_entity_debug_info_message( await help_test_entity_debug_info_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
fan.DOMAIN, fan.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
fan.SERVICE_TURN_ON, fan.SERVICE_TURN_ON,
@ -2035,7 +2031,7 @@ async def test_entity_debug_info_message(
) )
async def test_publishing_with_custom_encoding( async def test_publishing_with_custom_encoding(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
service: str, service: str,
topic: str, topic: str,
@ -2051,7 +2047,7 @@ async def test_publishing_with_custom_encoding(
await help_test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
domain, domain,
config, config,
@ -2075,21 +2071,21 @@ async def test_reloadable(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_setup_manual_entity_from_yaml( async def test_setup_manual_entity_from_yaml(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
platform = fan.DOMAIN platform = fan.DOMAIN
assert hass.states.get(f"{platform}.test") assert hass.states.get(f"{platform}.test")
async def test_unload_entry( async def test_unload_entry(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = fan.DOMAIN domain = fan.DOMAIN
config = DEFAULT_CONFIG config = DEFAULT_CONFIG
await help_test_unload_config_entry_with_platform( await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_no_yaml_config, domain, config hass, mqtt_mock_entry, domain, config
) )

View File

@ -133,12 +133,12 @@ async def async_set_humidity(
) )
async def test_fail_setup_if_no_command_topic( async def test_fail_setup_if_no_command_topic(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test if command fails with command topic.""" """Test if command fails with command topic."""
with pytest.raises(AssertionError): with pytest.raises(AssertionError):
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
assert ( assert (
"Invalid config for [mqtt]: required key not provided @ data['mqtt']['humidifier'][0]['command_topic']. Got None" "Invalid config for [mqtt]: required key not provided @ data['mqtt']['humidifier'][0]['command_topic']. Got None"
in caplog.text in caplog.text
@ -177,11 +177,11 @@ async def test_fail_setup_if_no_command_topic(
) )
async def test_controlling_state_via_topic( async def test_controlling_state_via_topic(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test the controlling state via topic.""" """Test the controlling state via topic."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get("humidifier.test") state = hass.states.get("humidifier.test")
assert state.state == STATE_UNKNOWN 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( async def test_controlling_state_via_topic_and_json_message(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test the controlling state via topic and JSON message.""" """Test the controlling state via topic and JSON message."""
await hass.async_block_till_done() await hass.async_block_till_done()
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get("humidifier.test") state = hass.states.get("humidifier.test")
assert state.state == STATE_UNKNOWN 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( async def test_controlling_state_via_topic_and_json_message_shared_topic(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test the controlling state via topic and JSON message using a shared topic.""" """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") state = hass.states.get("humidifier.test")
assert state.state == STATE_UNKNOWN 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( async def test_sending_mqtt_commands_and_optimistic(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test optimistic mode without state topic.""" """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") state = hass.states.get("humidifier.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -547,11 +547,11 @@ async def test_sending_mqtt_commands_and_optimistic(
) )
async def test_sending_mqtt_command_templates_( async def test_sending_mqtt_command_templates_(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Testing command templates with optimistic mode without state topic.""" """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") state = hass.states.get("humidifier.test")
assert state.state == STATE_UNKNOWN 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( async def test_sending_mqtt_commands_and_explicit_optimistic(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test optimistic mode with state topic and turn on attributes.""" """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") state = hass.states.get("humidifier.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -753,7 +753,7 @@ async def test_sending_mqtt_commands_and_explicit_optimistic(
) )
async def test_encoding_subscribable_topics( async def test_encoding_subscribable_topics(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
topic: str, topic: str,
value: str, value: str,
attribute: str | None, attribute: str | None,
@ -765,7 +765,7 @@ async def test_encoding_subscribable_topics(
config[CONF_MODE_COMMAND_TOPIC] = "humidifier/some_mode_command_topic" config[CONF_MODE_COMMAND_TOPIC] = "humidifier/some_mode_command_topic"
await help_test_encoding_subscribable_topics( await help_test_encoding_subscribable_topics(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
humidifier.DOMAIN, humidifier.DOMAIN,
config, config,
topic, topic,
@ -796,11 +796,11 @@ async def test_encoding_subscribable_topics(
) )
async def test_attributes( async def test_attributes(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes.""" """Test attributes."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get("humidifier.test") state = hass.states.get("humidifier.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -939,15 +939,15 @@ async def test_attributes(
) )
async def test_validity_configurations( async def test_validity_configurations(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
valid: bool, valid: bool,
) -> None: ) -> None:
"""Test validity of configurations.""" """Test validity of configurations."""
if valid: if valid:
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
return return
with pytest.raises(AssertionError): with pytest.raises(AssertionError):
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -1043,49 +1043,49 @@ async def test_validity_configurations(
) )
async def test_supported_features( async def test_supported_features(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
name: str, name: str,
success: bool, success: bool,
features: humidifier.HumidifierEntityFeature | None, features: humidifier.HumidifierEntityFeature | None,
) -> None: ) -> None:
"""Test supported features.""" """Test supported features."""
if success: if success:
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get(f"humidifier.{name}") state = hass.states.get(f"humidifier.{name}")
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == features assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == features
return return
with pytest.raises(AssertionError): with pytest.raises(AssertionError):
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_availability_when_connection_lost( async def test_availability_when_connection_lost(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN hass, mqtt_mock_entry, humidifier.DOMAIN
) )
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_availability_without_topic( async def test_availability_without_topic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, humidifier.DOMAIN, DEFAULT_CONFIG
) )
async def test_default_availability_payload( async def test_default_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
await help_test_default_availability_payload( await help_test_default_availability_payload(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
humidifier.DOMAIN, humidifier.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
True, True,
@ -1095,12 +1095,12 @@ async def test_default_availability_payload(
async def test_custom_availability_payload( async def test_custom_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by custom payload with defined topic.""" """Test availability by custom payload with defined topic."""
await help_test_custom_availability_payload( await help_test_custom_availability_payload(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
humidifier.DOMAIN, humidifier.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
True, True,
@ -1110,21 +1110,21 @@ async def test_custom_availability_payload(
async def test_setting_attribute_via_mqtt_json_message( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message( await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_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( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_blocked_attribute_via_mqtt_json_message( await help_test_setting_blocked_attribute_via_mqtt_json_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
humidifier.DOMAIN, humidifier.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
MQTT_HUMIDIFIER_ATTRIBUTES_BLOCKED, 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( async def test_setting_attribute_with_template(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template( await help_test_setting_attribute_with_template(
hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, humidifier.DOMAIN, DEFAULT_CONFIG
) )
async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_not_dict(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_not_dict( await help_test_update_with_json_attrs_not_dict(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
humidifier.DOMAIN, humidifier.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -1157,13 +1157,13 @@ async def test_update_with_json_attrs_not_dict(
async def test_update_with_json_attrs_bad_json( async def test_update_with_json_attrs_bad_json(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_json( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
humidifier.DOMAIN, humidifier.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -1172,13 +1172,13 @@ async def test_update_with_json_attrs_bad_json(
async def test_discovery_update_attr( async def test_discovery_update_attr(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered MQTTAttributes.""" """Test update of discovered MQTTAttributes."""
await help_test_discovery_update_attr( await help_test_discovery_update_attr(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
humidifier.DOMAIN, humidifier.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -1211,27 +1211,27 @@ async def test_discovery_update_attr(
], ],
) )
async def test_unique_id( async def test_unique_id(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test unique_id option only creates one fan per id.""" """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( async def test_discovery_removal_humidifier(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test removal of discovered humidifier.""" """Test removal of discovered humidifier."""
data = '{ "name": "test", "command_topic": "test_topic", "target_humidity_command_topic": "test-topic2" }' data = '{ "name": "test", "command_topic": "test_topic", "target_humidity_command_topic": "test-topic2" }'
await help_test_discovery_removal( 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( async def test_discovery_update_humidifier(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered humidifier.""" """Test update of discovered humidifier."""
@ -1247,7 +1247,7 @@ async def test_discovery_update_humidifier(
} }
await help_test_discovery_update( await help_test_discovery_update(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
humidifier.DOMAIN, humidifier.DOMAIN,
config1, config1,
@ -1257,7 +1257,7 @@ async def test_discovery_update_humidifier(
async def test_discovery_update_unchanged_humidifier( async def test_discovery_update_unchanged_humidifier(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered humidifier.""" """Test update of discovered humidifier."""
@ -1267,7 +1267,7 @@ async def test_discovery_update_unchanged_humidifier(
) as discovery_update: ) as discovery_update:
await help_test_discovery_update_unchanged( await help_test_discovery_update_unchanged(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
humidifier.DOMAIN, humidifier.DOMAIN,
data1, data1,
@ -1278,78 +1278,78 @@ async def test_discovery_update_unchanged_humidifier(
@pytest.mark.no_fail_on_log_exception @pytest.mark.no_fail_on_log_exception
async def test_discovery_broken( async def test_discovery_broken(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test handling of bad discovery message.""" """Test handling of bad discovery message."""
data1 = '{ "name": "Beer" }' data1 = '{ "name": "Beer" }'
data2 = '{ "name": "Milk", "command_topic": "test_topic", "target_humidity_command_topic": "test-topic2" }' data2 = '{ "name": "Milk", "command_topic": "test_topic", "target_humidity_command_topic": "test-topic2" }'
await help_test_discovery_broken( 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( async def test_entity_device_info_with_connection(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT fan device registry integration.""" """Test MQTT fan device registry integration."""
await help_test_entity_device_info_with_connection( await help_test_entity_device_info_with_connection(
hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, humidifier.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_with_identifier( async def test_entity_device_info_with_identifier(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT fan device registry integration.""" """Test MQTT fan device registry integration."""
await help_test_entity_device_info_with_identifier( await help_test_entity_device_info_with_identifier(
hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, humidifier.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_update( async def test_entity_device_info_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry update.""" """Test device registry update."""
await help_test_entity_device_info_update( await help_test_entity_device_info_update(
hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, humidifier.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_remove( async def test_entity_device_info_remove(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry remove.""" """Test device registry remove."""
await help_test_entity_device_info_remove( await help_test_entity_device_info_remove(
hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, humidifier.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_subscriptions( async def test_entity_id_update_subscriptions(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT subscriptions are managed when entity_id is updated.""" """Test MQTT subscriptions are managed when entity_id is updated."""
await help_test_entity_id_update_subscriptions( await help_test_entity_id_update_subscriptions(
hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, humidifier.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_discovery_update( async def test_entity_id_update_discovery_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT discovery update when entity_id is updated.""" """Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update( await help_test_entity_id_update_discovery_update(
hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, humidifier.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_debug_info_message( async def test_entity_debug_info_message(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT debug info.""" """Test MQTT debug info."""
await help_test_entity_debug_info_message( await help_test_entity_debug_info_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
humidifier.DOMAIN, humidifier.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
humidifier.SERVICE_TURN_ON, humidifier.SERVICE_TURN_ON,
@ -1391,7 +1391,7 @@ async def test_entity_debug_info_message(
) )
async def test_publishing_with_custom_encoding( async def test_publishing_with_custom_encoding(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
service: str, service: str,
topic: str, topic: str,
@ -1407,7 +1407,7 @@ async def test_publishing_with_custom_encoding(
await help_test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
domain, domain,
config, config,
@ -1431,21 +1431,21 @@ async def test_reloadable(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_setup_manual_entity_from_yaml( async def test_setup_manual_entity_from_yaml(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
platform = humidifier.DOMAIN platform = humidifier.DOMAIN
assert hass.states.get(f"{platform}.test") assert hass.states.get(f"{platform}.test")
async def test_unload_config_entry( async def test_unload_config_entry(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = humidifier.DOMAIN domain = humidifier.DOMAIN
config = DEFAULT_CONFIG config = DEFAULT_CONFIG
await help_test_unload_config_entry_with_platform( await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_no_yaml_config, domain, config hass, mqtt_mock_entry, domain, config
) )

File diff suppressed because it is too large Load Diff

View File

@ -125,10 +125,10 @@ def vacuum_platform_only():
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_default_supported_features( async def test_default_supported_features(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test that the correct supported features.""" """Test that the correct supported features."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
entity = hass.states.get("vacuum.mqtttest") entity = hass.states.get("vacuum.mqtttest")
entity_features = entity.attributes.get(mqttvacuum.CONF_SUPPORTED_FEATURES, 0) entity_features = entity.attributes.get(mqttvacuum.CONF_SUPPORTED_FEATURES, 0)
assert sorted(services_to_strings(entity_features, SERVICE_TO_STRING)) == sorted( 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], [DEFAULT_CONFIG_ALL_SERVICES],
) )
async def test_all_commands( async def test_all_commands(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test simple commands to the vacuum.""" """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") await common.async_turn_on(hass, "vacuum.mqtttest")
mqtt_mock.async_publish.assert_called_once_with( mqtt_mock.async_publish.assert_called_once_with(
@ -240,10 +240,10 @@ async def test_all_commands(
], ],
) )
async def test_commands_without_supported_features( async def test_commands_without_supported_features(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test commands which are not supported by the vacuum.""" """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") await common.async_turn_on(hass, "vacuum.mqtttest")
mqtt_mock.async_publish.assert_not_called() 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( async def test_attributes_without_supported_features(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test attributes which are not supported by the vacuum.""" """Test attributes which are not supported by the vacuum."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
message = """{ message = """{
"battery_level": 54, "battery_level": 54,
@ -325,10 +325,10 @@ async def test_attributes_without_supported_features(
[DEFAULT_CONFIG_ALL_SERVICES], [DEFAULT_CONFIG_ALL_SERVICES],
) )
async def test_status( async def test_status(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test status updates from the vacuum.""" """Test status updates from the vacuum."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
message = """{ message = """{
"battery_level": 54, "battery_level": 54,
@ -365,10 +365,10 @@ async def test_status(
[DEFAULT_CONFIG_ALL_SERVICES], [DEFAULT_CONFIG_ALL_SERVICES],
) )
async def test_status_battery( async def test_status_battery(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test status updates from the vacuum.""" """Test status updates from the vacuum."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
message = """{ message = """{
"battery_level": 54 "battery_level": 54
@ -383,11 +383,11 @@ async def test_status_battery(
[DEFAULT_CONFIG_ALL_SERVICES], [DEFAULT_CONFIG_ALL_SERVICES],
) )
async def test_status_cleaning( async def test_status_cleaning(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test status updates from the vacuum.""" """Test status updates from the vacuum."""
await hass.async_block_till_done() await hass.async_block_till_done()
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
message = """{ message = """{
"cleaning": true "cleaning": true
@ -402,10 +402,10 @@ async def test_status_cleaning(
[DEFAULT_CONFIG_ALL_SERVICES], [DEFAULT_CONFIG_ALL_SERVICES],
) )
async def test_status_docked( async def test_status_docked(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test status updates from the vacuum.""" """Test status updates from the vacuum."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
message = """{ message = """{
"docked": true "docked": true
@ -420,10 +420,10 @@ async def test_status_docked(
[DEFAULT_CONFIG_ALL_SERVICES], [DEFAULT_CONFIG_ALL_SERVICES],
) )
async def test_status_charging( async def test_status_charging(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test status updates from the vacuum.""" """Test status updates from the vacuum."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
message = """{ message = """{
"charging": true "charging": true
@ -435,10 +435,10 @@ async def test_status_charging(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_ALL_SERVICES]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_ALL_SERVICES])
async def test_status_fan_speed( async def test_status_fan_speed(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test status updates from the vacuum.""" """Test status updates from the vacuum."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
message = """{ message = """{
"fan_speed": "max" "fan_speed": "max"
@ -450,10 +450,10 @@ async def test_status_fan_speed(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_ALL_SERVICES]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_ALL_SERVICES])
async def test_status_fan_speed_list( async def test_status_fan_speed_list(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test status updates from the vacuum.""" """Test status updates from the vacuum."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get("vacuum.mqtttest") state = hass.states.get("vacuum.mqtttest")
assert state.attributes.get(ATTR_FAN_SPEED_LIST) == ["min", "medium", "high", "max"] 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( async def test_status_no_fan_speed_list(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test status updates from the vacuum. """Test status updates from the vacuum.
If the vacuum doesn't support fan speed, fan speed list should be None. 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") state = hass.states.get("vacuum.mqtttest")
assert state.attributes.get(ATTR_FAN_SPEED_LIST) is None 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]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_ALL_SERVICES])
async def test_status_error( async def test_status_error(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test status updates from the vacuum.""" """Test status updates from the vacuum."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
message = """{ message = """{
"error": "Error1" "error": "Error1"
@ -526,10 +526,10 @@ async def test_status_error(
], ],
) )
async def test_battery_template( async def test_battery_template(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test that you can use non-default templates for battery_level.""" """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") async_fire_mqtt_message(hass, "retroroomba/battery_level", "54")
state = hass.states.get("vacuum.mqtttest") state = hass.states.get("vacuum.mqtttest")
@ -539,10 +539,10 @@ async def test_battery_template(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_ALL_SERVICES]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_ALL_SERVICES])
async def test_status_invalid_json( async def test_status_invalid_json(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test to make sure nothing breaks if the vacuum sends bad JSON.""" """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}') async_fire_mqtt_message(hass, "vacuum/state", '{"asdfasas false}')
state = hass.states.get("vacuum.mqtttest") state = hass.states.get("vacuum.mqtttest")
@ -563,12 +563,12 @@ async def test_status_invalid_json(
) )
async def test_missing_templates( async def test_missing_templates(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test to make sure missing template is not allowed.""" """Test to make sure missing template is not allowed."""
with pytest.raises(AssertionError): with pytest.raises(AssertionError):
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
assert ( assert (
"Invalid config for [mqtt]: some but not all values in the same group of inclusion" "Invalid config for [mqtt]: some but not all values in the same group of inclusion"
in caplog.text in caplog.text
@ -577,58 +577,58 @@ async def test_missing_templates(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_2]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_2])
async def test_availability_when_connection_lost( async def test_availability_when_connection_lost(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN hass, mqtt_mock_entry, vacuum.DOMAIN
) )
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_2]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_2])
async def test_availability_without_topic( async def test_availability_without_topic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2 hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2
) )
async def test_default_availability_payload( async def test_default_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
await help_test_default_availability_payload( await help_test_default_availability_payload(
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2 hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2
) )
async def test_custom_availability_payload( async def test_custom_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by custom payload with defined topic.""" """Test availability by custom payload with defined topic."""
await help_test_custom_availability_payload( await help_test_custom_availability_payload(
hass, mqtt_mock_entry_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( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message( await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_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( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_blocked_attribute_via_mqtt_json_message( await help_test_setting_blocked_attribute_via_mqtt_json_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
vacuum.DOMAIN, vacuum.DOMAIN,
DEFAULT_CONFIG_2, DEFAULT_CONFIG_2,
MQTT_LEGACY_VACUUM_ATTRIBUTES_BLOCKED, 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( async def test_setting_attribute_with_template(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template( await help_test_setting_attribute_with_template(
hass, mqtt_mock_entry_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( async def test_update_with_json_attrs_not_dict(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_not_dict( await help_test_update_with_json_attrs_not_dict(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
vacuum.DOMAIN, vacuum.DOMAIN,
DEFAULT_CONFIG_2, 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( async def test_update_with_json_attrs_bad_json(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_json( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
vacuum.DOMAIN, vacuum.DOMAIN,
DEFAULT_CONFIG_2, DEFAULT_CONFIG_2,
@ -676,13 +676,13 @@ async def test_update_with_json_attrs_bad_json(
async def test_discovery_update_attr( async def test_discovery_update_attr(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered MQTTAttributes.""" """Test update of discovered MQTTAttributes."""
await help_test_discovery_update_attr( await help_test_discovery_update_attr(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
vacuum.DOMAIN, vacuum.DOMAIN,
DEFAULT_CONFIG_2, DEFAULT_CONFIG_2,
@ -711,40 +711,40 @@ async def test_discovery_update_attr(
], ],
) )
async def test_unique_id( async def test_unique_id(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test unique id option only creates one vacuum per unique_id.""" """Test unique id option only creates one vacuum per unique_id."""
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( async def test_discovery_removal_vacuum(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test removal of discovered vacuum.""" """Test removal of discovered vacuum."""
data = json.dumps(DEFAULT_CONFIG_2[mqtt.DOMAIN][vacuum.DOMAIN]) data = json.dumps(DEFAULT_CONFIG_2[mqtt.DOMAIN][vacuum.DOMAIN])
await help_test_discovery_removal( await help_test_discovery_removal(
hass, mqtt_mock_entry_no_yaml_config, caplog, vacuum.DOMAIN, data hass, mqtt_mock_entry, caplog, vacuum.DOMAIN, data
) )
async def test_discovery_update_vacuum( async def test_discovery_update_vacuum(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered vacuum.""" """Test update of discovered vacuum."""
config1 = {"name": "Beer", "command_topic": "test_topic"} config1 = {"name": "Beer", "command_topic": "test_topic"}
config2 = {"name": "Milk", "command_topic": "test_topic"} config2 = {"name": "Milk", "command_topic": "test_topic"}
await help_test_discovery_update( 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( async def test_discovery_update_unchanged_vacuum(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered vacuum.""" """Test update of discovered vacuum."""
@ -754,7 +754,7 @@ async def test_discovery_update_unchanged_vacuum(
) as discovery_update: ) as discovery_update:
await help_test_discovery_update_unchanged( await help_test_discovery_update_unchanged(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
vacuum.DOMAIN, vacuum.DOMAIN,
data1, data1,
@ -765,55 +765,55 @@ async def test_discovery_update_unchanged_vacuum(
@pytest.mark.no_fail_on_log_exception @pytest.mark.no_fail_on_log_exception
async def test_discovery_broken( async def test_discovery_broken(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test handling of bad discovery message.""" """Test handling of bad discovery message."""
data1 = '{ "name": "Beer",' ' "command_topic": "test_topic#" }' data1 = '{ "name": "Beer",' ' "command_topic": "test_topic#" }'
data2 = '{ "name": "Milk",' ' "command_topic": "test_topic" }' data2 = '{ "name": "Milk",' ' "command_topic": "test_topic" }'
await help_test_discovery_broken( 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( async def test_entity_device_info_with_connection(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT vacuum device registry integration.""" """Test MQTT vacuum device registry integration."""
await help_test_entity_device_info_with_connection( await help_test_entity_device_info_with_connection(
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2 hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2
) )
async def test_entity_device_info_with_identifier( async def test_entity_device_info_with_identifier(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT vacuum device registry integration.""" """Test MQTT vacuum device registry integration."""
await help_test_entity_device_info_with_identifier( await help_test_entity_device_info_with_identifier(
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2 hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2
) )
async def test_entity_device_info_update( async def test_entity_device_info_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry update.""" """Test device registry update."""
await help_test_entity_device_info_update( await help_test_entity_device_info_update(
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2 hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2
) )
async def test_entity_device_info_remove( async def test_entity_device_info_remove(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry remove.""" """Test device registry remove."""
await help_test_entity_device_info_remove( await help_test_entity_device_info_remove(
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2 hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2
) )
async def test_entity_id_update_subscriptions( async def test_entity_id_update_subscriptions(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT subscriptions are managed when entity_id is updated.""" """Test MQTT subscriptions are managed when entity_id is updated."""
config = { config = {
@ -829,7 +829,7 @@ async def test_entity_id_update_subscriptions(
} }
await help_test_entity_id_update_subscriptions( await help_test_entity_id_update_subscriptions(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
vacuum.DOMAIN, vacuum.DOMAIN,
config, config,
["test-topic", "avty-topic"], ["test-topic", "avty-topic"],
@ -837,16 +837,16 @@ async def test_entity_id_update_subscriptions(
async def test_entity_id_update_discovery_update( async def test_entity_id_update_discovery_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT discovery update when entity_id is updated.""" """Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update( await help_test_entity_id_update_discovery_update(
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2 hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2
) )
async def test_entity_debug_info_message( async def test_entity_debug_info_message(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT debug info.""" """Test MQTT debug info."""
config = { config = {
@ -862,7 +862,7 @@ async def test_entity_debug_info_message(
} }
await help_test_entity_debug_info_message( await help_test_entity_debug_info_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
vacuum.DOMAIN, vacuum.DOMAIN,
config, config,
vacuum.SERVICE_TURN_ON, vacuum.SERVICE_TURN_ON,
@ -911,7 +911,7 @@ async def test_entity_debug_info_message(
) )
async def test_publishing_with_custom_encoding( async def test_publishing_with_custom_encoding(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
service: str, service: str,
topic: str, topic: str,
@ -932,7 +932,7 @@ async def test_publishing_with_custom_encoding(
await help_test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
domain, domain,
config, config,
@ -977,7 +977,7 @@ async def test_reloadable(
) )
async def test_encoding_subscribable_topics( async def test_encoding_subscribable_topics(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
topic: str, topic: str,
value: str, value: str,
attribute: str | None, attribute: str | None,
@ -1002,7 +1002,7 @@ async def test_encoding_subscribable_topics(
await help_test_encoding_subscribable_topics( await help_test_encoding_subscribable_topics(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
vacuum.DOMAIN, vacuum.DOMAIN,
config, config,
topic, topic,
@ -1015,9 +1015,9 @@ async def test_encoding_subscribable_topics(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_setup_manual_entity_from_yaml( async def test_setup_manual_entity_from_yaml(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
platform = vacuum.DOMAIN platform = vacuum.DOMAIN
assert hass.states.get(f"{platform}.mqtttest") assert hass.states.get(f"{platform}.mqtttest")

View File

@ -247,12 +247,12 @@ def light_platform_only():
) )
async def test_fail_setup_if_no_command_topic( async def test_fail_setup_if_no_command_topic(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test if command fails with command topic.""" """Test if command fails with command topic."""
with pytest.raises(AssertionError): with pytest.raises(AssertionError):
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
assert ( assert (
"Invalid config for [mqtt]: required key not provided @ data['mqtt']['light'][0]['command_topic']. Got None." "Invalid config for [mqtt]: required key not provided @ data['mqtt']['light'][0]['command_topic']. Got None."
in caplog.text 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( 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: ) -> None:
"""Test if there is no color and brightness if no topic.""" """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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN 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( async def test_controlling_state_via_topic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the controlling of the state via topic.""" """Test the controlling of the state via topic."""
color_modes = ["color_temp", "hs", "rgb", "rgbw", "rgbww", "xy"] 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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -480,11 +480,11 @@ async def test_controlling_state_via_topic(
) )
async def test_invalid_state_via_topic( async def test_invalid_state_via_topic(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test handling of empty data via topic.""" """Test handling of empty data via topic."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get("light.test") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -597,10 +597,10 @@ async def test_invalid_state_via_topic(
], ],
) )
async def test_brightness_controlling_scale( async def test_brightness_controlling_scale(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the brightness controlling scale.""" """Test the brightness controlling scale."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get("light.test") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -646,10 +646,10 @@ async def test_brightness_controlling_scale(
], ],
) )
async def test_brightness_from_rgb_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: ) -> None:
"""Test the brightness controlling scale.""" """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() await hass.async_block_till_done()
state = hass.states.get("light.test") 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( 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: ) -> None:
"""Test the setting of the state with a template.""" """Test the setting of the state with a template."""
color_modes = ["color_temp", "hs", "rgb", "rgbw", "rgbww", "xy"] 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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN 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( async def test_sending_mqtt_commands_and_optimistic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the sending of command in optimistic mode.""" """Test the sending of command in optimistic mode."""
color_modes = ["color_temp", "hs", "rgb", "rgbw", "rgbww", "xy"] 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,)) 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") state = hass.states.get("light.test")
assert state.state == STATE_ON 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( 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: ) -> None:
"""Test the sending of RGB command with template.""" """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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN 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( 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: ) -> None:
"""Test the sending of RGBW command with template.""" """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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN 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( 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: ) -> None:
"""Test the sending of RGBWW command with template.""" """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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN 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( 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: ) -> None:
"""Test the sending of Color Temp command with template.""" """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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN 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( async def test_on_command_first(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test on command being sent before brightness.""" """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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -1217,10 +1217,10 @@ async def test_on_command_first(
], ],
) )
async def test_on_command_last( async def test_on_command_last(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test on command being sent after brightness.""" """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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -1260,10 +1260,10 @@ async def test_on_command_last(
], ],
) )
async def test_on_command_brightness( async def test_on_command_brightness(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test on command being sent as only brightness.""" """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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -1322,10 +1322,10 @@ async def test_on_command_brightness(
], ],
) )
async def test_on_command_brightness_scaled( async def test_on_command_brightness_scaled(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test brightness scale.""" """Test brightness scale."""
mqtt_mock = await mqtt_mock_entry_no_yaml_config() mqtt_mock = await mqtt_mock_entry()
state = hass.states.get("light.test") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -1395,10 +1395,10 @@ async def test_on_command_brightness_scaled(
], ],
) )
async def test_on_command_rgb( async def test_on_command_rgb(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test on command in RGB brightness mode.""" """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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -1491,10 +1491,10 @@ async def test_on_command_rgb(
], ],
) )
async def test_on_command_rgbw( async def test_on_command_rgbw(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test on command in RGBW brightness mode.""" """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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -1587,10 +1587,10 @@ async def test_on_command_rgbw(
], ],
) )
async def test_on_command_rgbww( async def test_on_command_rgbww(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test on command in RGBWW brightness mode.""" """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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -1684,10 +1684,10 @@ async def test_on_command_rgbww(
], ],
) )
async def test_on_command_rgb_template( async def test_on_command_rgb_template(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test on command in RGB brightness mode with RGB template.""" """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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -1727,10 +1727,10 @@ async def test_on_command_rgb_template(
], ],
) )
async def test_on_command_rgbw_template( async def test_on_command_rgbw_template(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test on command in RGBW brightness mode with RGBW template.""" """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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -1770,10 +1770,10 @@ async def test_on_command_rgbw_template(
], ],
) )
async def test_on_command_rgbww_template( async def test_on_command_rgbww_template(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test on command in RGBWW brightness mode with RGBWW template.""" """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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -1824,12 +1824,12 @@ async def test_on_command_rgbww_template(
], ],
) )
async def test_on_command_white( async def test_on_command_white(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test sending commands for RGB + white light.""" """Test sending commands for RGB + white light."""
color_modes = ["rgb", "white"] 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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -1916,12 +1916,12 @@ async def test_on_command_white(
], ],
) )
async def test_explicit_color_mode( async def test_explicit_color_mode(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test explicit color mode over mqtt.""" """Test explicit color mode over mqtt."""
color_modes = ["color_temp", "hs", "rgb", "rgbw", "rgbww", "xy"] 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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -2062,12 +2062,12 @@ async def test_explicit_color_mode(
], ],
) )
async def test_explicit_color_mode_templated( async def test_explicit_color_mode_templated(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test templated explicit color mode over mqtt.""" """Test templated explicit color mode over mqtt."""
color_modes = ["color_temp", "hs"] color_modes = ["color_temp", "hs"]
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get("light.test") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -2157,12 +2157,12 @@ async def test_explicit_color_mode_templated(
], ],
) )
async def test_white_state_update( async def test_white_state_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test state updates for RGB + white light.""" """Test state updates for RGB + white light."""
color_modes = ["rgb", "white"] color_modes = ["rgb", "white"]
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get("light.test") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -2213,10 +2213,10 @@ async def test_white_state_update(
], ],
) )
async def test_effect( async def test_effect(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test effect.""" """Test effect."""
mqtt_mock = await mqtt_mock_entry_no_yaml_config() mqtt_mock = await mqtt_mock_entry()
state = hass.states.get("light.test") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -2242,58 +2242,58 @@ async def test_effect(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_availability_when_connection_lost( async def test_availability_when_connection_lost(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN hass, mqtt_mock_entry, light.DOMAIN
) )
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_availability_without_topic( async def test_availability_without_topic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_default_availability_payload( async def test_default_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
await help_test_default_availability_payload( await help_test_default_availability_payload(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_custom_availability_payload( async def test_custom_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by custom payload with defined topic.""" """Test availability by custom payload with defined topic."""
await help_test_custom_availability_payload( await help_test_custom_availability_payload(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_setting_attribute_via_mqtt_json_message( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message( await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_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( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_blocked_attribute_via_mqtt_json_message( await help_test_setting_blocked_attribute_via_mqtt_json_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
light.DOMAIN, light.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
MQTT_LIGHT_ATTRIBUTES_BLOCKED, 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( async def test_setting_attribute_with_template(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template( await help_test_setting_attribute_with_template(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_not_dict(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_not_dict( await help_test_update_with_json_attrs_not_dict(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
light.DOMAIN, light.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -2326,13 +2326,13 @@ async def test_update_with_json_attrs_not_dict(
async def test_update_with_json_attrs_bad_json( async def test_update_with_json_attrs_bad_json(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_json( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
light.DOMAIN, light.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -2341,13 +2341,13 @@ async def test_update_with_json_attrs_bad_json(
async def test_discovery_update_attr( async def test_discovery_update_attr(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered MQTTAttributes.""" """Test update of discovered MQTTAttributes."""
await help_test_discovery_update_attr( await help_test_discovery_update_attr(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
light.DOMAIN, light.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -2378,15 +2378,15 @@ async def test_discovery_update_attr(
], ],
) )
async def test_unique_id( async def test_unique_id(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test unique id option only creates one light per unique_id.""" """Test unique id option only creates one light per unique_id."""
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( async def test_discovery_removal_light(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test removal of discovered light.""" """Test removal of discovered light."""
@ -2395,18 +2395,16 @@ async def test_discovery_removal_light(
' "state_topic": "test_topic",' ' "state_topic": "test_topic",'
' "command_topic": "test_topic" }' ' "command_topic": "test_topic" }'
) )
await help_test_discovery_removal( await help_test_discovery_removal(hass, mqtt_mock_entry, caplog, light.DOMAIN, data)
hass, mqtt_mock_entry_no_yaml_config, caplog, light.DOMAIN, data
)
async def test_discovery_ignores_extra_keys( async def test_discovery_ignores_extra_keys(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test discovery ignores extra keys that are not blocked.""" """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 # inserted `platform` key should be ignored
data = ( data = (
'{ "name": "Beer",' ' "platform": "mqtt",' ' "command_topic": "test_topic"}' '{ "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( async def test_discovery_update_light_topic_and_template(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered light.""" """Test update of discovered light."""
@ -2665,7 +2663,7 @@ async def test_discovery_update_light_topic_and_template(
await help_test_discovery_update( await help_test_discovery_update(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
light.DOMAIN, light.DOMAIN,
config1, config1,
@ -2677,7 +2675,7 @@ async def test_discovery_update_light_topic_and_template(
async def test_discovery_update_light_template( async def test_discovery_update_light_template(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered light.""" """Test update of discovered light."""
@ -2880,7 +2878,7 @@ async def test_discovery_update_light_template(
await help_test_discovery_update( await help_test_discovery_update(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
light.DOMAIN, light.DOMAIN,
config1, config1,
@ -2892,7 +2890,7 @@ async def test_discovery_update_light_template(
async def test_discovery_update_unchanged_light( async def test_discovery_update_unchanged_light(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered light.""" """Test update of discovered light."""
@ -2906,7 +2904,7 @@ async def test_discovery_update_unchanged_light(
) as discovery_update: ) as discovery_update:
await help_test_discovery_update_unchanged( await help_test_discovery_update_unchanged(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
light.DOMAIN, light.DOMAIN,
data1, data1,
@ -2917,7 +2915,7 @@ async def test_discovery_update_unchanged_light(
@pytest.mark.no_fail_on_log_exception @pytest.mark.no_fail_on_log_exception
async def test_discovery_broken( async def test_discovery_broken(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test handling of bad discovery message.""" """Test handling of bad discovery message."""
@ -2928,71 +2926,71 @@ async def test_discovery_broken(
' "command_topic": "test_topic" }' ' "command_topic": "test_topic" }'
) )
await help_test_discovery_broken( 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( async def test_entity_device_info_with_connection(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT light device registry integration.""" """Test MQTT light device registry integration."""
await help_test_entity_device_info_with_connection( await help_test_entity_device_info_with_connection(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_with_identifier( async def test_entity_device_info_with_identifier(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT light device registry integration.""" """Test MQTT light device registry integration."""
await help_test_entity_device_info_with_identifier( await help_test_entity_device_info_with_identifier(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_update( async def test_entity_device_info_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry update.""" """Test device registry update."""
await help_test_entity_device_info_update( await help_test_entity_device_info_update(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_remove( async def test_entity_device_info_remove(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry remove.""" """Test device registry remove."""
await help_test_entity_device_info_remove( await help_test_entity_device_info_remove(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_subscriptions( async def test_entity_id_update_subscriptions(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT subscriptions are managed when entity_id is updated.""" """Test MQTT subscriptions are managed when entity_id is updated."""
await help_test_entity_id_update_subscriptions( await help_test_entity_id_update_subscriptions(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_discovery_update( async def test_entity_id_update_discovery_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT discovery update when entity_id is updated.""" """Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update( await help_test_entity_id_update_discovery_update(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_debug_info_message( async def test_entity_debug_info_message(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT debug info.""" """Test MQTT debug info."""
await help_test_entity_debug_info_message( await help_test_entity_debug_info_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
light.DOMAIN, light.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
light.SERVICE_TURN_ON, light.SERVICE_TURN_ON,
@ -3015,10 +3013,10 @@ async def test_entity_debug_info_message(
], ],
) )
async def test_max_mireds( async def test_max_mireds(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setting min_mireds and max_mireds.""" """Test setting min_mireds and max_mireds."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get("light.test") state = hass.states.get("light.test")
assert state.attributes.get("min_mireds") == 153 assert state.attributes.get("min_mireds") == 153
@ -3113,7 +3111,7 @@ async def test_max_mireds(
) )
async def test_publishing_with_custom_encoding( async def test_publishing_with_custom_encoding(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
service: str, service: str,
topic: str, topic: str,
@ -3133,7 +3131,7 @@ async def test_publishing_with_custom_encoding(
await help_test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
domain, domain,
config, config,
@ -3189,7 +3187,7 @@ async def test_reloadable(
) )
async def test_encoding_subscribable_topics( async def test_encoding_subscribable_topics(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
topic: str, topic: str,
value: str, value: str,
attribute: str | None, attribute: str | None,
@ -3211,7 +3209,7 @@ async def test_encoding_subscribable_topics(
await help_test_encoding_subscribable_topics( await help_test_encoding_subscribable_topics(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
light.DOMAIN, light.DOMAIN,
config, config,
topic, topic,
@ -3230,7 +3228,7 @@ async def test_encoding_subscribable_topics(
) )
async def test_encoding_subscribable_topics_brightness( async def test_encoding_subscribable_topics_brightness(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
topic: str, topic: str,
value: str, value: str,
@ -3244,7 +3242,7 @@ async def test_encoding_subscribable_topics_brightness(
await help_test_encoding_subscribable_topics( await help_test_encoding_subscribable_topics(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
light.DOMAIN, light.DOMAIN,
config, config,
topic, topic,
@ -3274,10 +3272,10 @@ async def test_encoding_subscribable_topics_brightness(
], ],
) )
async def test_sending_mqtt_brightness_command_with_template( 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: ) -> None:
"""Test the sending of Brightness command with template.""" """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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN 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( 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: ) -> None:
"""Test the sending of Effect command with template.""" """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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN 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( 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: ) -> None:
"""Test the sending of HS Color command with template.""" """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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN 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( 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: ) -> None:
"""Test the sending of XY Color command with template.""" """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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN 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]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_setup_manual_entity_from_yaml( async def test_setup_manual_entity_from_yaml(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
platform = light.DOMAIN platform = light.DOMAIN
assert hass.states.get(f"{platform}.test") assert hass.states.get(f"{platform}.test")
async def test_unload_entry( async def test_unload_entry(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = light.DOMAIN domain = light.DOMAIN
config = DEFAULT_CONFIG config = DEFAULT_CONFIG
await help_test_unload_config_entry_with_platform( await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_no_yaml_config, domain, config hass, mqtt_mock_entry, domain, config
) )

View File

@ -192,12 +192,12 @@ class JsonValidator:
) )
async def test_fail_setup_if_no_command_topic( async def test_fail_setup_if_no_command_topic(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test if setup fails with no command topic.""" """Test if setup fails with no command topic."""
with pytest.raises(AssertionError): with pytest.raises(AssertionError):
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
assert ( assert (
"Invalid config for [mqtt]: required key not provided @ data['mqtt']['light'][0]['command_topic']. Got None." "Invalid config for [mqtt]: required key not provided @ data['mqtt']['light'][0]['command_topic']. Got None."
in caplog.text 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( async def test_fail_setup_if_color_mode_deprecated(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test if setup fails if color mode is combined with deprecated config keys.""" """Test if setup fails if color mode is combined with deprecated config keys."""
with pytest.raises(AssertionError): with pytest.raises(AssertionError):
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
assert ( assert (
"Invalid config for [mqtt]: color_mode must not be combined with any of" "Invalid config for [mqtt]: color_mode must not be combined with any of"
in caplog.text 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( async def test_fail_setup_if_color_modes_invalid(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
error: str, error: str,
) -> None: ) -> None:
"""Test if setup fails if supported color modes is invalid.""" """Test if setup fails if supported color modes is invalid."""
with pytest.raises(AssertionError): with pytest.raises(AssertionError):
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
assert error in caplog.text assert error in caplog.text
@ -284,10 +284,10 @@ async def test_fail_setup_if_color_modes_invalid(
], ],
) )
async def test_legacy_rgb_light( async def test_legacy_rgb_light(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test legacy RGB light flags expected features and color modes.""" """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") state = hass.states.get("light.test")
color_modes = [light.ColorMode.HS] 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( 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: ) -> None:
"""Test for no RGB, brightness, color temp, effector XY.""" """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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN 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( async def test_controlling_state_via_topic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the controlling of the state via topic.""" """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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -504,12 +504,12 @@ async def test_controlling_state_via_topic(
) )
async def test_controlling_state_via_topic2( async def test_controlling_state_via_topic2(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test the controlling of the state via topic for a light supporting color mode.""" """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"] 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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -681,7 +681,7 @@ async def test_controlling_state_via_topic2(
], ],
) )
async def test_sending_mqtt_commands_and_optimistic( async def test_sending_mqtt_commands_and_optimistic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the sending of command in optimistic mode.""" """Test the sending of command in optimistic mode."""
fake_state = State( fake_state = State(
@ -696,7 +696,7 @@ async def test_sending_mqtt_commands_and_optimistic(
) )
mock_restore_cache(hass, (fake_state,)) 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") state = hass.states.get("light.test")
assert state.state == STATE_ON 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( async def test_sending_mqtt_commands_and_optimistic2(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the sending of command in optimistic mode for a light supporting color mode.""" """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"] 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,)) 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") state = hass.states.get("light.test")
assert state.state == STATE_ON assert state.state == STATE_ON
@ -1063,10 +1063,10 @@ async def test_sending_mqtt_commands_and_optimistic2(
], ],
) )
async def test_sending_hs_color( async def test_sending_hs_color(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test light.turn_on with hs color sends hs color parameters.""" """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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -1125,11 +1125,11 @@ async def test_sending_hs_color(
], ],
) )
async def test_sending_rgb_color_no_brightness( async def test_sending_rgb_color_no_brightness(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test light.turn_on with hs color sends rgb color parameters.""" """Test light.turn_on with hs color sends rgb color parameters."""
await hass.async_block_till_done() 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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN 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( async def test_sending_rgb_color_no_brightness2(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test light.turn_on with hs color sends rgb color parameters.""" """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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN 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( async def test_sending_rgb_color_with_brightness(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test light.turn_on with hs color sends rgb color parameters.""" """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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN 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( 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: ) -> None:
"""Test light.turn_on with hs color sends rgb color parameters.""" """Test light.turn_on with hs color sends rgb color parameters."""
await hass.async_block_till_done() 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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -1405,10 +1405,10 @@ async def test_sending_rgb_color_with_scaled_brightness(
], ],
) )
async def test_sending_scaled_white( async def test_sending_scaled_white(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test light.turn_on with scaled white.""" """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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -1449,10 +1449,10 @@ async def test_sending_scaled_white(
], ],
) )
async def test_sending_xy_color( async def test_sending_xy_color(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test light.turn_on with hs color sends xy color parameters.""" """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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -1511,10 +1511,10 @@ async def test_sending_xy_color(
], ],
) )
async def test_effect( async def test_effect(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test for effect being sent when included.""" """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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -1578,10 +1578,10 @@ async def test_effect(
], ],
) )
async def test_flash_short_and_long( async def test_flash_short_and_long(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test for flash length being sent when included.""" """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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -1641,10 +1641,10 @@ async def test_flash_short_and_long(
], ],
) )
async def test_transition( async def test_transition(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test for transition time being sent when included.""" """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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -1693,10 +1693,10 @@ async def test_transition(
], ],
) )
async def test_brightness_scale( async def test_brightness_scale(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test for brightness scaling.""" """Test for brightness scaling."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get("light.test") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -1741,10 +1741,10 @@ async def test_brightness_scale(
], ],
) )
async def test_white_scale( async def test_white_scale(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test for white scaling.""" """Test for white scaling."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get("light.test") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -1801,10 +1801,10 @@ async def test_white_scale(
], ],
) )
async def test_invalid_values( async def test_invalid_values(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test that invalid color/brightness/etc. values are ignored.""" """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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -1912,58 +1912,58 @@ async def test_invalid_values(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_availability_when_connection_lost( async def test_availability_when_connection_lost(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN hass, mqtt_mock_entry, light.DOMAIN
) )
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_availability_without_topic( async def test_availability_without_topic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_default_availability_payload( async def test_default_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
await help_test_default_availability_payload( await help_test_default_availability_payload(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_custom_availability_payload( async def test_custom_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by custom payload with defined topic.""" """Test availability by custom payload with defined topic."""
await help_test_custom_availability_payload( await help_test_custom_availability_payload(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_setting_attribute_via_mqtt_json_message( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message( await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_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( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_blocked_attribute_via_mqtt_json_message( await help_test_setting_blocked_attribute_via_mqtt_json_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
light.DOMAIN, light.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
MQTT_LIGHT_ATTRIBUTES_BLOCKED, 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( async def test_setting_attribute_with_template(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template( await help_test_setting_attribute_with_template(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_not_dict(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_not_dict( await help_test_update_with_json_attrs_not_dict(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
light.DOMAIN, light.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -1996,13 +1996,13 @@ async def test_update_with_json_attrs_not_dict(
async def test_update_with_json_attrs_bad_json( async def test_update_with_json_attrs_bad_json(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_json( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
light.DOMAIN, light.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -2011,13 +2011,13 @@ async def test_update_with_json_attrs_bad_json(
async def test_discovery_update_attr( async def test_discovery_update_attr(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered MQTTAttributes.""" """Test update of discovered MQTTAttributes."""
await help_test_discovery_update_attr( await help_test_discovery_update_attr(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
light.DOMAIN, light.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -2050,22 +2050,22 @@ async def test_discovery_update_attr(
], ],
) )
async def test_unique_id( async def test_unique_id(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test unique id option only creates one light per unique_id.""" """Test unique id option only creates one light per unique_id."""
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( async def test_discovery_removal(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test removal of discovered mqtt_json lights.""" """Test removal of discovered mqtt_json lights."""
data = '{ "name": "test", "schema": "json", "command_topic": "test_topic" }' data = '{ "name": "test", "schema": "json", "command_topic": "test_topic" }'
await help_test_discovery_removal( await help_test_discovery_removal(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
light.DOMAIN, light.DOMAIN,
data, data,
@ -2074,7 +2074,7 @@ async def test_discovery_removal(
async def test_discovery_update_light( async def test_discovery_update_light(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered light.""" """Test update of discovered light."""
@ -2092,7 +2092,7 @@ async def test_discovery_update_light(
} }
await help_test_discovery_update( await help_test_discovery_update(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
light.DOMAIN, light.DOMAIN,
config1, config1,
@ -2102,7 +2102,7 @@ async def test_discovery_update_light(
async def test_discovery_update_unchanged_light( async def test_discovery_update_unchanged_light(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered light.""" """Test update of discovered light."""
@ -2117,7 +2117,7 @@ async def test_discovery_update_unchanged_light(
) as discovery_update: ) as discovery_update:
await help_test_discovery_update_unchanged( await help_test_discovery_update_unchanged(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
light.DOMAIN, light.DOMAIN,
data1, data1,
@ -2128,7 +2128,7 @@ async def test_discovery_update_unchanged_light(
@pytest.mark.no_fail_on_log_exception @pytest.mark.no_fail_on_log_exception
async def test_discovery_broken( async def test_discovery_broken(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test handling of bad discovery message.""" """Test handling of bad discovery message."""
@ -2141,7 +2141,7 @@ async def test_discovery_broken(
) )
await help_test_discovery_broken( await help_test_discovery_broken(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
light.DOMAIN, light.DOMAIN,
data1, data1,
@ -2150,78 +2150,78 @@ async def test_discovery_broken(
async def test_entity_device_info_with_connection( async def test_entity_device_info_with_connection(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT light device registry integration.""" """Test MQTT light device registry integration."""
await help_test_entity_device_info_with_connection( await help_test_entity_device_info_with_connection(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
light.DOMAIN, light.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
) )
async def test_entity_device_info_with_identifier( async def test_entity_device_info_with_identifier(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT light device registry integration.""" """Test MQTT light device registry integration."""
await help_test_entity_device_info_with_identifier( await help_test_entity_device_info_with_identifier(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
light.DOMAIN, light.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
) )
async def test_entity_device_info_update( async def test_entity_device_info_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry update.""" """Test device registry update."""
await help_test_entity_device_info_update( await help_test_entity_device_info_update(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
light.DOMAIN, light.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
) )
async def test_entity_device_info_remove( async def test_entity_device_info_remove(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry remove.""" """Test device registry remove."""
await help_test_entity_device_info_remove( await help_test_entity_device_info_remove(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
light.DOMAIN, light.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
) )
async def test_entity_id_update_subscriptions( async def test_entity_id_update_subscriptions(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT subscriptions are managed when entity_id is updated.""" """Test MQTT subscriptions are managed when entity_id is updated."""
await help_test_entity_id_update_subscriptions( await help_test_entity_id_update_subscriptions(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_discovery_update( async def test_entity_id_update_discovery_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT discovery update when entity_id is updated.""" """Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update( await help_test_entity_id_update_discovery_update(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_debug_info_message( async def test_entity_debug_info_message(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT debug info.""" """Test MQTT debug info."""
await help_test_entity_debug_info_message( await help_test_entity_debug_info_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
light.DOMAIN, light.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
light.SERVICE_TURN_ON, light.SERVICE_TURN_ON,
@ -2247,10 +2247,10 @@ async def test_entity_debug_info_message(
], ],
) )
async def test_max_mireds( async def test_max_mireds(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setting min_mireds and max_mireds.""" """Test setting min_mireds and max_mireds."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get("light.test") state = hass.states.get("light.test")
assert state.attributes.get("min_mireds") == 153 assert state.attributes.get("min_mireds") == 153
@ -2282,7 +2282,7 @@ async def test_max_mireds(
) )
async def test_publishing_with_custom_encoding( async def test_publishing_with_custom_encoding(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
service: str, service: str,
topic: str, topic: str,
@ -2300,7 +2300,7 @@ async def test_publishing_with_custom_encoding(
await help_test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
domain, domain,
config, config,
@ -2338,7 +2338,7 @@ async def test_reloadable(
) )
async def test_encoding_subscribable_topics( async def test_encoding_subscribable_topics(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
topic: str, topic: str,
value: str, value: str,
attribute: str | None, attribute: str | None,
@ -2358,7 +2358,7 @@ async def test_encoding_subscribable_topics(
] ]
await help_test_encoding_subscribable_topics( await help_test_encoding_subscribable_topics(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
light.DOMAIN, light.DOMAIN,
config, config,
topic, topic,
@ -2372,9 +2372,9 @@ async def test_encoding_subscribable_topics(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_setup_manual_entity_from_yaml( async def test_setup_manual_entity_from_yaml(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
platform = light.DOMAIN platform = light.DOMAIN
assert hass.states.get(f"{platform}.test") assert hass.states.get(f"{platform}.test")

View File

@ -141,12 +141,12 @@ def light_platform_only():
) )
async def test_setup_fails( async def test_setup_fails(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test that setup fails with missing required configuration items.""" """Test that setup fails with missing required configuration items."""
with pytest.raises(AssertionError): with pytest.raises(AssertionError):
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
assert "Invalid config" in caplog.text assert "Invalid config" in caplog.text
@ -170,10 +170,10 @@ async def test_setup_fails(
], ],
) )
async def test_rgb_light( async def test_rgb_light(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test RGB light flags brightness support.""" """Test RGB light flags brightness support."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get("light.test") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -207,10 +207,10 @@ async def test_rgb_light(
], ],
) )
async def test_state_change_via_topic( async def test_state_change_via_topic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test state change via topic.""" """Test state change via topic."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get("light.test") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN 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( 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: ) -> None:
"""Test state, bri, color, effect, color temp change.""" """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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN 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( async def test_sending_mqtt_commands_and_optimistic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the sending of command in optimistic mode.""" """Test the sending of command in optimistic mode."""
fake_state = State( fake_state = State(
@ -397,7 +397,7 @@ async def test_sending_mqtt_commands_and_optimistic(
) )
mock_restore_cache(hass, (fake_state,)) 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") state = hass.states.get("light.test")
assert state.state == STATE_ON 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( 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: ) -> None:
"""Test the sending of command in optimistic mode.""" """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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -633,10 +633,10 @@ async def test_sending_mqtt_commands_non_optimistic_brightness_template(
], ],
) )
async def test_effect( async def test_effect(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test effect sent over MQTT in optimistic mode.""" """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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -687,10 +687,10 @@ async def test_effect(
], ],
) )
async def test_flash( async def test_flash(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test flash sent over MQTT in optimistic mode.""" """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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -738,10 +738,10 @@ async def test_flash(
], ],
) )
async def test_transition( async def test_transition(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test for transition time being sent when included.""" """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") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -796,11 +796,11 @@ async def test_transition(
], ],
) )
async def test_invalid_values( async def test_invalid_values(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test that invalid values are ignored.""" """Test that invalid values are ignored."""
await hass.async_block_till_done() await hass.async_block_till_done()
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get("light.test") state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -864,58 +864,58 @@ async def test_invalid_values(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_availability_when_connection_lost( async def test_availability_when_connection_lost(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN hass, mqtt_mock_entry, light.DOMAIN
) )
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_availability_without_topic( async def test_availability_without_topic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_default_availability_payload( async def test_default_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
await help_test_default_availability_payload( await help_test_default_availability_payload(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_custom_availability_payload( async def test_custom_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by custom payload with defined topic.""" """Test availability by custom payload with defined topic."""
await help_test_custom_availability_payload( await help_test_custom_availability_payload(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_setting_attribute_via_mqtt_json_message( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message( await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_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( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_blocked_attribute_via_mqtt_json_message( await help_test_setting_blocked_attribute_via_mqtt_json_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
light.DOMAIN, light.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
MQTT_LIGHT_ATTRIBUTES_BLOCKED, 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( async def test_setting_attribute_with_template(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template( await help_test_setting_attribute_with_template(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_not_dict(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_not_dict( await help_test_update_with_json_attrs_not_dict(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
light.DOMAIN, light.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -948,13 +948,13 @@ async def test_update_with_json_attrs_not_dict(
async def test_update_with_json_attrs_bad_json( async def test_update_with_json_attrs_bad_json(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_json( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
light.DOMAIN, light.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -963,13 +963,13 @@ async def test_update_with_json_attrs_bad_json(
async def test_discovery_update_attr( async def test_discovery_update_attr(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered MQTTAttributes.""" """Test update of discovered MQTTAttributes."""
await help_test_discovery_update_attr( await help_test_discovery_update_attr(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
light.DOMAIN, light.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -1006,15 +1006,15 @@ async def test_discovery_update_attr(
], ],
) )
async def test_unique_id( async def test_unique_id(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test unique id option only creates one light per unique_id.""" """Test unique id option only creates one light per unique_id."""
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( async def test_discovery_removal(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test removal of discovered mqtt_json lights.""" """Test removal of discovered mqtt_json lights."""
@ -1025,14 +1025,12 @@ async def test_discovery_removal(
' "command_on_template": "on",' ' "command_on_template": "on",'
' "command_off_template": "off"}' ' "command_off_template": "off"}'
) )
await help_test_discovery_removal( await help_test_discovery_removal(hass, mqtt_mock_entry, caplog, light.DOMAIN, data)
hass, mqtt_mock_entry_no_yaml_config, caplog, light.DOMAIN, data
)
async def test_discovery_update_light( async def test_discovery_update_light(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered light.""" """Test update of discovered light."""
@ -1053,13 +1051,13 @@ async def test_discovery_update_light(
"command_off_template": "off", "command_off_template": "off",
} }
await help_test_discovery_update( 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( async def test_discovery_update_unchanged_light(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered light.""" """Test update of discovered light."""
@ -1076,7 +1074,7 @@ async def test_discovery_update_unchanged_light(
) as discovery_update: ) as discovery_update:
await help_test_discovery_update_unchanged( await help_test_discovery_update_unchanged(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
light.DOMAIN, light.DOMAIN,
data1, data1,
@ -1087,7 +1085,7 @@ async def test_discovery_update_unchanged_light(
@pytest.mark.no_fail_on_log_exception @pytest.mark.no_fail_on_log_exception
async def test_discovery_broken( async def test_discovery_broken(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test handling of bad discovery message.""" """Test handling of bad discovery message."""
@ -1101,66 +1099,66 @@ async def test_discovery_broken(
' "command_off_template": "off"}' ' "command_off_template": "off"}'
) )
await help_test_discovery_broken( 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( async def test_entity_device_info_with_connection(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT light device registry integration.""" """Test MQTT light device registry integration."""
await help_test_entity_device_info_with_connection( await help_test_entity_device_info_with_connection(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_with_identifier( async def test_entity_device_info_with_identifier(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT light device registry integration.""" """Test MQTT light device registry integration."""
await help_test_entity_device_info_with_identifier( await help_test_entity_device_info_with_identifier(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_update( async def test_entity_device_info_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry update.""" """Test device registry update."""
await help_test_entity_device_info_update( await help_test_entity_device_info_update(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_remove( async def test_entity_device_info_remove(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry remove.""" """Test device registry remove."""
await help_test_entity_device_info_remove( await help_test_entity_device_info_remove(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_subscriptions( async def test_entity_id_update_subscriptions(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT subscriptions are managed when entity_id is updated.""" """Test MQTT subscriptions are managed when entity_id is updated."""
await help_test_entity_id_update_subscriptions( await help_test_entity_id_update_subscriptions(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_discovery_update( async def test_entity_id_update_discovery_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT discovery update when entity_id is updated.""" """Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update( await help_test_entity_id_update_discovery_update(
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_debug_info_message( async def test_entity_debug_info_message(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT debug info.""" """Test MQTT debug info."""
config = { config = {
@ -1177,7 +1175,7 @@ async def test_entity_debug_info_message(
} }
await help_test_entity_debug_info_message( await help_test_entity_debug_info_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
light.DOMAIN, light.DOMAIN,
config, config,
light.SERVICE_TURN_ON, light.SERVICE_TURN_ON,
@ -1203,10 +1201,10 @@ async def test_entity_debug_info_message(
], ],
) )
async def test_max_mireds( async def test_max_mireds(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setting min_mireds and max_mireds.""" """Test setting min_mireds and max_mireds."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get("light.test") state = hass.states.get("light.test")
assert state.attributes.get("min_mireds") == 153 assert state.attributes.get("min_mireds") == 153
@ -1238,7 +1236,7 @@ async def test_max_mireds(
) )
async def test_publishing_with_custom_encoding( async def test_publishing_with_custom_encoding(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
service: str, service: str,
topic: str, topic: str,
@ -1256,7 +1254,7 @@ async def test_publishing_with_custom_encoding(
await help_test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
domain, domain,
config, config,
@ -1288,7 +1286,7 @@ async def test_reloadable(
) )
async def test_encoding_subscribable_topics( async def test_encoding_subscribable_topics(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
topic: str, topic: str,
value: str, value: str,
attribute: str | None, attribute: str | None,
@ -1300,7 +1298,7 @@ async def test_encoding_subscribable_topics(
config["state_template"] = "{{ value }}" config["state_template"] = "{{ value }}"
await help_test_encoding_subscribable_topics( await help_test_encoding_subscribable_topics(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
light.DOMAIN, light.DOMAIN,
config, config,
topic, topic,
@ -1313,21 +1311,21 @@ async def test_encoding_subscribable_topics(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_setup_manual_entity_from_yaml( async def test_setup_manual_entity_from_yaml(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
platform = light.DOMAIN platform = light.DOMAIN
assert hass.states.get(f"{platform}.test") assert hass.states.get(f"{platform}.test")
async def test_unload_entry( async def test_unload_entry(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = light.DOMAIN domain = light.DOMAIN
config = DEFAULT_CONFIG config = DEFAULT_CONFIG
await help_test_unload_config_entry_with_platform( await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_no_yaml_config, domain, config hass, mqtt_mock_entry, domain, config
) )

View File

@ -98,12 +98,12 @@ def lock_platform_only():
) )
async def test_controlling_state_via_topic( async def test_controlling_state_via_topic(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
payload: str, payload: str,
lock_state: str, lock_state: str,
) -> None: ) -> None:
"""Test the controlling state via topic.""" """Test the controlling state via topic."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get("lock.test") state = hass.states.get("lock.test")
assert state.state is STATE_UNLOCKED 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( async def test_controlling_non_default_state_via_topic(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
payload: str, payload: str,
lock_state: str, lock_state: str,
) -> None: ) -> None:
"""Test the controlling state via topic.""" """Test the controlling state via topic."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get("lock.test") state = hass.states.get("lock.test")
assert state.state is STATE_UNLOCKED 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( async def test_controlling_state_via_topic_and_json_message(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
payload: str, payload: str,
lock_state: str, lock_state: str,
) -> None: ) -> None:
"""Test the controlling state via topic and JSON message.""" """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") state = hass.states.get("lock.test")
assert state.state is STATE_UNLOCKED 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( async def test_controlling_non_default_state_via_topic_and_json_message(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
payload: str, payload: str,
lock_state: str, lock_state: str,
) -> None: ) -> None:
"""Test the controlling state via topic and JSON message.""" """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") state = hass.states.get("lock.test")
assert state.state is STATE_UNLOCKED 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( async def test_sending_mqtt_commands_and_optimistic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test optimistic mode without state topic.""" """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") state = hass.states.get("lock.test")
assert state.state is STATE_UNLOCKED 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( async def test_sending_mqtt_commands_with_template(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test sending commands with template.""" """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") state = hass.states.get("lock.test")
assert state.state is STATE_UNLOCKED 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( 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: ) -> None:
"""Test optimistic mode without state topic.""" """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") state = hass.states.get("lock.test")
assert state.state is STATE_UNLOCKED 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( 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: ) -> None:
"""Test open function of the lock without state topic.""" """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") state = hass.states.get("lock.test")
assert state.state is STATE_UNLOCKED 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( 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: ) -> None:
"""Test open function of the lock without state topic.""" """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") state = hass.states.get("lock.test")
assert state.state is STATE_UNLOCKED 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( async def test_sending_mqtt_commands_pessimistic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test function of the lock with state topics.""" """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") state = hass.states.get("lock.test")
assert state.state is STATE_UNLOCKED assert state.state is STATE_UNLOCKED
@ -652,58 +652,58 @@ async def test_sending_mqtt_commands_pessimistic(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_availability_when_connection_lost( async def test_availability_when_connection_lost(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN hass, mqtt_mock_entry, lock.DOMAIN
) )
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_availability_without_topic( async def test_availability_without_topic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, lock.DOMAIN, DEFAULT_CONFIG
) )
async def test_default_availability_payload( async def test_default_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
await help_test_default_availability_payload( await help_test_default_availability_payload(
hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, lock.DOMAIN, DEFAULT_CONFIG
) )
async def test_custom_availability_payload( async def test_custom_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by custom payload with defined topic.""" """Test availability by custom payload with defined topic."""
await help_test_custom_availability_payload( await help_test_custom_availability_payload(
hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, lock.DOMAIN, DEFAULT_CONFIG
) )
async def test_setting_attribute_via_mqtt_json_message( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message( await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_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( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_blocked_attribute_via_mqtt_json_message( await help_test_setting_blocked_attribute_via_mqtt_json_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
lock.DOMAIN, lock.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
MQTT_LOCK_ATTRIBUTES_BLOCKED, 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( async def test_setting_attribute_with_template(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template( await help_test_setting_attribute_with_template(
hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, lock.DOMAIN, DEFAULT_CONFIG
) )
async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_not_dict(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_not_dict( await help_test_update_with_json_attrs_not_dict(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
lock.DOMAIN, lock.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -736,13 +736,13 @@ async def test_update_with_json_attrs_not_dict(
async def test_update_with_json_attrs_bad_json( async def test_update_with_json_attrs_bad_json(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_json( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
lock.DOMAIN, lock.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -751,12 +751,12 @@ async def test_update_with_json_attrs_bad_json(
async def test_discovery_update_attr( async def test_discovery_update_attr(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered MQTTAttributes.""" """Test update of discovered MQTTAttributes."""
await help_test_discovery_update_attr( await help_test_discovery_update_attr(
hass, mqtt_mock_entry_no_yaml_config, caplog, lock.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, caplog, lock.DOMAIN, DEFAULT_CONFIG
) )
@ -784,27 +784,25 @@ async def test_discovery_update_attr(
], ],
) )
async def test_unique_id( async def test_unique_id(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test unique id option only creates one lock per unique_id.""" """Test unique id option only creates one lock per unique_id."""
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( async def test_discovery_removal_lock(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test removal of discovered lock.""" """Test removal of discovered lock."""
data = '{ "name": "test",' ' "command_topic": "test_topic" }' data = '{ "name": "test",' ' "command_topic": "test_topic" }'
await help_test_discovery_removal( await help_test_discovery_removal(hass, mqtt_mock_entry, caplog, lock.DOMAIN, data)
hass, mqtt_mock_entry_no_yaml_config, caplog, lock.DOMAIN, data
)
async def test_discovery_update_lock( async def test_discovery_update_lock(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered lock.""" """Test update of discovered lock."""
@ -821,13 +819,13 @@ async def test_discovery_update_lock(
"availability_topic": "availability_topic2", "availability_topic": "availability_topic2",
} }
await help_test_discovery_update( 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( async def test_discovery_update_unchanged_lock(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered lock.""" """Test update of discovered lock."""
@ -841,7 +839,7 @@ async def test_discovery_update_unchanged_lock(
) as discovery_update: ) as discovery_update:
await help_test_discovery_update_unchanged( await help_test_discovery_update_unchanged(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
lock.DOMAIN, lock.DOMAIN,
data1, data1,
@ -852,78 +850,78 @@ async def test_discovery_update_unchanged_lock(
@pytest.mark.no_fail_on_log_exception @pytest.mark.no_fail_on_log_exception
async def test_discovery_broken( async def test_discovery_broken(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test handling of bad discovery message.""" """Test handling of bad discovery message."""
data1 = '{ "name": "Beer" }' data1 = '{ "name": "Beer" }'
data2 = '{ "name": "Milk",' ' "command_topic": "test_topic" }' data2 = '{ "name": "Milk",' ' "command_topic": "test_topic" }'
await help_test_discovery_broken( 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( async def test_entity_device_info_with_connection(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT lock device registry integration.""" """Test MQTT lock device registry integration."""
await help_test_entity_device_info_with_connection( await help_test_entity_device_info_with_connection(
hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, lock.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_with_identifier( async def test_entity_device_info_with_identifier(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT lock device registry integration.""" """Test MQTT lock device registry integration."""
await help_test_entity_device_info_with_identifier( await help_test_entity_device_info_with_identifier(
hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, lock.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_update( async def test_entity_device_info_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry update.""" """Test device registry update."""
await help_test_entity_device_info_update( await help_test_entity_device_info_update(
hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, lock.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_remove( async def test_entity_device_info_remove(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry remove.""" """Test device registry remove."""
await help_test_entity_device_info_remove( await help_test_entity_device_info_remove(
hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, lock.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_subscriptions( async def test_entity_id_update_subscriptions(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT subscriptions are managed when entity_id is updated.""" """Test MQTT subscriptions are managed when entity_id is updated."""
await help_test_entity_id_update_subscriptions( await help_test_entity_id_update_subscriptions(
hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, lock.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_discovery_update( async def test_entity_id_update_discovery_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT discovery update when entity_id is updated.""" """Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update( await help_test_entity_id_update_discovery_update(
hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, lock.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_debug_info_message( async def test_entity_debug_info_message(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT debug info.""" """Test MQTT debug info."""
await help_test_entity_debug_info_message( await help_test_entity_debug_info_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
lock.DOMAIN, lock.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
SERVICE_LOCK, SERVICE_LOCK,
@ -945,7 +943,7 @@ async def test_entity_debug_info_message(
) )
async def test_publishing_with_custom_encoding( async def test_publishing_with_custom_encoding(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
service: str, service: str,
topic: str, topic: str,
@ -959,7 +957,7 @@ async def test_publishing_with_custom_encoding(
await help_test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
domain, domain,
config, config,
@ -989,7 +987,7 @@ async def test_reloadable(
) )
async def test_encoding_subscribable_topics( async def test_encoding_subscribable_topics(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
topic: str, topic: str,
value: str, value: str,
attribute: str | None, attribute: str | None,
@ -998,7 +996,7 @@ async def test_encoding_subscribable_topics(
"""Test handling of incoming encoded payload.""" """Test handling of incoming encoded payload."""
await help_test_encoding_subscribable_topics( await help_test_encoding_subscribable_topics(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
lock.DOMAIN, lock.DOMAIN,
DEFAULT_CONFIG[mqtt.DOMAIN][lock.DOMAIN], DEFAULT_CONFIG[mqtt.DOMAIN][lock.DOMAIN],
topic, topic,
@ -1010,21 +1008,21 @@ async def test_encoding_subscribable_topics(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_setup_manual_entity_from_yaml( async def test_setup_manual_entity_from_yaml(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
platform = lock.DOMAIN platform = lock.DOMAIN
assert hass.states.get(f"{platform}.test") assert hass.states.get(f"{platform}.test")
async def test_unload_entry( async def test_unload_entry(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = lock.DOMAIN domain = lock.DOMAIN
config = DEFAULT_CONFIG config = DEFAULT_CONFIG
await help_test_unload_config_entry_with_platform( await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_no_yaml_config, domain, config hass, mqtt_mock_entry, domain, config
) )

View File

@ -33,14 +33,14 @@ from tests.typing import MqttMockHAClientGenerator
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SENSOR]) @patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SENSOR])
async def test_availability_with_shared_state_topic( async def test_availability_with_shared_state_topic(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test the state is not changed twice. """Test the state is not changed twice.
When an entity with a shared state_topic and availability_topic becomes available When an entity with a shared state_topic and availability_topic becomes available
The state should only change once. The state should only change once.
""" """
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
events = [] events = []

View File

@ -93,10 +93,10 @@ def number_platform_only():
], ],
) )
async def test_run_number_setup( async def test_run_number_setup(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test that it fetches the given payload.""" """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") async_fire_mqtt_message(hass, "test/state_number", "10")
@ -142,11 +142,11 @@ async def test_run_number_setup(
], ],
) )
async def test_value_template( async def test_value_template(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test that it fetches the given payload with a template.""" """Test that it fetches the given payload with a template."""
topic = "test/state_number" topic = "test/state_number"
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
async_fire_mqtt_message(hass, topic, '{"val":10}') async_fire_mqtt_message(hass, topic, '{"val":10}')
@ -186,7 +186,7 @@ async def test_value_template(
], ],
) )
async def test_restore_native_value( async def test_restore_native_value(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test that the stored native_value is restored.""" """Test that the stored native_value is restored."""
@ -201,7 +201,7 @@ async def test_restore_native_value(
mock_restore_cache_with_extra_data( mock_restore_cache_with_extra_data(
hass, ((State("number.test_number", "abc"), RESTORE_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") state = hass.states.get("number.test_number")
assert state.state == "37.8" assert state.state == "37.8"
@ -222,7 +222,7 @@ async def test_restore_native_value(
], ],
) )
async def test_run_number_service_optimistic( async def test_run_number_service_optimistic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test that set_value service works in optimistic mode.""" """Test that set_value service works in optimistic mode."""
topic = "test/number" topic = "test/number"
@ -239,7 +239,7 @@ async def test_run_number_service_optimistic(
hass, ((State("number.test_number", "abc"), RESTORE_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") state = hass.states.get("number.test_number")
assert state.state == "3" 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( 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: ) -> None:
"""Test that set_value service works in optimistic mode and with a command_template.""" """Test that set_value service works in optimistic mode and with a command_template."""
topic = "test/number" topic = "test/number"
@ -316,7 +316,7 @@ async def test_run_number_service_optimistic_with_command_template(
mock_restore_cache_with_extra_data( mock_restore_cache_with_extra_data(
hass, ((State("number.test_number", "abc"), RESTORE_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") state = hass.states.get("number.test_number")
assert state.state == "3" assert state.state == "3"
@ -379,13 +379,13 @@ async def test_run_number_service_optimistic_with_command_template(
], ],
) )
async def test_run_number_service( async def test_run_number_service(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test that set_value service works in non optimistic mode.""" """Test that set_value service works in non optimistic mode."""
cmd_topic = "test/number/set" cmd_topic = "test/number/set"
state_topic = "test/number" 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") async_fire_mqtt_message(hass, state_topic, "32")
state = hass.states.get("number.test_number") 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( 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: ) -> None:
"""Test that set_value service works in non optimistic mode and with a command_template.""" """Test that set_value service works in non optimistic mode and with a command_template."""
cmd_topic = "test/number/set" cmd_topic = "test/number/set"
state_topic = "test/number" 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") async_fire_mqtt_message(hass, state_topic, "32")
state = hass.states.get("number.test_number") 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]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_availability_when_connection_lost( async def test_availability_when_connection_lost(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN hass, mqtt_mock_entry, number.DOMAIN
) )
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_availability_without_topic( async def test_availability_without_topic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, number.DOMAIN, DEFAULT_CONFIG
) )
async def test_default_availability_payload( async def test_default_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
await help_test_default_availability_payload( await help_test_default_availability_payload(
hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, number.DOMAIN, DEFAULT_CONFIG
) )
async def test_custom_availability_payload( async def test_custom_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by custom payload with defined topic.""" """Test availability by custom payload with defined topic."""
await help_test_custom_availability_payload( await help_test_custom_availability_payload(
hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, number.DOMAIN, DEFAULT_CONFIG
) )
async def test_setting_attribute_via_mqtt_json_message( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message( await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_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( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_blocked_attribute_via_mqtt_json_message( await help_test_setting_blocked_attribute_via_mqtt_json_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
number.DOMAIN, number.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
MQTT_NUMBER_ATTRIBUTES_BLOCKED, 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( async def test_setting_attribute_with_template(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template( await help_test_setting_attribute_with_template(
hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, number.DOMAIN, DEFAULT_CONFIG
) )
async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_not_dict(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_not_dict( await help_test_update_with_json_attrs_not_dict(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
number.DOMAIN, number.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -529,13 +529,13 @@ async def test_update_with_json_attrs_not_dict(
async def test_update_with_json_attrs_bad_json( async def test_update_with_json_attrs_bad_json(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_json( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
number.DOMAIN, number.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -544,13 +544,13 @@ async def test_update_with_json_attrs_bad_json(
async def test_discovery_update_attr( async def test_discovery_update_attr(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered MQTTAttributes.""" """Test update of discovered MQTTAttributes."""
await help_test_discovery_update_attr( await help_test_discovery_update_attr(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
number.DOMAIN, number.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -581,27 +581,27 @@ async def test_discovery_update_attr(
], ],
) )
async def test_unique_id( async def test_unique_id(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test unique id option only creates one number per unique_id.""" """Test unique id option only creates one number per unique_id."""
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( async def test_discovery_removal_number(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test removal of discovered number.""" """Test removal of discovered number."""
data = json.dumps(DEFAULT_CONFIG[mqtt.DOMAIN][number.DOMAIN]) data = json.dumps(DEFAULT_CONFIG[mqtt.DOMAIN][number.DOMAIN])
await help_test_discovery_removal( await help_test_discovery_removal(
hass, mqtt_mock_entry_no_yaml_config, caplog, number.DOMAIN, data hass, mqtt_mock_entry, caplog, number.DOMAIN, data
) )
async def test_discovery_update_number( async def test_discovery_update_number(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered number.""" """Test update of discovered number."""
@ -617,13 +617,13 @@ async def test_discovery_update_number(
} }
await help_test_discovery_update( 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( async def test_discovery_update_unchanged_number(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered number.""" """Test update of discovered number."""
@ -635,7 +635,7 @@ async def test_discovery_update_unchanged_number(
) as discovery_update: ) as discovery_update:
await help_test_discovery_update_unchanged( await help_test_discovery_update_unchanged(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
number.DOMAIN, number.DOMAIN,
data1, data1,
@ -646,7 +646,7 @@ async def test_discovery_update_unchanged_number(
@pytest.mark.no_fail_on_log_exception @pytest.mark.no_fail_on_log_exception
async def test_discovery_broken( async def test_discovery_broken(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test handling of bad discovery message.""" """Test handling of bad discovery message."""
@ -656,71 +656,71 @@ async def test_discovery_broken(
) )
await help_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( async def test_entity_device_info_with_connection(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT number device registry integration.""" """Test MQTT number device registry integration."""
await help_test_entity_device_info_with_connection( await help_test_entity_device_info_with_connection(
hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, number.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_with_identifier( async def test_entity_device_info_with_identifier(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT number device registry integration.""" """Test MQTT number device registry integration."""
await help_test_entity_device_info_with_identifier( await help_test_entity_device_info_with_identifier(
hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, number.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_update( async def test_entity_device_info_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry update.""" """Test device registry update."""
await help_test_entity_device_info_update( await help_test_entity_device_info_update(
hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, number.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_remove( async def test_entity_device_info_remove(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry remove.""" """Test device registry remove."""
await help_test_entity_device_info_remove( await help_test_entity_device_info_remove(
hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, number.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_subscriptions( async def test_entity_id_update_subscriptions(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT subscriptions are managed when entity_id is updated.""" """Test MQTT subscriptions are managed when entity_id is updated."""
await help_test_entity_id_update_subscriptions( await help_test_entity_id_update_subscriptions(
hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, number.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_discovery_update( async def test_entity_id_update_discovery_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT discovery update when entity_id is updated.""" """Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update( await help_test_entity_id_update_discovery_update(
hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, number.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_debug_info_message( async def test_entity_debug_info_message(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT debug info.""" """Test MQTT debug info."""
await help_test_entity_debug_info_message( await help_test_entity_debug_info_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
number.DOMAIN, number.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
SERVICE_SET_VALUE, SERVICE_SET_VALUE,
@ -748,10 +748,10 @@ async def test_entity_debug_info_message(
], ],
) )
async def test_min_max_step_attributes( async def test_min_max_step_attributes(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test min/max/step attributes.""" """Test min/max/step attributes."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get("number.test_number") state = hass.states.get("number.test_number")
assert state.attributes.get(ATTR_MIN) == 5 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( async def test_invalid_min_max_attributes(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test invalid min/max attributes.""" """Test invalid min/max attributes."""
with pytest.raises(AssertionError): 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 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( async def test_default_mode(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test default mode.""" """Test default mode."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get("number.test_number") state = hass.states.get("number.test_number")
assert state.attributes.get(ATTR_MODE) == "auto" assert state.attributes.get(ATTR_MODE) == "auto"
@ -856,11 +856,11 @@ async def test_default_mode(
) )
async def test_mode( async def test_mode(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
mode, mode,
) -> None: ) -> None:
"""Test mode.""" """Test mode."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get("number.test_number") state = hass.states.get("number.test_number")
assert state.attributes.get(ATTR_MODE) == mode assert state.attributes.get(ATTR_MODE) == mode
@ -899,15 +899,15 @@ async def test_mode(
) )
async def test_invalid_mode( async def test_invalid_mode(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
valid: bool, valid: bool,
) -> None: ) -> None:
"""Test invalid mode.""" """Test invalid mode."""
if valid: if valid:
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
return return
with pytest.raises(AssertionError): with pytest.raises(AssertionError):
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -927,12 +927,12 @@ async def test_invalid_mode(
async def test_mqtt_payload_not_a_number_warning( async def test_mqtt_payload_not_a_number_warning(
hass: HomeAssistant, hass: HomeAssistant,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test warning for MQTT payload which is not a number.""" """Test warning for MQTT payload which is not a number."""
topic = "test/state_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") 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( async def test_mqtt_payload_out_of_range_error(
hass: HomeAssistant, hass: HomeAssistant,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test error when MQTT payload is out of min/max range.""" """Test error when MQTT payload is out of min/max range."""
topic = "test/state_number" topic = "test/state_number"
await hass.async_block_till_done() 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") 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( async def test_publishing_with_custom_encoding(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
service: str, service: str,
topic: str, topic: str,
@ -1005,7 +1005,7 @@ async def test_publishing_with_custom_encoding(
await help_test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
domain, domain,
config, config,
@ -1036,7 +1036,7 @@ async def test_reloadable(
) )
async def test_encoding_subscribable_topics( async def test_encoding_subscribable_topics(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
topic: str, topic: str,
value: str, value: str,
attribute: str | None, attribute: str | None,
@ -1045,7 +1045,7 @@ async def test_encoding_subscribable_topics(
"""Test handling of incoming encoded payload.""" """Test handling of incoming encoded payload."""
await help_test_encoding_subscribable_topics( await help_test_encoding_subscribable_topics(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
number.DOMAIN, number.DOMAIN,
DEFAULT_CONFIG[mqtt.DOMAIN][number.DOMAIN], DEFAULT_CONFIG[mqtt.DOMAIN][number.DOMAIN],
topic, topic,
@ -1057,21 +1057,21 @@ async def test_encoding_subscribable_topics(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_setup_manual_entity_from_yaml( async def test_setup_manual_entity_from_yaml(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
platform = number.DOMAIN platform = number.DOMAIN
assert hass.states.get(f"{platform}.test") assert hass.states.get(f"{platform}.test")
async def test_unload_entry( async def test_unload_entry(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = number.DOMAIN domain = number.DOMAIN
config = DEFAULT_CONFIG config = DEFAULT_CONFIG
await help_test_unload_config_entry_with_platform( await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_no_yaml_config, domain, config hass, mqtt_mock_entry, domain, config
) )

View File

@ -58,13 +58,13 @@ def scene_platform_only():
], ],
) )
async def test_sending_mqtt_commands( async def test_sending_mqtt_commands(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the sending MQTT commands.""" """Test the sending MQTT commands."""
fake_state = State("scene.test", STATE_UNKNOWN) fake_state = State("scene.test", STATE_UNKNOWN)
mock_restore_cache(hass, (fake_state,)) 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") state = hass.states.get("scene.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -79,26 +79,26 @@ async def test_sending_mqtt_commands(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_availability_when_connection_lost( async def test_availability_when_connection_lost(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_no_yaml_config, scene.DOMAIN hass, mqtt_mock_entry, scene.DOMAIN
) )
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_availability_without_topic( async def test_availability_without_topic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_no_yaml_config, scene.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, scene.DOMAIN, DEFAULT_CONFIG
) )
async def test_default_availability_payload( async def test_default_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
config = { config = {
@ -112,7 +112,7 @@ async def test_default_availability_payload(
} }
await help_test_default_availability_payload( await help_test_default_availability_payload(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
scene.DOMAIN, scene.DOMAIN,
config, config,
True, True,
@ -122,7 +122,7 @@ async def test_default_availability_payload(
async def test_custom_availability_payload( async def test_custom_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by custom payload with defined topic.""" """Test availability by custom payload with defined topic."""
config = { config = {
@ -137,7 +137,7 @@ async def test_custom_availability_payload(
await help_test_custom_availability_payload( await help_test_custom_availability_payload(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
scene.DOMAIN, scene.DOMAIN,
config, config,
True, True,
@ -168,27 +168,25 @@ async def test_custom_availability_payload(
], ],
) )
async def test_unique_id( async def test_unique_id(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test unique id option only creates one scene per unique_id.""" """Test unique id option only creates one scene per unique_id."""
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( async def test_discovery_removal_scene(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test removal of discovered scene.""" """Test removal of discovered scene."""
data = '{ "name": "test",' ' "command_topic": "test_topic" }' data = '{ "name": "test",' ' "command_topic": "test_topic" }'
await help_test_discovery_removal( await help_test_discovery_removal(hass, mqtt_mock_entry, caplog, scene.DOMAIN, data)
hass, mqtt_mock_entry_no_yaml_config, caplog, scene.DOMAIN, data
)
async def test_discovery_update_payload( async def test_discovery_update_payload(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered scene.""" """Test update of discovered scene."""
@ -201,7 +199,7 @@ async def test_discovery_update_payload(
await help_test_discovery_update( await help_test_discovery_update(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
scene.DOMAIN, scene.DOMAIN,
config1, config1,
@ -211,7 +209,7 @@ async def test_discovery_update_payload(
async def test_discovery_update_unchanged_scene( async def test_discovery_update_unchanged_scene(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered scene.""" """Test update of discovered scene."""
@ -221,7 +219,7 @@ async def test_discovery_update_unchanged_scene(
) as discovery_update: ) as discovery_update:
await help_test_discovery_update_unchanged( await help_test_discovery_update_unchanged(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
scene.DOMAIN, scene.DOMAIN,
data1, data1,
@ -232,14 +230,14 @@ async def test_discovery_update_unchanged_scene(
@pytest.mark.no_fail_on_log_exception @pytest.mark.no_fail_on_log_exception
async def test_discovery_broken( async def test_discovery_broken(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test handling of bad discovery message.""" """Test handling of bad discovery message."""
data1 = '{ "name": "Beer" }' data1 = '{ "name": "Beer" }'
data2 = '{ "name": "Milk",' ' "command_topic": "test_topic" }' data2 = '{ "name": "Milk",' ' "command_topic": "test_topic" }'
await help_test_discovery_broken( 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]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_setup_manual_entity_from_yaml( async def test_setup_manual_entity_from_yaml(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
platform = scene.DOMAIN platform = scene.DOMAIN
assert hass.states.get(f"{platform}.test") assert hass.states.get(f"{platform}.test")
async def test_unload_entry( async def test_unload_entry(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = scene.DOMAIN domain = scene.DOMAIN
config = DEFAULT_CONFIG config = DEFAULT_CONFIG
await help_test_unload_config_entry_with_platform( await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_no_yaml_config, domain, config hass, mqtt_mock_entry, domain, config
) )

View File

@ -99,11 +99,11 @@ def _test_run_select_setup_params(
) )
async def test_run_select_setup( async def test_run_select_setup(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
topic: str, topic: str,
) -> None: ) -> None:
"""Test that it fetches the given payload.""" """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") async_fire_mqtt_message(hass, topic, "milk")
@ -137,10 +137,10 @@ async def test_run_select_setup(
], ],
) )
async def test_value_template( async def test_value_template(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test that it fetches the given payload with a template.""" """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"}') 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( async def test_run_select_service_optimistic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test that set_value service works in optimistic mode.""" """Test that set_value service works in optimistic mode."""
fake_state = State("select.test_select", "milk") fake_state = State("select.test_select", "milk")
mock_restore_cache(hass, (fake_state,)) 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") state = hass.states.get("select.test_select")
assert state.state == "milk" 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( 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: ) -> None:
"""Test that set_value service works in optimistic mode and with a command_template.""" """Test that set_value service works in optimistic mode and with a command_template."""
fake_state = State("select.test_select", "milk") fake_state = State("select.test_select", "milk")
mock_restore_cache(hass, (fake_state,)) 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") state = hass.states.get("select.test_select")
assert state.state == "milk" assert state.state == "milk"
@ -263,13 +263,13 @@ async def test_run_select_service_optimistic_with_command_template(
], ],
) )
async def test_run_select_service( async def test_run_select_service(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test that set_value service works in non optimistic mode.""" """Test that set_value service works in non optimistic mode."""
cmd_topic = "test/select/set" cmd_topic = "test/select/set"
state_topic = "test/select" 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") async_fire_mqtt_message(hass, state_topic, "beer")
state = hass.states.get("select.test_select") 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( 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: ) -> None:
"""Test that set_value service works in non optimistic mode and with a command_template.""" """Test that set_value service works in non optimistic mode and with a command_template."""
cmd_topic = "test/select/set" cmd_topic = "test/select/set"
state_topic = "test/select" 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") async_fire_mqtt_message(hass, state_topic, "beer")
state = hass.states.get("select.test_select") 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]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_availability_when_connection_lost( async def test_availability_when_connection_lost(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN hass, mqtt_mock_entry, select.DOMAIN
) )
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_availability_without_topic( async def test_availability_without_topic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, select.DOMAIN, DEFAULT_CONFIG
) )
async def test_default_availability_payload( async def test_default_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
await help_test_default_availability_payload( await help_test_default_availability_payload(
hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, select.DOMAIN, DEFAULT_CONFIG
) )
async def test_custom_availability_payload( async def test_custom_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by custom payload with defined topic.""" """Test availability by custom payload with defined topic."""
await help_test_custom_availability_payload( await help_test_custom_availability_payload(
hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, select.DOMAIN, DEFAULT_CONFIG
) )
async def test_setting_attribute_via_mqtt_json_message( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message( await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_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( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_blocked_attribute_via_mqtt_json_message( await help_test_setting_blocked_attribute_via_mqtt_json_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
select.DOMAIN, select.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
MQTT_SELECT_ATTRIBUTES_BLOCKED, 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( async def test_setting_attribute_with_template(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template( await help_test_setting_attribute_with_template(
hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, select.DOMAIN, DEFAULT_CONFIG
) )
async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_not_dict(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_not_dict( await help_test_update_with_json_attrs_not_dict(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
select.DOMAIN, select.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -412,13 +412,13 @@ async def test_update_with_json_attrs_not_dict(
async def test_update_with_json_attrs_bad_json( async def test_update_with_json_attrs_bad_json(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_json( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
select.DOMAIN, select.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -427,13 +427,13 @@ async def test_update_with_json_attrs_bad_json(
async def test_discovery_update_attr( async def test_discovery_update_attr(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered MQTTAttributes.""" """Test update of discovered MQTTAttributes."""
await help_test_discovery_update_attr( await help_test_discovery_update_attr(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
select.DOMAIN, select.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -466,27 +466,27 @@ async def test_discovery_update_attr(
], ],
) )
async def test_unique_id( async def test_unique_id(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test unique id option only creates one select per unique_id.""" """Test unique id option only creates one select per unique_id."""
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( async def test_discovery_removal_select(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test removal of discovered select.""" """Test removal of discovered select."""
data = json.dumps(DEFAULT_CONFIG[mqtt.DOMAIN][select.DOMAIN]) data = json.dumps(DEFAULT_CONFIG[mqtt.DOMAIN][select.DOMAIN])
await help_test_discovery_removal( await help_test_discovery_removal(
hass, mqtt_mock_entry_no_yaml_config, caplog, select.DOMAIN, data hass, mqtt_mock_entry, caplog, select.DOMAIN, data
) )
async def test_discovery_update_select( async def test_discovery_update_select(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered select.""" """Test update of discovered select."""
@ -504,13 +504,13 @@ async def test_discovery_update_select(
} }
await help_test_discovery_update( 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( async def test_discovery_update_unchanged_select(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered select.""" """Test update of discovered select."""
@ -520,7 +520,7 @@ async def test_discovery_update_unchanged_select(
) as discovery_update: ) as discovery_update:
await help_test_discovery_update_unchanged( await help_test_discovery_update_unchanged(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
select.DOMAIN, select.DOMAIN,
data1, data1,
@ -531,7 +531,7 @@ async def test_discovery_update_unchanged_select(
@pytest.mark.no_fail_on_log_exception @pytest.mark.no_fail_on_log_exception
async def test_discovery_broken( async def test_discovery_broken(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test handling of bad discovery message.""" """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"]}' data2 = '{ "name": "Milk", "state_topic": "test-topic", "command_topic": "test-topic", "options": ["milk", "beer"]}'
await help_test_discovery_broken( 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( async def test_entity_device_info_with_connection(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT select device registry integration.""" """Test MQTT select device registry integration."""
await help_test_entity_device_info_with_connection( await help_test_entity_device_info_with_connection(
hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, select.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_with_identifier( async def test_entity_device_info_with_identifier(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT select device registry integration.""" """Test MQTT select device registry integration."""
await help_test_entity_device_info_with_identifier( await help_test_entity_device_info_with_identifier(
hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, select.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_update( async def test_entity_device_info_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry update.""" """Test device registry update."""
await help_test_entity_device_info_update( await help_test_entity_device_info_update(
hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, select.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_remove( async def test_entity_device_info_remove(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry remove.""" """Test device registry remove."""
await help_test_entity_device_info_remove( await help_test_entity_device_info_remove(
hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, select.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_subscriptions( async def test_entity_id_update_subscriptions(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT subscriptions are managed when entity_id is updated.""" """Test MQTT subscriptions are managed when entity_id is updated."""
await help_test_entity_id_update_subscriptions( await help_test_entity_id_update_subscriptions(
hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, select.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_discovery_update( async def test_entity_id_update_discovery_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT discovery update when entity_id is updated.""" """Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update( await help_test_entity_id_update_discovery_update(
hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, select.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_debug_info_message( async def test_entity_debug_info_message(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT debug info.""" """Test MQTT debug info."""
await help_test_entity_debug_info_message( await help_test_entity_debug_info_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
select.DOMAIN, select.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
select.SERVICE_SELECT_OPTION, select.SERVICE_SELECT_OPTION,
@ -638,11 +638,11 @@ def _test_options_attributes_options_config(
) )
async def test_options_attributes( async def test_options_attributes(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
options: list[str], options: list[str],
) -> None: ) -> None:
"""Test options attribute.""" """Test options attribute."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get("select.test_select") state = hass.states.get("select.test_select")
assert state.attributes.get(ATTR_OPTIONS) == options 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( async def test_mqtt_payload_not_an_option_warning(
hass: HomeAssistant, hass: HomeAssistant,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test warning for MQTT payload which is not a valid option.""" """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") 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( async def test_publishing_with_custom_encoding(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
service: str, service: str,
topic: str, topic: str,
@ -710,7 +710,7 @@ async def test_publishing_with_custom_encoding(
await help_test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
domain, domain,
config, config,
@ -741,7 +741,7 @@ async def test_reloadable(
) )
async def test_encoding_subscribable_topics( async def test_encoding_subscribable_topics(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
topic: str, topic: str,
value: str, value: str,
attribute: str | None, attribute: str | None,
@ -752,7 +752,7 @@ async def test_encoding_subscribable_topics(
config["options"] = ["milk", "beer"] config["options"] = ["milk", "beer"]
await help_test_encoding_subscribable_topics( await help_test_encoding_subscribable_topics(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
select.DOMAIN, select.DOMAIN,
config, config,
topic, topic,
@ -764,31 +764,31 @@ async def test_encoding_subscribable_topics(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_setup_manual_entity_from_yaml( async def test_setup_manual_entity_from_yaml(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
platform = select.DOMAIN platform = select.DOMAIN
assert hass.states.get(f"{platform}.test") assert hass.states.get(f"{platform}.test")
async def test_unload_entry( async def test_unload_entry(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = select.DOMAIN domain = select.DOMAIN
config = DEFAULT_CONFIG config = DEFAULT_CONFIG
await help_test_unload_config_entry_with_platform( 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( async def test_persistent_state_after_reconfig(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test of the state is persistent after reconfiguring the select options.""" """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"]}' 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") await help_test_discovery_setup(hass, SELECT_DOMAIN, discovery_data, "milk")

View File

@ -99,10 +99,10 @@ def sensor_platform_only():
], ],
) )
async def test_setting_sensor_value_via_mqtt_message( 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: ) -> None:
"""Test the setting of the value via MQTT.""" """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") async_fire_mqtt_message(hass, "test-topic", "100.22")
state = hass.states.get("sensor.test") 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( async def test_setting_sensor_native_value_handling_via_mqtt_message(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
device_class: sensor.SensorDeviceClass | None, device_class: sensor.SensorDeviceClass | None,
native_value: str, native_value: str,
@ -225,7 +225,7 @@ async def test_setting_sensor_native_value_handling_via_mqtt_message(
log: bool, log: bool,
) -> None: ) -> None:
"""Test the setting of the value via MQTT.""" """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) async_fire_mqtt_message(hass, "test-topic", native_value)
state = hass.states.get("sensor.test") 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( async def test_setting_numeric_sensor_native_value_handling_via_mqtt_message(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test the setting of a numeric sensor value via MQTT.""" """Test the setting of a numeric sensor value via MQTT."""
await hass.async_block_till_done() await hass.async_block_till_done()
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
# float value # float value
async_fire_mqtt_message(hass, "test-topic", '{ "power": 45.3, "current": 5.24 }') 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( 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: ) -> None:
"""Test the expiration of the value.""" """Test the expiration of the value."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get("sensor.test") state = hass.states.get("sensor.test")
assert state.state == STATE_UNAVAILABLE 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( async def test_setting_sensor_value_expires(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the expiration of the value.""" """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 should be unavailable since expire_after is defined and > 0
state = hass.states.get("sensor.test") 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( 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: ) -> None:
"""Test the setting of the value via MQTT with JSON payload.""" """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" }') async_fire_mqtt_message(hass, "test-topic", '{ "val": "100" }')
state = hass.states.get("sensor.test") 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( 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: ) -> None:
"""Test the setting of the value via MQTT with fall back to current state.""" """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( async_fire_mqtt_message(
hass, "test-topic", '{ "val": "valcontent", "par": "parcontent" }' 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( async def test_setting_sensor_last_reset_via_mqtt_message(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test the setting of the last_reset property via MQTT.""" """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") async_fire_mqtt_message(hass, "last-reset-topic", "2020-01-02 08:11:00")
state = hass.states.get("sensor.test") state = hass.states.get("sensor.test")
@ -525,10 +525,10 @@ async def test_setting_sensor_bad_last_reset_via_mqtt_message(
hass: HomeAssistant, hass: HomeAssistant,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
datestring, datestring,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test the setting of the last_reset property via MQTT.""" """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) async_fire_mqtt_message(hass, "last-reset-topic", datestring)
state = hass.states.get("sensor.test") 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( 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: ) -> None:
"""Test the setting of the last_reset property via MQTT.""" """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", "") async_fire_mqtt_message(hass, "last-reset-topic", "")
state = hass.states.get("sensor.test") 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( 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: ) -> None:
"""Test the setting of the value via MQTT with JSON payload.""" """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( async_fire_mqtt_message(
hass, "last-reset-topic", '{ "last_reset": "2020-01-02 08:11:00" }' 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( async def test_setting_sensor_last_reset_via_mqtt_json_message_2(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test the setting of the value via MQTT with JSON payload.""" """Test the setting of the value via MQTT with JSON payload."""
await hass.async_block_till_done() await hass.async_block_till_done()
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
async_fire_mqtt_message( async_fire_mqtt_message(
hass, hass,
@ -662,10 +662,10 @@ async def test_setting_sensor_last_reset_via_mqtt_json_message_2(
], ],
) )
async def test_force_update_disabled( async def test_force_update_disabled(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test force update option.""" """Test force update option."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
events: list[Event] = [] events: list[Event] = []
@ -700,10 +700,10 @@ async def test_force_update_disabled(
], ],
) )
async def test_force_update_enabled( async def test_force_update_enabled(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test force update option.""" """Test force update option."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
events: list[Event] = [] events: list[Event] = []
@ -724,57 +724,57 @@ async def test_force_update_enabled(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_availability_when_connection_lost( async def test_availability_when_connection_lost(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN hass, mqtt_mock_entry, sensor.DOMAIN
) )
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_availability_without_topic( async def test_availability_without_topic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
) )
async def test_default_availability_payload( async def test_default_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
await help_test_default_availability_payload( await help_test_default_availability_payload(
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
) )
async def test_default_availability_list_payload( async def test_default_availability_list_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
await help_test_default_availability_list_payload( await help_test_default_availability_list_payload(
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
) )
async def test_default_availability_list_payload_all( async def test_default_availability_list_payload_all(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
await help_test_default_availability_list_payload_all( await help_test_default_availability_list_payload_all(
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
) )
async def test_default_availability_list_payload_any( async def test_default_availability_list_payload_any(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
await help_test_default_availability_list_payload_any( await help_test_default_availability_list_payload_any(
hass, mqtt_mock_entry_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( async def test_custom_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by custom payload with defined topic.""" """Test availability by custom payload with defined topic."""
await help_test_custom_availability_payload( await help_test_custom_availability_payload(
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
) )
async def test_discovery_update_availability( async def test_discovery_update_availability(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability discovery update.""" """Test availability discovery update."""
await help_test_discovery_update_availability( await help_test_discovery_update_availability(
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
) )
@ -824,12 +824,12 @@ async def test_discovery_update_availability(
) )
async def test_invalid_device_class( async def test_invalid_device_class(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test device_class option with invalid value.""" """Test device_class option with invalid value."""
with pytest.raises(AssertionError): with pytest.raises(AssertionError):
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
assert ( assert (
"Invalid config for [mqtt]: expected SensorDeviceClass or one of" in caplog.text "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( async def test_valid_device_class(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device_class option with valid values.""" """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") state = hass.states.get("sensor.test_1")
assert state.attributes["device_class"] == "temperature" assert state.attributes["device_class"] == "temperature"
@ -887,12 +887,12 @@ async def test_valid_device_class(
) )
async def test_invalid_state_class( async def test_invalid_state_class(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test state_class option with invalid value.""" """Test state_class option with invalid value."""
with pytest.raises(AssertionError): with pytest.raises(AssertionError):
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
assert ( assert (
"Invalid config for [mqtt]: expected SensorStateClass or one of" in caplog.text "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( async def test_valid_state_class(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test state_class option with valid values.""" """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") state = hass.states.get("sensor.test_1")
assert state.attributes["state_class"] == "measurement" 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( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message( await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_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( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_blocked_attribute_via_mqtt_json_message( await help_test_setting_blocked_attribute_via_mqtt_json_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
sensor.DOMAIN, sensor.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
MQTT_SENSOR_ATTRIBUTES_BLOCKED, 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( async def test_setting_attribute_with_template(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template( await help_test_setting_attribute_with_template(
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
) )
async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_not_dict(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_not_dict( await help_test_update_with_json_attrs_not_dict(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
sensor.DOMAIN, sensor.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -982,13 +982,13 @@ async def test_update_with_json_attrs_not_dict(
async def test_update_with_json_attrs_bad_json( async def test_update_with_json_attrs_bad_json(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_json( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
sensor.DOMAIN, sensor.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -997,13 +997,13 @@ async def test_update_with_json_attrs_bad_json(
async def test_discovery_update_attr( async def test_discovery_update_attr(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered MQTTAttributes.""" """Test update of discovered MQTTAttributes."""
await help_test_discovery_update_attr( await help_test_discovery_update_attr(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
sensor.DOMAIN, sensor.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -1032,27 +1032,27 @@ async def test_discovery_update_attr(
], ],
) )
async def test_unique_id( async def test_unique_id(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test unique id option only creates one sensor per unique_id.""" """Test unique id option only creates one sensor per unique_id."""
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( async def test_discovery_removal_sensor(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test removal of discovered sensor.""" """Test removal of discovered sensor."""
data = '{ "name": "test", "state_topic": "test_topic" }' data = '{ "name": "test", "state_topic": "test_topic" }'
await help_test_discovery_removal( 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( async def test_discovery_update_sensor_topic_template(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered sensor.""" """Test update of discovered sensor."""
@ -1077,7 +1077,7 @@ async def test_discovery_update_sensor_topic_template(
await help_test_discovery_update( await help_test_discovery_update(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
sensor.DOMAIN, sensor.DOMAIN,
config1, config1,
@ -1089,7 +1089,7 @@ async def test_discovery_update_sensor_topic_template(
async def test_discovery_update_sensor_template( async def test_discovery_update_sensor_template(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered sensor.""" """Test update of discovered sensor."""
@ -1112,7 +1112,7 @@ async def test_discovery_update_sensor_template(
await help_test_discovery_update( await help_test_discovery_update(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
sensor.DOMAIN, sensor.DOMAIN,
config1, config1,
@ -1124,7 +1124,7 @@ async def test_discovery_update_sensor_template(
async def test_discovery_update_unchanged_sensor( async def test_discovery_update_unchanged_sensor(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered sensor.""" """Test update of discovered sensor."""
@ -1134,7 +1134,7 @@ async def test_discovery_update_unchanged_sensor(
) as discovery_update: ) as discovery_update:
await help_test_discovery_update_unchanged( await help_test_discovery_update_unchanged(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
sensor.DOMAIN, sensor.DOMAIN,
data1, data1,
@ -1145,76 +1145,76 @@ async def test_discovery_update_unchanged_sensor(
@pytest.mark.no_fail_on_log_exception @pytest.mark.no_fail_on_log_exception
async def test_discovery_broken( async def test_discovery_broken(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test handling of bad discovery message.""" """Test handling of bad discovery message."""
data1 = '{ "name": "Beer", "state_topic": "test_topic#" }' data1 = '{ "name": "Beer", "state_topic": "test_topic#" }'
data2 = '{ "name": "Milk", "state_topic": "test_topic" }' data2 = '{ "name": "Milk", "state_topic": "test_topic" }'
await help_test_discovery_broken( 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( async def test_entity_device_info_with_connection(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT sensor device registry integration.""" """Test MQTT sensor device registry integration."""
await help_test_entity_device_info_with_connection( await help_test_entity_device_info_with_connection(
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_with_identifier( async def test_entity_device_info_with_identifier(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT sensor device registry integration.""" """Test MQTT sensor device registry integration."""
await help_test_entity_device_info_with_identifier( await help_test_entity_device_info_with_identifier(
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_update( async def test_entity_device_info_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry update.""" """Test device registry update."""
await help_test_entity_device_info_update( await help_test_entity_device_info_update(
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_remove( async def test_entity_device_info_remove(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry remove.""" """Test device registry remove."""
await help_test_entity_device_info_remove( await help_test_entity_device_info_remove(
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_subscriptions( async def test_entity_id_update_subscriptions(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT subscriptions are managed when entity_id is updated.""" """Test MQTT subscriptions are managed when entity_id is updated."""
await help_test_entity_id_update_subscriptions( await help_test_entity_id_update_subscriptions(
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_discovery_update( async def test_entity_id_update_discovery_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT discovery update when entity_id is updated.""" """Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update( await help_test_entity_id_update_discovery_update(
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_with_hub( async def test_entity_device_info_with_hub(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT sensor device registry integration.""" """Test MQTT sensor device registry integration."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
registry = dr.async_get(hass) registry = dr.async_get(hass)
hub = registry.async_get_or_create( hub = registry.async_get_or_create(
config_entry_id="123", config_entry_id="123",
@ -1241,66 +1241,66 @@ async def test_entity_device_info_with_hub(
async def test_entity_debug_info( async def test_entity_debug_info(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT sensor debug info.""" """Test MQTT sensor debug info."""
await help_test_entity_debug_info( await help_test_entity_debug_info(
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_debug_info_max_messages( async def test_entity_debug_info_max_messages(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT sensor debug info.""" """Test MQTT sensor debug info."""
await help_test_entity_debug_info_max_messages( await help_test_entity_debug_info_max_messages(
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_debug_info_message( async def test_entity_debug_info_message(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT debug info.""" """Test MQTT debug info."""
await help_test_entity_debug_info_message( await help_test_entity_debug_info_message(
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG, None hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG, None
) )
async def test_entity_debug_info_remove( async def test_entity_debug_info_remove(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT sensor debug info.""" """Test MQTT sensor debug info."""
await help_test_entity_debug_info_remove( await help_test_entity_debug_info_remove(
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_debug_info_update_entity_id( 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: ) -> None:
"""Test MQTT sensor debug info.""" """Test MQTT sensor debug info."""
await help_test_entity_debug_info_update_entity_id( await help_test_entity_debug_info_update_entity_id(
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_disabled_by_default( async def test_entity_disabled_by_default(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test entity disabled by default.""" """Test entity disabled by default."""
await help_test_entity_disabled_by_default( await help_test_entity_disabled_by_default(
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
) )
@pytest.mark.no_fail_on_log_exception @pytest.mark.no_fail_on_log_exception
async def test_entity_category( async def test_entity_category(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test entity category.""" """Test entity category."""
await help_test_entity_category( await help_test_entity_category(
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG 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( async def test_value_template_with_entity_id(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the access to attributes in value_template via the entity_id.""" """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") async_fire_mqtt_message(hass, "test-topic", "100")
state = hass.states.get("sensor.test") state = hass.states.get("sensor.test")
@ -1373,7 +1373,7 @@ async def test_reloadable(
) )
async def test_cleanup_triggers_and_restoring_state( async def test_cleanup_triggers_and_restoring_state(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
tmp_path: Path, tmp_path: Path,
freezer: FrozenDateTimeFactory, freezer: FrozenDateTimeFactory,
@ -1382,7 +1382,7 @@ async def test_cleanup_triggers_and_restoring_state(
"""Test cleanup old triggers at reloading and restoring the state.""" """Test cleanup old triggers at reloading and restoring the state."""
freezer.move_to("2022-02-02 12:01:00+01:00") 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") async_fire_mqtt_message(hass, "test-topic1", "100")
state = hass.states.get("sensor.test1") state = hass.states.get("sensor.test1")
assert state.state == "38" # 100 °F -> 38 °C 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( async def test_skip_restoring_state_with_over_due_expire_trigger(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
freezer: FrozenDateTimeFactory, freezer: FrozenDateTimeFactory,
) -> None: ) -> None:
"""Test restoring a state with over due expire timer.""" """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() fake_extra_data = MagicMock()
mock_restore_cache_with_extra_data(hass, ((fake_state, fake_extra_data),)) 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") state = hass.states.get("sensor.test3")
assert state.state == STATE_UNAVAILABLE 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( async def test_encoding_subscribable_topics(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
topic: str, topic: str,
value: str, value: str,
attribute: str | None, attribute: str | None,
@ -1467,7 +1467,7 @@ async def test_encoding_subscribable_topics(
"""Test handling of incoming encoded payload.""" """Test handling of incoming encoded payload."""
await help_test_encoding_subscribable_topics( await help_test_encoding_subscribable_topics(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
sensor.DOMAIN, sensor.DOMAIN,
DEFAULT_CONFIG[mqtt.DOMAIN][sensor.DOMAIN], DEFAULT_CONFIG[mqtt.DOMAIN][sensor.DOMAIN],
topic, topic,
@ -1480,21 +1480,21 @@ async def test_encoding_subscribable_topics(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_setup_manual_entity_from_yaml( async def test_setup_manual_entity_from_yaml(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
platform = sensor.DOMAIN platform = sensor.DOMAIN
assert hass.states.get(f"{platform}.test") assert hass.states.get(f"{platform}.test")
async def test_unload_entry( async def test_unload_entry(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = sensor.DOMAIN domain = sensor.DOMAIN
config = DEFAULT_CONFIG config = DEFAULT_CONFIG
await help_test_unload_config_entry_with_platform( await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_no_yaml_config, domain, config hass, mqtt_mock_entry, domain, config
) )

View File

@ -103,10 +103,10 @@ async def async_turn_off(
], ],
) )
async def test_controlling_state_via_topic( async def test_controlling_state_via_topic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the controlling state via topic.""" """Test the controlling state via topic."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get("siren.test") state = hass.states.get("siren.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -140,11 +140,11 @@ async def test_controlling_state_via_topic(
], ],
) )
async def test_sending_mqtt_commands_and_optimistic( async def test_sending_mqtt_commands_and_optimistic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the sending MQTT commands in optimistic mode.""" """Test the sending MQTT commands in optimistic mode."""
await hass.async_block_till_done() 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") state = hass.states.get("siren.test")
assert state.state == STATE_OFF 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( async def test_controlling_state_via_topic_and_json_message(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test the controlling state via topic and JSON message.""" """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") state = hass.states.get("siren.test")
assert state.state == STATE_UNKNOWN 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( async def test_controlling_state_and_attributes_with_json_message_without_template(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test the controlling state via topic and JSON message without a value template.""" """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") state = hass.states.get("siren.test")
assert state.state == STATE_UNKNOWN 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( async def test_filtering_not_supported_attributes_optimistic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setting attributes with support flags optimistic.""" """Test setting attributes with support flags optimistic."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state1 = hass.states.get("siren.test1") state1 = hass.states.get("siren.test1")
assert state1.state == STATE_OFF 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( 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: ) -> None:
"""Test setting attributes with support flags via state.""" """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") state1 = hass.states.get("siren.test1")
assert state1.state == STATE_UNKNOWN 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]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_availability_when_connection_lost( async def test_availability_when_connection_lost(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN hass, mqtt_mock_entry, siren.DOMAIN
) )
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_availability_without_topic( async def test_availability_without_topic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, siren.DOMAIN, DEFAULT_CONFIG
) )
async def test_default_availability_payload( async def test_default_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
config = { config = {
@ -514,7 +514,7 @@ async def test_default_availability_payload(
} }
await help_test_default_availability_payload( await help_test_default_availability_payload(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
siren.DOMAIN, siren.DOMAIN,
config, config,
True, True,
@ -524,7 +524,7 @@ async def test_default_availability_payload(
async def test_custom_availability_payload( async def test_custom_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by custom payload with defined topic.""" """Test availability by custom payload with defined topic."""
config = { config = {
@ -541,7 +541,7 @@ async def test_custom_availability_payload(
await help_test_custom_availability_payload( await help_test_custom_availability_payload(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
siren.DOMAIN, siren.DOMAIN,
config, config,
True, True,
@ -569,10 +569,10 @@ async def test_custom_availability_payload(
], ],
) )
async def test_custom_state_payload( async def test_custom_state_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the state payload.""" """Test the state payload."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get("siren.test") state = hass.states.get("siren.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -590,41 +590,41 @@ async def test_custom_state_payload(
async def test_setting_attribute_via_mqtt_json_message( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message( await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_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( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_blocked_attribute_via_mqtt_json_message( await help_test_setting_blocked_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG, {} hass, mqtt_mock_entry, siren.DOMAIN, DEFAULT_CONFIG, {}
) )
async def test_setting_attribute_with_template( async def test_setting_attribute_with_template(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template( await help_test_setting_attribute_with_template(
hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, siren.DOMAIN, DEFAULT_CONFIG
) )
async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_not_dict(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_not_dict( await help_test_update_with_json_attrs_not_dict(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
siren.DOMAIN, siren.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -633,13 +633,13 @@ async def test_update_with_json_attrs_not_dict(
async def test_update_with_json_attrs_bad_json( async def test_update_with_json_attrs_bad_json(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_json( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
siren.DOMAIN, siren.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -648,13 +648,13 @@ async def test_update_with_json_attrs_bad_json(
async def test_discovery_update_attr( async def test_discovery_update_attr(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered MQTTAttributes.""" """Test update of discovered MQTTAttributes."""
await help_test_discovery_update_attr( await help_test_discovery_update_attr(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
siren.DOMAIN, siren.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -685,15 +685,15 @@ async def test_discovery_update_attr(
], ],
) )
async def test_unique_id( async def test_unique_id(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test unique id option only creates one siren per unique_id.""" """Test unique id option only creates one siren per unique_id."""
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( async def test_discovery_removal_siren(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test removal of discovered siren.""" """Test removal of discovered siren."""
@ -702,14 +702,12 @@ async def test_discovery_removal_siren(
' "state_topic": "test_topic",' ' "state_topic": "test_topic",'
' "command_topic": "test_topic" }' ' "command_topic": "test_topic" }'
) )
await help_test_discovery_removal( await help_test_discovery_removal(hass, mqtt_mock_entry, caplog, siren.DOMAIN, data)
hass, mqtt_mock_entry_no_yaml_config, caplog, siren.DOMAIN, data
)
async def test_discovery_update_siren_topic_template( async def test_discovery_update_siren_topic_template(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered siren.""" """Test update of discovered siren."""
@ -736,7 +734,7 @@ async def test_discovery_update_siren_topic_template(
await help_test_discovery_update( await help_test_discovery_update(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
siren.DOMAIN, siren.DOMAIN,
config1, config1,
@ -748,7 +746,7 @@ async def test_discovery_update_siren_topic_template(
async def test_discovery_update_siren_template( async def test_discovery_update_siren_template(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered siren.""" """Test update of discovered siren."""
@ -773,7 +771,7 @@ async def test_discovery_update_siren_template(
await help_test_discovery_update( await help_test_discovery_update(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
siren.DOMAIN, siren.DOMAIN,
config1, config1,
@ -809,10 +807,10 @@ async def test_discovery_update_siren_template(
) )
async def test_command_templates( async def test_command_templates(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test siren with command templates optimistic.""" """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") state1 = hass.states.get("siren.beer")
assert state1.state == STATE_OFF assert state1.state == STATE_OFF
@ -875,7 +873,7 @@ async def test_command_templates(
async def test_discovery_update_unchanged_siren( async def test_discovery_update_unchanged_siren(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered siren.""" """Test update of discovered siren."""
@ -890,7 +888,7 @@ async def test_discovery_update_unchanged_siren(
) as discovery_update: ) as discovery_update:
await help_test_discovery_update_unchanged( await help_test_discovery_update_unchanged(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
siren.DOMAIN, siren.DOMAIN,
data1, data1,
@ -901,7 +899,7 @@ async def test_discovery_update_unchanged_siren(
@pytest.mark.no_fail_on_log_exception @pytest.mark.no_fail_on_log_exception
async def test_discovery_broken( async def test_discovery_broken(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test handling of bad discovery message.""" """Test handling of bad discovery message."""
@ -912,71 +910,71 @@ async def test_discovery_broken(
' "command_topic": "test_topic" }' ' "command_topic": "test_topic" }'
) )
await help_test_discovery_broken( 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( async def test_entity_device_info_with_connection(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT siren device registry integration.""" """Test MQTT siren device registry integration."""
await help_test_entity_device_info_with_connection( await help_test_entity_device_info_with_connection(
hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, siren.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_with_identifier( async def test_entity_device_info_with_identifier(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT siren device registry integration.""" """Test MQTT siren device registry integration."""
await help_test_entity_device_info_with_identifier( await help_test_entity_device_info_with_identifier(
hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, siren.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_update( async def test_entity_device_info_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry update.""" """Test device registry update."""
await help_test_entity_device_info_update( await help_test_entity_device_info_update(
hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, siren.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_remove( async def test_entity_device_info_remove(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry remove.""" """Test device registry remove."""
await help_test_entity_device_info_remove( await help_test_entity_device_info_remove(
hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, siren.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_subscriptions( async def test_entity_id_update_subscriptions(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT subscriptions are managed when entity_id is updated.""" """Test MQTT subscriptions are managed when entity_id is updated."""
await help_test_entity_id_update_subscriptions( await help_test_entity_id_update_subscriptions(
hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, siren.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_discovery_update( async def test_entity_id_update_discovery_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT discovery update when entity_id is updated.""" """Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update( await help_test_entity_id_update_discovery_update(
hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, siren.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_debug_info_message( async def test_entity_debug_info_message(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT debug info.""" """Test MQTT debug info."""
await help_test_entity_debug_info_message( await help_test_entity_debug_info_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
siren.DOMAIN, siren.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
siren.SERVICE_TURN_ON, siren.SERVICE_TURN_ON,
@ -1005,7 +1003,7 @@ async def test_entity_debug_info_message(
) )
async def test_publishing_with_custom_encoding( async def test_publishing_with_custom_encoding(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
service: str, service: str,
topic: str, topic: str,
@ -1020,7 +1018,7 @@ async def test_publishing_with_custom_encoding(
await help_test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
domain, domain,
config, config,
@ -1050,7 +1048,7 @@ async def test_reloadable(
) )
async def test_encoding_subscribable_topics( async def test_encoding_subscribable_topics(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
topic: str, topic: str,
value: str, value: str,
attribute: str | None, attribute: str | None,
@ -1059,7 +1057,7 @@ async def test_encoding_subscribable_topics(
"""Test handling of incoming encoded payload.""" """Test handling of incoming encoded payload."""
await help_test_encoding_subscribable_topics( await help_test_encoding_subscribable_topics(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
siren.DOMAIN, siren.DOMAIN,
DEFAULT_CONFIG[mqtt.DOMAIN][siren.DOMAIN], DEFAULT_CONFIG[mqtt.DOMAIN][siren.DOMAIN],
topic, topic,
@ -1071,21 +1069,21 @@ async def test_encoding_subscribable_topics(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_setup_manual_entity_from_yaml( async def test_setup_manual_entity_from_yaml(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
platform = siren.DOMAIN platform = siren.DOMAIN
assert hass.states.get(f"{platform}.test") assert hass.states.get(f"{platform}.test")
async def test_unload_entry( async def test_unload_entry(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = siren.DOMAIN domain = siren.DOMAIN
config = DEFAULT_CONFIG config = DEFAULT_CONFIG
await help_test_unload_config_entry_with_platform( await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_no_yaml_config, domain, config hass, mqtt_mock_entry, domain, config
) )

View File

@ -105,10 +105,10 @@ def vacuum_platform_only():
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_default_supported_features( async def test_default_supported_features(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test that the correct supported features.""" """Test that the correct supported features."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
entity = hass.states.get("vacuum.mqtttest") entity = hass.states.get("vacuum.mqtttest")
entity_features = entity.attributes.get(mqttvacuum.CONF_SUPPORTED_FEATURES, 0) entity_features = entity.attributes.get(mqttvacuum.CONF_SUPPORTED_FEATURES, 0)
assert sorted(services_to_strings(entity_features, SERVICE_TO_STRING)) == sorted( 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]) @pytest.mark.parametrize("hass_config", [CONFIG_ALL_SERVICES])
async def test_all_commands( async def test_all_commands(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test simple commands send to the vacuum.""" """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( await hass.services.async_call(
DOMAIN, SERVICE_START, {"entity_id": ENTITY_MATCH_ALL}, blocking=True 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( async def test_commands_without_supported_features(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test commands which are not supported by the vacuum.""" """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( await hass.services.async_call(
DOMAIN, SERVICE_START, {"entity_id": ENTITY_MATCH_ALL}, blocking=True 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]) @pytest.mark.parametrize("hass_config", [CONFIG_ALL_SERVICES])
async def test_status( async def test_status(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test status updates from the vacuum.""" """Test status updates from the vacuum."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get("vacuum.mqtttest") state = hass.states.get("vacuum.mqtttest")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -310,10 +310,10 @@ async def test_status(
], ],
) )
async def test_no_fan_vacuum( async def test_no_fan_vacuum(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test status updates from the vacuum when fan is not supported.""" """Test status updates from the vacuum when fan is not supported."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
message = """{ message = """{
"battery_level": 54, "battery_level": 54,
@ -357,10 +357,10 @@ async def test_no_fan_vacuum(
@pytest.mark.parametrize("hass_config", [CONFIG_ALL_SERVICES]) @pytest.mark.parametrize("hass_config", [CONFIG_ALL_SERVICES])
@pytest.mark.no_fail_on_log_exception @pytest.mark.no_fail_on_log_exception
async def test_status_invalid_json( async def test_status_invalid_json(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test to make sure nothing breaks if the vacuum sends bad JSON.""" """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}') async_fire_mqtt_message(hass, "vacuum/state", '{"asdfasas false}')
state = hass.states.get("vacuum.mqtttest") state = hass.states.get("vacuum.mqtttest")
@ -369,58 +369,58 @@ async def test_status_invalid_json(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_2]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_2])
async def test_availability_when_connection_lost( async def test_availability_when_connection_lost(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN hass, mqtt_mock_entry, vacuum.DOMAIN
) )
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_2]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_2])
async def test_availability_without_topic( async def test_availability_without_topic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2 hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2
) )
async def test_default_availability_payload( async def test_default_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
await help_test_default_availability_payload( await help_test_default_availability_payload(
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2 hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2
) )
async def test_custom_availability_payload( async def test_custom_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by custom payload with defined topic.""" """Test availability by custom payload with defined topic."""
await help_test_custom_availability_payload( await help_test_custom_availability_payload(
hass, mqtt_mock_entry_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( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message( await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_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( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_blocked_attribute_via_mqtt_json_message( await help_test_setting_blocked_attribute_via_mqtt_json_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
vacuum.DOMAIN, vacuum.DOMAIN,
DEFAULT_CONFIG_2, DEFAULT_CONFIG_2,
MQTT_VACUUM_ATTRIBUTES_BLOCKED, 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( async def test_setting_attribute_with_template(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template( await help_test_setting_attribute_with_template(
hass, mqtt_mock_entry_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( async def test_update_with_json_attrs_not_dict(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_not_dict( await help_test_update_with_json_attrs_not_dict(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
vacuum.DOMAIN, vacuum.DOMAIN,
DEFAULT_CONFIG_2, 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( async def test_update_with_json_attrs_bad_json(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_json( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
vacuum.DOMAIN, vacuum.DOMAIN,
DEFAULT_CONFIG_2, DEFAULT_CONFIG_2,
@ -468,13 +468,13 @@ async def test_update_with_json_attrs_bad_json(
async def test_discovery_update_attr( async def test_discovery_update_attr(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered MQTTAttributes.""" """Test update of discovered MQTTAttributes."""
await help_test_discovery_update_attr( await help_test_discovery_update_attr(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
vacuum.DOMAIN, vacuum.DOMAIN,
DEFAULT_CONFIG_2, DEFAULT_CONFIG_2,
@ -505,40 +505,40 @@ async def test_discovery_update_attr(
], ],
) )
async def test_unique_id( async def test_unique_id(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test unique id option only creates one vacuum per unique_id.""" """Test unique id option only creates one vacuum per unique_id."""
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( async def test_discovery_removal_vacuum(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test removal of discovered vacuum.""" """Test removal of discovered vacuum."""
data = '{ "schema": "state", "name": "test", "command_topic": "test_topic"}' data = '{ "schema": "state", "name": "test", "command_topic": "test_topic"}'
await help_test_discovery_removal( await help_test_discovery_removal(
hass, mqtt_mock_entry_no_yaml_config, caplog, vacuum.DOMAIN, data hass, mqtt_mock_entry, caplog, vacuum.DOMAIN, data
) )
async def test_discovery_update_vacuum( async def test_discovery_update_vacuum(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered vacuum.""" """Test update of discovered vacuum."""
config1 = {"schema": "state", "name": "Beer", "command_topic": "test_topic"} config1 = {"schema": "state", "name": "Beer", "command_topic": "test_topic"}
config2 = {"schema": "state", "name": "Milk", "command_topic": "test_topic"} config2 = {"schema": "state", "name": "Milk", "command_topic": "test_topic"}
await help_test_discovery_update( 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( async def test_discovery_update_unchanged_vacuum(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered vacuum.""" """Test update of discovered vacuum."""
@ -548,7 +548,7 @@ async def test_discovery_update_unchanged_vacuum(
) as discovery_update: ) as discovery_update:
await help_test_discovery_update_unchanged( await help_test_discovery_update_unchanged(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
vacuum.DOMAIN, vacuum.DOMAIN,
data1, data1,
@ -559,78 +559,78 @@ async def test_discovery_update_unchanged_vacuum(
@pytest.mark.no_fail_on_log_exception @pytest.mark.no_fail_on_log_exception
async def test_discovery_broken( async def test_discovery_broken(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test handling of bad discovery message.""" """Test handling of bad discovery message."""
data1 = '{ "schema": "state", "name": "Beer", "command_topic": "test_topic#"}' data1 = '{ "schema": "state", "name": "Beer", "command_topic": "test_topic#"}'
data2 = '{ "schema": "state", "name": "Milk", "command_topic": "test_topic"}' data2 = '{ "schema": "state", "name": "Milk", "command_topic": "test_topic"}'
await help_test_discovery_broken( 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( async def test_entity_device_info_with_connection(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT vacuum device registry integration.""" """Test MQTT vacuum device registry integration."""
await help_test_entity_device_info_with_connection( await help_test_entity_device_info_with_connection(
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2 hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2
) )
async def test_entity_device_info_with_identifier( async def test_entity_device_info_with_identifier(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT vacuum device registry integration.""" """Test MQTT vacuum device registry integration."""
await help_test_entity_device_info_with_identifier( await help_test_entity_device_info_with_identifier(
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2 hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2
) )
async def test_entity_device_info_update( async def test_entity_device_info_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry update.""" """Test device registry update."""
await help_test_entity_device_info_update( await help_test_entity_device_info_update(
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2 hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2
) )
async def test_entity_device_info_remove( async def test_entity_device_info_remove(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry remove.""" """Test device registry remove."""
await help_test_entity_device_info_remove( await help_test_entity_device_info_remove(
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2 hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2
) )
async def test_entity_id_update_subscriptions( async def test_entity_id_update_subscriptions(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT subscriptions are managed when entity_id is updated.""" """Test MQTT subscriptions are managed when entity_id is updated."""
await help_test_entity_id_update_subscriptions( await help_test_entity_id_update_subscriptions(
hass, mqtt_mock_entry_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( async def test_entity_id_update_discovery_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT discovery update when entity_id is updated.""" """Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update( await help_test_entity_id_update_discovery_update(
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2 hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2
) )
async def test_entity_debug_info_message( async def test_entity_debug_info_message(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT debug info.""" """Test MQTT debug info."""
await help_test_entity_debug_info_message( await help_test_entity_debug_info_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
vacuum.DOMAIN, vacuum.DOMAIN,
DEFAULT_CONFIG_2, DEFAULT_CONFIG_2,
vacuum.SERVICE_START, vacuum.SERVICE_START,
@ -681,7 +681,7 @@ async def test_entity_debug_info_message(
) )
async def test_publishing_with_custom_encoding( async def test_publishing_with_custom_encoding(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
service: str, service: str,
topic: str, topic: str,
@ -707,7 +707,7 @@ async def test_publishing_with_custom_encoding(
await help_test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
domain, domain,
config, config,
@ -748,7 +748,7 @@ async def test_reloadable(
) )
async def test_encoding_subscribable_topics( async def test_encoding_subscribable_topics(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
topic: str, topic: str,
value: str, value: str,
attribute: str | None, attribute: str | None,
@ -757,7 +757,7 @@ async def test_encoding_subscribable_topics(
"""Test handling of incoming encoded payload.""" """Test handling of incoming encoded payload."""
await help_test_encoding_subscribable_topics( await help_test_encoding_subscribable_topics(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
vacuum.DOMAIN, vacuum.DOMAIN,
DEFAULT_CONFIG[mqtt.DOMAIN][vacuum.DOMAIN], DEFAULT_CONFIG[mqtt.DOMAIN][vacuum.DOMAIN],
topic, topic,
@ -770,9 +770,9 @@ async def test_encoding_subscribable_topics(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_setup_manual_entity_from_yaml( async def test_setup_manual_entity_from_yaml(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
platform = vacuum.DOMAIN platform = vacuum.DOMAIN
assert hass.states.get(f"{platform}.mqtttest") assert hass.states.get(f"{platform}.mqtttest")

View File

@ -23,11 +23,11 @@ def no_platforms():
async def test_subscribe_topics( async def test_subscribe_topics(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test subscription to topics.""" """Test subscription to topics."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
calls1 = [] calls1 = []
@callback @callback
@ -76,11 +76,11 @@ async def test_subscribe_topics(
async def test_modify_topics( async def test_modify_topics(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test modification of topics.""" """Test modification of topics."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
calls1 = [] calls1 = []
@callback @callback
@ -143,11 +143,11 @@ async def test_modify_topics(
async def test_qos_encoding_default( async def test_qos_encoding_default(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test default qos and encoding.""" """Test default qos and encoding."""
mqtt_mock = await mqtt_mock_entry_no_yaml_config() mqtt_mock = await mqtt_mock_entry()
@callback @callback
def msg_callback(*args): def msg_callback(*args):
@ -165,11 +165,11 @@ async def test_qos_encoding_default(
async def test_qos_encoding_custom( async def test_qos_encoding_custom(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test custom qos and encoding.""" """Test custom qos and encoding."""
mqtt_mock = await mqtt_mock_entry_no_yaml_config() mqtt_mock = await mqtt_mock_entry()
@callback @callback
def msg_callback(*args): def msg_callback(*args):
@ -194,11 +194,11 @@ async def test_qos_encoding_custom(
async def test_no_change( async def test_no_change(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test subscription to topics without change.""" """Test subscription to topics without change."""
mqtt_mock = await mqtt_mock_entry_no_yaml_config() mqtt_mock = await mqtt_mock_entry()
calls = [] calls = []

View File

@ -79,10 +79,10 @@ def switch_platform_only():
], ],
) )
async def test_controlling_state_via_topic( async def test_controlling_state_via_topic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the controlling state via topic.""" """Test the controlling state via topic."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get("switch.test") state = hass.states.get("switch.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -122,13 +122,13 @@ async def test_controlling_state_via_topic(
], ],
) )
async def test_sending_mqtt_commands_and_optimistic( async def test_sending_mqtt_commands_and_optimistic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the sending MQTT commands in optimistic mode.""" """Test the sending MQTT commands in optimistic mode."""
fake_state = State("switch.test", "on") fake_state = State("switch.test", "on")
mock_restore_cache(hass, (fake_state,)) 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") state = hass.states.get("switch.test")
assert state.state == STATE_ON 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( async def test_sending_inital_state_and_optimistic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the initial state in optimistic mode.""" """Test the initial state in optimistic mode."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get("switch.test") state = hass.states.get("switch.test")
assert state.state == STATE_UNKNOWN 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( 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: ) -> None:
"""Test the controlling state via topic and JSON message.""" """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") state = hass.states.get("switch.test")
assert state.state == STATE_UNKNOWN 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]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_availability_when_connection_lost( async def test_availability_when_connection_lost(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN hass, mqtt_mock_entry, switch.DOMAIN
) )
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_availability_without_topic( async def test_availability_without_topic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, switch.DOMAIN, DEFAULT_CONFIG
) )
async def test_default_availability_payload( async def test_default_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
config = { config = {
@ -255,7 +255,7 @@ async def test_default_availability_payload(
} }
await help_test_default_availability_payload( await help_test_default_availability_payload(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
switch.DOMAIN, switch.DOMAIN,
config, config,
True, True,
@ -265,7 +265,7 @@ async def test_default_availability_payload(
async def test_custom_availability_payload( async def test_custom_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by custom payload with defined topic.""" """Test availability by custom payload with defined topic."""
config = { config = {
@ -282,7 +282,7 @@ async def test_custom_availability_payload(
await help_test_custom_availability_payload( await help_test_custom_availability_payload(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
switch.DOMAIN, switch.DOMAIN,
config, config,
True, True,
@ -310,10 +310,10 @@ async def test_custom_availability_payload(
], ],
) )
async def test_custom_state_payload( async def test_custom_state_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the state payload.""" """Test the state payload."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get("switch.test") state = hass.states.get("switch.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -331,41 +331,41 @@ async def test_custom_state_payload(
async def test_setting_attribute_via_mqtt_json_message( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message( await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_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( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_blocked_attribute_via_mqtt_json_message( await help_test_setting_blocked_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG, {} hass, mqtt_mock_entry, switch.DOMAIN, DEFAULT_CONFIG, {}
) )
async def test_setting_attribute_with_template( async def test_setting_attribute_with_template(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template( await help_test_setting_attribute_with_template(
hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, switch.DOMAIN, DEFAULT_CONFIG
) )
async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_not_dict(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_not_dict( await help_test_update_with_json_attrs_not_dict(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
switch.DOMAIN, switch.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -374,13 +374,13 @@ async def test_update_with_json_attrs_not_dict(
async def test_update_with_json_attrs_bad_json( async def test_update_with_json_attrs_bad_json(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_json( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
switch.DOMAIN, switch.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -389,13 +389,13 @@ async def test_update_with_json_attrs_bad_json(
async def test_discovery_update_attr( async def test_discovery_update_attr(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered MQTTAttributes.""" """Test update of discovered MQTTAttributes."""
await help_test_discovery_update_attr( await help_test_discovery_update_attr(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
switch.DOMAIN, switch.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -426,15 +426,15 @@ async def test_discovery_update_attr(
], ],
) )
async def test_unique_id( async def test_unique_id(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test unique id option only creates one switch per unique_id.""" """Test unique id option only creates one switch per unique_id."""
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( async def test_discovery_removal_switch(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test removal of discovered switch.""" """Test removal of discovered switch."""
@ -444,13 +444,13 @@ async def test_discovery_removal_switch(
' "command_topic": "test_topic" }' ' "command_topic": "test_topic" }'
) )
await help_test_discovery_removal( 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( async def test_discovery_update_switch_topic_template(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered switch.""" """Test update of discovered switch."""
@ -477,7 +477,7 @@ async def test_discovery_update_switch_topic_template(
await help_test_discovery_update( await help_test_discovery_update(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
switch.DOMAIN, switch.DOMAIN,
config1, config1,
@ -489,7 +489,7 @@ async def test_discovery_update_switch_topic_template(
async def test_discovery_update_switch_template( async def test_discovery_update_switch_template(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered switch.""" """Test update of discovered switch."""
@ -514,7 +514,7 @@ async def test_discovery_update_switch_template(
await help_test_discovery_update( await help_test_discovery_update(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
switch.DOMAIN, switch.DOMAIN,
config1, config1,
@ -526,7 +526,7 @@ async def test_discovery_update_switch_template(
async def test_discovery_update_unchanged_switch( async def test_discovery_update_unchanged_switch(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered switch.""" """Test update of discovered switch."""
@ -541,7 +541,7 @@ async def test_discovery_update_unchanged_switch(
) as discovery_update: ) as discovery_update:
await help_test_discovery_update_unchanged( await help_test_discovery_update_unchanged(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
switch.DOMAIN, switch.DOMAIN,
data1, data1,
@ -552,7 +552,7 @@ async def test_discovery_update_unchanged_switch(
@pytest.mark.no_fail_on_log_exception @pytest.mark.no_fail_on_log_exception
async def test_discovery_broken( async def test_discovery_broken(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test handling of bad discovery message.""" """Test handling of bad discovery message."""
@ -563,71 +563,71 @@ async def test_discovery_broken(
' "command_topic": "test_topic" }' ' "command_topic": "test_topic" }'
) )
await help_test_discovery_broken( 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( async def test_entity_device_info_with_connection(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT switch device registry integration.""" """Test MQTT switch device registry integration."""
await help_test_entity_device_info_with_connection( await help_test_entity_device_info_with_connection(
hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, switch.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_with_identifier( async def test_entity_device_info_with_identifier(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT switch device registry integration.""" """Test MQTT switch device registry integration."""
await help_test_entity_device_info_with_identifier( await help_test_entity_device_info_with_identifier(
hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, switch.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_update( async def test_entity_device_info_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry update.""" """Test device registry update."""
await help_test_entity_device_info_update( await help_test_entity_device_info_update(
hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, switch.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_remove( async def test_entity_device_info_remove(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry remove.""" """Test device registry remove."""
await help_test_entity_device_info_remove( await help_test_entity_device_info_remove(
hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, switch.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_subscriptions( async def test_entity_id_update_subscriptions(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT subscriptions are managed when entity_id is updated.""" """Test MQTT subscriptions are managed when entity_id is updated."""
await help_test_entity_id_update_subscriptions( await help_test_entity_id_update_subscriptions(
hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, switch.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_discovery_update( async def test_entity_id_update_discovery_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT discovery update when entity_id is updated.""" """Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update( await help_test_entity_id_update_discovery_update(
hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, switch.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_debug_info_message( async def test_entity_debug_info_message(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT debug info.""" """Test MQTT debug info."""
await help_test_entity_debug_info_message( await help_test_entity_debug_info_message(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
switch.DOMAIN, switch.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
switch.SERVICE_TURN_ON, switch.SERVICE_TURN_ON,
@ -655,7 +655,7 @@ async def test_entity_debug_info_message(
) )
async def test_publishing_with_custom_encoding( async def test_publishing_with_custom_encoding(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
service: str, service: str,
topic: str, topic: str,
@ -669,7 +669,7 @@ async def test_publishing_with_custom_encoding(
await help_test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
domain, domain,
config, config,
@ -699,7 +699,7 @@ async def test_reloadable(
) )
async def test_encoding_subscribable_topics( async def test_encoding_subscribable_topics(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
topic: str, topic: str,
value: str, value: str,
attribute: str | None, attribute: str | None,
@ -708,7 +708,7 @@ async def test_encoding_subscribable_topics(
"""Test handling of incoming encoded payload.""" """Test handling of incoming encoded payload."""
await help_test_encoding_subscribable_topics( await help_test_encoding_subscribable_topics(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
switch.DOMAIN, switch.DOMAIN,
DEFAULT_CONFIG[mqtt.DOMAIN][switch.DOMAIN], DEFAULT_CONFIG[mqtt.DOMAIN][switch.DOMAIN],
topic, topic,
@ -720,21 +720,21 @@ async def test_encoding_subscribable_topics(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_setup_manual_entity_from_yaml( async def test_setup_manual_entity_from_yaml(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
platform = switch.DOMAIN platform = switch.DOMAIN
assert hass.states.get(f"{platform}.test") assert hass.states.get(f"{platform}.test")
async def test_unload_entry( async def test_unload_entry(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = switch.DOMAIN domain = switch.DOMAIN
config = DEFAULT_CONFIG config = DEFAULT_CONFIG
await help_test_unload_config_entry_with_platform( await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_no_yaml_config, domain, config hass, mqtt_mock_entry, domain, config
) )

View File

@ -64,11 +64,11 @@ def tag_mock():
async def test_discover_bad_tag( async def test_discover_bad_tag(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
tag_mock, tag_mock,
) -> None: ) -> None:
"""Test bad discovery message.""" """Test bad discovery message."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
config1 = copy.deepcopy(DEFAULT_CONFIG_DEVICE) config1 = copy.deepcopy(DEFAULT_CONFIG_DEVICE)
# Test sending bad data # Test sending bad data
@ -91,11 +91,11 @@ async def test_discover_bad_tag(
async def test_if_fires_on_mqtt_message_with_device( async def test_if_fires_on_mqtt_message_with_device(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
tag_mock, tag_mock,
) -> None: ) -> None:
"""Test tag scanning, with device.""" """Test tag scanning, with device."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
config = copy.deepcopy(DEFAULT_CONFIG_DEVICE) config = copy.deepcopy(DEFAULT_CONFIG_DEVICE)
async_fire_mqtt_message(hass, "homeassistant/tag/bla1/config", json.dumps(config)) 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( async def test_if_fires_on_mqtt_message_without_device(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
tag_mock, tag_mock,
) -> None: ) -> None:
"""Test tag scanning, without device.""" """Test tag scanning, without device."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
config = copy.deepcopy(DEFAULT_CONFIG) config = copy.deepcopy(DEFAULT_CONFIG)
async_fire_mqtt_message(hass, "homeassistant/tag/bla1/config", json.dumps(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( async def test_if_fires_on_mqtt_message_with_template(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
tag_mock, tag_mock,
) -> None: ) -> None:
"""Test tag scanning, with device.""" """Test tag scanning, with device."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
config = copy.deepcopy(DEFAULT_CONFIG_JSON) config = copy.deepcopy(DEFAULT_CONFIG_JSON)
async_fire_mqtt_message(hass, "homeassistant/tag/bla1/config", json.dumps(config)) 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( async def test_strip_tag_id(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
tag_mock, tag_mock,
) -> None: ) -> None:
"""Test strip whitespace from tag_id.""" """Test strip whitespace from tag_id."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
config = copy.deepcopy(DEFAULT_CONFIG) config = copy.deepcopy(DEFAULT_CONFIG)
async_fire_mqtt_message(hass, "homeassistant/tag/bla1/config", json.dumps(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( async def test_if_fires_on_mqtt_message_after_update_with_device(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
tag_mock, tag_mock,
) -> None: ) -> None:
"""Test tag scanning after update.""" """Test tag scanning after update."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
config1 = copy.deepcopy(DEFAULT_CONFIG_DEVICE) config1 = copy.deepcopy(DEFAULT_CONFIG_DEVICE)
config1["some_future_option_1"] = "future_option_1" config1["some_future_option_1"] = "future_option_1"
config2 = copy.deepcopy(DEFAULT_CONFIG_DEVICE) 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( async def test_if_fires_on_mqtt_message_after_update_without_device(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
tag_mock, tag_mock,
) -> None: ) -> None:
"""Test tag scanning after update.""" """Test tag scanning after update."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
config1 = copy.deepcopy(DEFAULT_CONFIG) config1 = copy.deepcopy(DEFAULT_CONFIG)
config2 = copy.deepcopy(DEFAULT_CONFIG) config2 = copy.deepcopy(DEFAULT_CONFIG)
config2["topic"] = "foobar/tag_scanned2" 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( async def test_if_fires_on_mqtt_message_after_update_with_template(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
tag_mock, tag_mock,
) -> None: ) -> None:
"""Test tag scanning after update.""" """Test tag scanning after update."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
config1 = copy.deepcopy(DEFAULT_CONFIG_JSON) config1 = copy.deepcopy(DEFAULT_CONFIG_JSON)
config2 = copy.deepcopy(DEFAULT_CONFIG_JSON) config2 = copy.deepcopy(DEFAULT_CONFIG_JSON)
config2["value_template"] = "{{ value_json.RDM6300.UID }}" 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( async def test_no_resubscribe_same_topic(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test subscription to topics without change.""" """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) config = copy.deepcopy(DEFAULT_CONFIG_DEVICE)
async_fire_mqtt_message(hass, "homeassistant/tag/bla1/config", json.dumps(config)) 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( async def test_not_fires_on_mqtt_message_after_remove_by_mqtt_with_device(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
tag_mock, tag_mock,
) -> None: ) -> None:
"""Test tag scanning after removal.""" """Test tag scanning after removal."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
config = copy.deepcopy(DEFAULT_CONFIG_DEVICE) config = copy.deepcopy(DEFAULT_CONFIG_DEVICE)
async_fire_mqtt_message(hass, "homeassistant/tag/bla1/config", json.dumps(config)) 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( async def test_not_fires_on_mqtt_message_after_remove_by_mqtt_without_device(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
tag_mock, tag_mock,
) -> None: ) -> None:
"""Test tag scanning not firing after removal.""" """Test tag scanning not firing after removal."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
config = copy.deepcopy(DEFAULT_CONFIG) config = copy.deepcopy(DEFAULT_CONFIG)
async_fire_mqtt_message(hass, "homeassistant/tag/bla1/config", json.dumps(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: HomeAssistant,
hass_ws_client: WebSocketGenerator, hass_ws_client: WebSocketGenerator,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
tag_mock, tag_mock,
) -> None: ) -> None:
"""Test tag scanning after removal.""" """Test tag scanning after removal."""
assert await async_setup_component(hass, "config", {}) assert await async_setup_component(hass, "config", {})
await hass.async_block_till_done() await hass.async_block_till_done()
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
ws_client = await hass_ws_client(hass) ws_client = await hass_ws_client(hass)
config = copy.deepcopy(DEFAULT_CONFIG_DEVICE) 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( async def test_entity_device_info_with_connection(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT device registry integration.""" """Test MQTT device registry integration."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
registry = dr.async_get(hass) registry = dr.async_get(hass)
data = json.dumps( data = json.dumps(
@ -480,10 +480,10 @@ async def test_entity_device_info_with_connection(
async def test_entity_device_info_with_identifier( async def test_entity_device_info_with_identifier(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT device registry integration.""" """Test MQTT device registry integration."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
registry = dr.async_get(hass) registry = dr.async_get(hass)
data = json.dumps( data = json.dumps(
@ -513,10 +513,10 @@ async def test_entity_device_info_with_identifier(
async def test_entity_device_info_update( async def test_entity_device_info_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry update.""" """Test device registry update."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
registry = dr.async_get(hass) registry = dr.async_get(hass)
config = { config = {
@ -553,12 +553,12 @@ async def test_cleanup_tag(
hass: HomeAssistant, hass: HomeAssistant,
hass_ws_client: WebSocketGenerator, hass_ws_client: WebSocketGenerator,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test tag discovery topic is cleaned when device is removed from registry.""" """Test tag discovery topic is cleaned when device is removed from registry."""
assert await async_setup_component(hass, "config", {}) assert await async_setup_component(hass, "config", {})
await hass.async_block_till_done() 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) ws_client = await hass_ws_client(hass)
mqtt_entry = hass.config_entries.async_entries("mqtt")[0] mqtt_entry = hass.config_entries.async_entries("mqtt")[0]
@ -636,10 +636,10 @@ async def test_cleanup_tag(
async def test_cleanup_device( async def test_cleanup_device(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test removal from device registry when tag is removed.""" """Test removal from device registry when tag is removed."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
config = { config = {
"topic": "test-topic", "topic": "test-topic",
"device": {"identifiers": ["helloworld"]}, "device": {"identifiers": ["helloworld"]},
@ -664,11 +664,11 @@ async def test_cleanup_device(
async def test_cleanup_device_several_tags( async def test_cleanup_device_several_tags(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
tag_mock, tag_mock,
) -> None: ) -> None:
"""Test removal from device registry when the last tag is removed.""" """Test removal from device registry when the last tag is removed."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
config1 = { config1 = {
"topic": "test-topic1", "topic": "test-topic1",
"device": {"identifiers": ["helloworld"]}, "device": {"identifiers": ["helloworld"]},
@ -712,13 +712,13 @@ async def test_cleanup_device_several_tags(
async def test_cleanup_device_with_entity_and_trigger_1( async def test_cleanup_device_with_entity_and_trigger_1(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test removal from device registry for device with tag, entity and trigger. """Test removal from device registry for device with tag, entity and trigger.
Tag removed first, then trigger and entity. Tag removed first, then trigger and entity.
""" """
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
config1 = { config1 = {
"topic": "test-topic", "topic": "test-topic",
"device": {"identifiers": ["helloworld"]}, "device": {"identifiers": ["helloworld"]},
@ -779,13 +779,13 @@ async def test_cleanup_device_with_entity_and_trigger_1(
async def test_cleanup_device_with_entity2( async def test_cleanup_device_with_entity2(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test removal from device registry for device with tag, entity and trigger. """Test removal from device registry for device with tag, entity and trigger.
Trigger and entity removed first, then tag. Trigger and entity removed first, then tag.
""" """
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
config1 = { config1 = {
"topic": "test-topic", "topic": "test-topic",
"device": {"identifiers": ["helloworld"]}, "device": {"identifiers": ["helloworld"]},
@ -846,11 +846,11 @@ async def test_cleanup_device_with_entity2(
@pytest.mark.xfail(raises=MultipleInvalid) @pytest.mark.xfail(raises=MultipleInvalid)
async def test_update_with_bad_config_not_breaks_discovery( async def test_update_with_bad_config_not_breaks_discovery(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
tag_mock, tag_mock,
) -> None: ) -> None:
"""Test a bad update does not break discovery.""" """Test a bad update does not break discovery."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
config1 = { config1 = {
"topic": "test-topic", "topic": "test-topic",
"device": {"identifiers": ["helloworld"]}, "device": {"identifiers": ["helloworld"]},

View File

@ -87,10 +87,10 @@ async def async_set_value(
], ],
) )
async def test_controlling_state_via_topic( async def test_controlling_state_via_topic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the controlling state via topic.""" """Test the controlling state via topic."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get("text.test") state = hass.states.get("text.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -133,11 +133,11 @@ async def test_controlling_state_via_topic(
) )
async def test_controlling_validation_state_via_topic( async def test_controlling_validation_state_via_topic(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test the validation of a received state.""" """Test the validation of a received state."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get("text.test") state = hass.states.get("text.test")
assert state.state == STATE_UNKNOWN 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( 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: ) -> None:
"""Test the validation of min and max configuration attributes.""" """Test the validation of min and max configuration attributes."""
with pytest.raises(AssertionError): with pytest.raises(AssertionError):
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
@pytest.mark.parametrize( @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( 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: ) -> None:
"""Test the max value of of max configuration attribute.""" """Test the max value of of max configuration attribute."""
with pytest.raises(AssertionError): with pytest.raises(AssertionError):
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
@pytest.mark.parametrize( @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( async def test_sending_mqtt_commands_and_optimistic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the sending MQTT commands in optimistic mode.""" """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") state = hass.states.get("text.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -294,10 +294,10 @@ async def test_sending_mqtt_commands_and_optimistic(
], ],
) )
async def test_set_text_validation( async def test_set_text_validation(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the initial state in optimistic mode.""" """Test the initial state in optimistic mode."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
state = hass.states.get("text.test") state = hass.states.get("text.test")
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@ -322,26 +322,26 @@ async def test_set_text_validation(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_availability_when_connection_lost( async def test_availability_when_connection_lost(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN hass, mqtt_mock_entry, text.DOMAIN
) )
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_availability_without_topic( async def test_availability_without_topic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, text.DOMAIN, DEFAULT_CONFIG
) )
async def test_default_availability_payload( async def test_default_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
config = { config = {
@ -355,7 +355,7 @@ async def test_default_availability_payload(
} }
await help_test_default_availability_payload( await help_test_default_availability_payload(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
text.DOMAIN, text.DOMAIN,
config, config,
True, True,
@ -365,7 +365,7 @@ async def test_default_availability_payload(
async def test_custom_availability_payload( async def test_custom_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by custom payload with defined topic.""" """Test availability by custom payload with defined topic."""
config = { config = {
@ -380,7 +380,7 @@ async def test_custom_availability_payload(
await help_test_custom_availability_payload( await help_test_custom_availability_payload(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
text.DOMAIN, text.DOMAIN,
config, config,
True, True,
@ -390,41 +390,41 @@ async def test_custom_availability_payload(
async def test_setting_attribute_via_mqtt_json_message( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message( await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_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( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_blocked_attribute_via_mqtt_json_message( await help_test_setting_blocked_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN, DEFAULT_CONFIG, {} hass, mqtt_mock_entry, text.DOMAIN, DEFAULT_CONFIG, {}
) )
async def test_setting_attribute_with_template( async def test_setting_attribute_with_template(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template( await help_test_setting_attribute_with_template(
hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, text.DOMAIN, DEFAULT_CONFIG
) )
async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_not_dict(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_not_dict( await help_test_update_with_json_attrs_not_dict(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
text.DOMAIN, text.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -433,13 +433,13 @@ async def test_update_with_json_attrs_not_dict(
async def test_update_with_json_attrs_bad_json( async def test_update_with_json_attrs_bad_json(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_json( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
text.DOMAIN, text.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -448,13 +448,13 @@ async def test_update_with_json_attrs_bad_json(
async def test_discovery_update_attr( async def test_discovery_update_attr(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered MQTTAttributes.""" """Test update of discovered MQTTAttributes."""
await help_test_discovery_update_attr( await help_test_discovery_update_attr(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
text.DOMAIN, text.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -485,15 +485,15 @@ async def test_discovery_update_attr(
], ],
) )
async def test_unique_id( async def test_unique_id(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test unique id option only creates one text per unique_id.""" """Test unique id option only creates one text per unique_id."""
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( async def test_discovery_removal_text(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test removal of discovered text entity.""" """Test removal of discovered text entity."""
@ -502,14 +502,12 @@ async def test_discovery_removal_text(
' "state_topic": "test_topic",' ' "state_topic": "test_topic",'
' "command_topic": "test_topic" }' ' "command_topic": "test_topic" }'
) )
await help_test_discovery_removal( await help_test_discovery_removal(hass, mqtt_mock_entry, caplog, text.DOMAIN, data)
hass, mqtt_mock_entry_no_yaml_config, caplog, text.DOMAIN, data
)
async def test_discovery_text_update( async def test_discovery_text_update(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered text entity.""" """Test update of discovered text entity."""
@ -525,13 +523,13 @@ async def test_discovery_text_update(
} }
await help_test_discovery_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( async def test_discovery_update_unchanged_update(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered update.""" """Test update of discovered update."""
@ -541,7 +539,7 @@ async def test_discovery_update_unchanged_update(
) as discovery_update: ) as discovery_update:
await help_test_discovery_update_unchanged( await help_test_discovery_update_unchanged(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
text.DOMAIN, text.DOMAIN,
data1, data1,
@ -551,20 +549,20 @@ async def test_discovery_update_unchanged_update(
async def test_discovery_update_text( async def test_discovery_update_text(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered text entity.""" """Test update of discovered text entity."""
config1 = {"name": "Beer", "command_topic": "cmd-topic1"} config1 = {"name": "Beer", "command_topic": "cmd-topic1"}
config2 = {"name": "Milk", "command_topic": "cmd-topic2"} config2 = {"name": "Milk", "command_topic": "cmd-topic2"}
await help_test_discovery_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_climate( async def test_discovery_update_unchanged_climate(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered text entity.""" """Test update of discovered text entity."""
@ -574,7 +572,7 @@ async def test_discovery_update_unchanged_climate(
) as discovery_update: ) as discovery_update:
await help_test_discovery_update_unchanged( await help_test_discovery_update_unchanged(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
text.DOMAIN, text.DOMAIN,
data1, data1,
@ -585,7 +583,7 @@ async def test_discovery_update_unchanged_climate(
@pytest.mark.no_fail_on_log_exception @pytest.mark.no_fail_on_log_exception
async def test_discovery_broken( async def test_discovery_broken(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test handling of bad discovery message.""" """Test handling of bad discovery message."""
@ -596,70 +594,70 @@ async def test_discovery_broken(
' "command_topic": "test_topic" }' ' "command_topic": "test_topic" }'
) )
await help_test_discovery_broken( 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( async def test_entity_device_info_with_connection(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT text device registry integration.""" """Test MQTT text device registry integration."""
await help_test_entity_device_info_with_connection( await help_test_entity_device_info_with_connection(
hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, text.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_with_identifier( async def test_entity_device_info_with_identifier(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT text device registry integration.""" """Test MQTT text device registry integration."""
await help_test_entity_device_info_with_identifier( await help_test_entity_device_info_with_identifier(
hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, text.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_update( async def test_entity_device_info_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry update.""" """Test device registry update."""
await help_test_entity_device_info_update( await help_test_entity_device_info_update(
hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, text.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_remove( async def test_entity_device_info_remove(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry remove.""" """Test device registry remove."""
await help_test_entity_device_info_remove( await help_test_entity_device_info_remove(
hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, text.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_subscriptions( async def test_entity_id_update_subscriptions(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT subscriptions are managed when entity_id is updated.""" """Test MQTT subscriptions are managed when entity_id is updated."""
await help_test_entity_id_update_subscriptions( await help_test_entity_id_update_subscriptions(
hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, text.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_discovery_update( async def test_entity_id_update_discovery_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT discovery update when entity_id is updated.""" """Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update( await help_test_entity_id_update_discovery_update(
hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, text.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_debug_info_message( async def test_entity_debug_info_message(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT debug info.""" """Test MQTT debug info."""
await help_test_entity_debug_info_message( await help_test_entity_debug_info_message(
hass, mqtt_mock_entry_no_yaml_config, 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( async def test_publishing_with_custom_encoding(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
service: str, service: str,
topic: str, topic: str,
@ -691,7 +689,7 @@ async def test_publishing_with_custom_encoding(
await help_test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
domain, domain,
config, config,
@ -721,7 +719,7 @@ async def test_reloadable(
) )
async def test_encoding_subscribable_topics( async def test_encoding_subscribable_topics(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
topic: str, topic: str,
value: str, value: str,
attribute: str | None, attribute: str | None,
@ -730,7 +728,7 @@ async def test_encoding_subscribable_topics(
"""Test handling of incoming encoded payload.""" """Test handling of incoming encoded payload."""
await help_test_encoding_subscribable_topics( await help_test_encoding_subscribable_topics(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
text.DOMAIN, text.DOMAIN,
DEFAULT_CONFIG[mqtt.DOMAIN][text.DOMAIN], DEFAULT_CONFIG[mqtt.DOMAIN][text.DOMAIN],
topic, topic,
@ -742,21 +740,21 @@ async def test_encoding_subscribable_topics(
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_setup_manual_entity_from_yaml( async def test_setup_manual_entity_from_yaml(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
platform = text.DOMAIN platform = text.DOMAIN
assert hass.states.get(f"{platform}.test") assert hass.states.get(f"{platform}.test")
async def test_unload_entry( async def test_unload_entry(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = text.DOMAIN domain = text.DOMAIN
config = DEFAULT_CONFIG config = DEFAULT_CONFIG
await help_test_unload_config_entry_with_platform( await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_no_yaml_config, domain, config hass, mqtt_mock_entry, domain, config
) )

View File

@ -26,10 +26,10 @@ def no_platforms():
@pytest.fixture(autouse=True) @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.""" """Initialize components."""
mock_component(hass, "group") 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: async def test_if_fires_on_topic_match(hass: HomeAssistant, calls) -> None:

View File

@ -81,12 +81,12 @@ def update_platform_only():
], ],
) )
async def test_run_update_setup( async def test_run_update_setup(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test that it fetches the given payload.""" """Test that it fetches the given payload."""
installed_version_topic = "test/installed-version" installed_version_topic = "test/installed-version"
latest_version_topic = "test/latest-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, installed_version_topic, "1.9.0")
async_fire_mqtt_message(hass, latest_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( async def test_run_update_setup_float(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test that it fetches the given payload when the version is parsable as a number.""" """Test that it fetches the given payload when the version is parsable as a number."""
installed_version_topic = "test/installed-version" installed_version_topic = "test/installed-version"
latest_version_topic = "test/latest-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, installed_version_topic, "1.9")
async_fire_mqtt_message(hass, latest_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( async def test_value_template(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test that it fetches the given payload with a template.""" """Test that it fetches the given payload with a template."""
installed_version_topic = "test/installed-version" installed_version_topic = "test/installed-version"
latest_version_topic = "test/latest-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, installed_version_topic, '{"installed":"1.9.0"}')
async_fire_mqtt_message(hass, latest_version_topic, '{"latest":"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( async def test_value_template_float(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test that it fetches the given payload with a template when the version is parsable as a number.""" """Test that it fetches the given payload with a template when the version is parsable as a number."""
installed_version_topic = "test/installed-version" installed_version_topic = "test/installed-version"
latest_version_topic = "test/latest-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, installed_version_topic, '{"installed":"1.9"}')
async_fire_mqtt_message(hass, latest_version_topic, '{"latest":"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( async def test_empty_json_state_message(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test an empty JSON payload.""" """Test an empty JSON payload."""
state_topic = "test/state-topic" state_topic = "test/state-topic"
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
async_fire_mqtt_message(hass, state_topic, "{}") async_fire_mqtt_message(hass, state_topic, "{}")
@ -300,11 +300,11 @@ async def test_empty_json_state_message(
], ],
) )
async def test_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: ) -> None:
"""Test whether it fetches data from a JSON payload.""" """Test whether it fetches data from a JSON payload."""
state_topic = "test/state-topic" state_topic = "test/state-topic"
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
async_fire_mqtt_message( async_fire_mqtt_message(
hass, hass,
@ -358,11 +358,11 @@ async def test_json_state_message(
], ],
) )
async def test_json_state_message_with_template( async def test_json_state_message_with_template(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test whether it fetches data from a JSON payload with template.""" """Test whether it fetches data from a JSON payload with template."""
state_topic = "test/state-topic" 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"}') 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( async def test_run_install_service(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test that install service works.""" """Test that install service works."""
installed_version_topic = "test/installed-version" installed_version_topic = "test/installed-version"
latest_version_topic = "test/latest-version" latest_version_topic = "test/latest-version"
command_topic = "test/install-command" 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, installed_version_topic, "1.9.0")
async_fire_mqtt_message(hass, latest_version_topic, "2.0.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]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_availability_when_connection_lost( async def test_availability_when_connection_lost(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability after MQTT disconnection.""" """Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost( await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_no_yaml_config, update.DOMAIN hass, mqtt_mock_entry, update.DOMAIN
) )
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_availability_without_topic( async def test_availability_without_topic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability without defined availability topic.""" """Test availability without defined availability topic."""
await help_test_availability_without_topic( await help_test_availability_without_topic(
hass, mqtt_mock_entry_no_yaml_config, update.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, update.DOMAIN, DEFAULT_CONFIG
) )
async def test_default_availability_payload( async def test_default_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by default payload with defined topic.""" """Test availability by default payload with defined topic."""
await help_test_default_availability_payload( await help_test_default_availability_payload(
hass, mqtt_mock_entry_no_yaml_config, update.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, update.DOMAIN, DEFAULT_CONFIG
) )
async def test_custom_availability_payload( async def test_custom_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test availability by custom payload with defined topic.""" """Test availability by custom payload with defined topic."""
await help_test_custom_availability_payload( await help_test_custom_availability_payload(
hass, mqtt_mock_entry_no_yaml_config, update.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, update.DOMAIN, DEFAULT_CONFIG
) )
async def test_setting_attribute_via_mqtt_json_message( 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: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message( await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_no_yaml_config, update.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, update.DOMAIN, DEFAULT_CONFIG
) )
async def test_setting_attribute_with_template( async def test_setting_attribute_with_template(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test the setting of attribute via MQTT with JSON payload.""" """Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template( await help_test_setting_attribute_with_template(
hass, mqtt_mock_entry_no_yaml_config, update.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, update.DOMAIN, DEFAULT_CONFIG
) )
async def test_update_with_json_attrs_not_dict( async def test_update_with_json_attrs_not_dict(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_not_dict( await help_test_update_with_json_attrs_not_dict(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
update.DOMAIN, update.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -500,13 +500,13 @@ async def test_update_with_json_attrs_not_dict(
async def test_update_with_json_attrs_bad_json( async def test_update_with_json_attrs_bad_json(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes get extracted from a JSON result.""" """Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_json( await help_test_update_with_json_attrs_bad_json(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
update.DOMAIN, update.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -515,13 +515,13 @@ async def test_update_with_json_attrs_bad_json(
async def test_discovery_update_attr( async def test_discovery_update_attr(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered MQTTAttributes.""" """Test update of discovered MQTTAttributes."""
await help_test_discovery_update_attr( await help_test_discovery_update_attr(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
update.DOMAIN, update.DOMAIN,
DEFAULT_CONFIG, DEFAULT_CONFIG,
@ -552,27 +552,27 @@ async def test_discovery_update_attr(
], ],
) )
async def test_unique_id( async def test_unique_id(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test unique id option only creates one update per unique_id.""" """Test unique id option only creates one update per unique_id."""
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( async def test_discovery_removal_update(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test removal of discovered update.""" """Test removal of discovered update."""
data = json.dumps(DEFAULT_CONFIG[mqtt.DOMAIN][update.DOMAIN]) data = json.dumps(DEFAULT_CONFIG[mqtt.DOMAIN][update.DOMAIN])
await help_test_discovery_removal( 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( async def test_discovery_update_update(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered update.""" """Test update of discovered update."""
@ -588,13 +588,13 @@ async def test_discovery_update_update(
} }
await help_test_discovery_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( async def test_discovery_update_unchanged_update(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test update of discovered update.""" """Test update of discovered update."""
@ -604,7 +604,7 @@ async def test_discovery_update_unchanged_update(
) as discovery_update: ) as discovery_update:
await help_test_discovery_update_unchanged( await help_test_discovery_update_unchanged(
hass, hass,
mqtt_mock_entry_no_yaml_config, mqtt_mock_entry,
caplog, caplog,
update.DOMAIN, update.DOMAIN,
data1, data1,
@ -615,7 +615,7 @@ async def test_discovery_update_unchanged_update(
@pytest.mark.no_fail_on_log_exception @pytest.mark.no_fail_on_log_exception
async def test_discovery_broken( async def test_discovery_broken(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test handling of bad discovery message.""" """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" }' data2 = '{ "name": "Milk", "state_topic": "installed-topic", "latest_version_topic": "latest-topic" }'
await help_test_discovery_broken( 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( async def test_entity_device_info_with_connection(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT update device registry integration.""" """Test MQTT update device registry integration."""
await help_test_entity_device_info_with_connection( await help_test_entity_device_info_with_connection(
hass, mqtt_mock_entry_no_yaml_config, update.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, update.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_with_identifier( async def test_entity_device_info_with_identifier(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT update device registry integration.""" """Test MQTT update device registry integration."""
await help_test_entity_device_info_with_identifier( await help_test_entity_device_info_with_identifier(
hass, mqtt_mock_entry_no_yaml_config, update.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, update.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_update( async def test_entity_device_info_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry update.""" """Test device registry update."""
await help_test_entity_device_info_update( await help_test_entity_device_info_update(
hass, mqtt_mock_entry_no_yaml_config, update.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, update.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_device_info_remove( async def test_entity_device_info_remove(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test device registry remove.""" """Test device registry remove."""
await help_test_entity_device_info_remove( await help_test_entity_device_info_remove(
hass, mqtt_mock_entry_no_yaml_config, update.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, update.DOMAIN, DEFAULT_CONFIG
) )
async def test_entity_id_update_discovery_update( async def test_entity_id_update_discovery_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test MQTT discovery update when entity_id is updated.""" """Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update( await help_test_entity_id_update_discovery_update(
hass, mqtt_mock_entry_no_yaml_config, update.DOMAIN, DEFAULT_CONFIG hass, mqtt_mock_entry, update.DOMAIN, DEFAULT_CONFIG
) )
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_setup_manual_entity_from_yaml( async def test_setup_manual_entity_from_yaml(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None: ) -> None:
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
await mqtt_mock_entry_no_yaml_config() await mqtt_mock_entry()
platform = update.DOMAIN platform = update.DOMAIN
assert hass.states.get(f"{platform}.test") assert hass.states.get(f"{platform}.test")
async def test_unload_entry( async def test_unload_entry(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = update.DOMAIN domain = update.DOMAIN
config = DEFAULT_CONFIG config = DEFAULT_CONFIG
await help_test_unload_config_entry_with_platform( await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_no_yaml_config, domain, config hass, mqtt_mock_entry, domain, config
) )

View File

@ -906,11 +906,11 @@ async def mqtt_mock(
mock_hass_config: None, mock_hass_config: None,
mqtt_client_mock: MqttMockPahoClient, mqtt_client_mock: MqttMockPahoClient,
mqtt_config_entry_data: dict[str, Any] | None, mqtt_config_entry_data: dict[str, Any] | None,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
) -> AsyncGenerator[MqttMockHAClient, None]: ) -> AsyncGenerator[MqttMockHAClient, None]:
"""Fixture to mock MQTT component.""" """Fixture to mock MQTT component."""
with patch("homeassistant.components.mqtt.PLATFORMS", []): with patch("homeassistant.components.mqtt.PLATFORMS", []):
return await mqtt_mock_entry_no_yaml_config() return await mqtt_mock_entry()
@asynccontextmanager @asynccontextmanager
@ -1043,12 +1043,12 @@ def mock_hass_config_yaml(
@pytest.fixture @pytest.fixture
async def mqtt_mock_entry_no_yaml_config( async def mqtt_mock_entry(
hass: HomeAssistant, hass: HomeAssistant,
mqtt_client_mock: MqttMockPahoClient, mqtt_client_mock: MqttMockPahoClient,
mqtt_config_entry_data: dict[str, Any] | None, mqtt_config_entry_data: dict[str, Any] | None,
) -> AsyncGenerator[MqttMockHAClientGenerator, 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( async def _async_setup_config_entry(
hass: HomeAssistant, entry: ConfigEntry hass: HomeAssistant, entry: ConfigEntry
@ -1068,30 +1068,6 @@ async def mqtt_mock_entry_no_yaml_config(
yield _setup_mqtt_entry 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) @pytest.fixture(autouse=True)
def mock_network() -> Generator[None, None, None]: def mock_network() -> Generator[None, None, None]:
"""Mock network.""" """Mock network."""