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

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