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

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