Add hass and None return type on MQTT platform tests (#87713)

Add hass and `None` return type on MQTT tests
This commit is contained in:
Jan Bouwhuis 2023-02-08 18:08:03 +01:00 committed by GitHub
parent ba85fdcd61
commit 1a414f1433
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 2673 additions and 1483 deletions

View file

@ -80,8 +80,8 @@ def lock_platform_only():
],
)
async def test_controlling_state_via_topic(
hass, mqtt_mock_entry_with_yaml_config, payload, lock_state
):
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config, payload, lock_state
) -> None:
"""Test the controlling state via topic."""
assert await async_setup_component(
hass,
@ -126,8 +126,8 @@ async def test_controlling_state_via_topic(
],
)
async def test_controlling_non_default_state_via_topic(
hass, mqtt_mock_entry_with_yaml_config, payload, lock_state
):
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config, payload, lock_state
) -> None:
"""Test the controlling state via topic."""
assert await async_setup_component(
hass,
@ -171,8 +171,8 @@ async def test_controlling_non_default_state_via_topic(
],
)
async def test_controlling_state_via_topic_and_json_message(
hass, mqtt_mock_entry_with_yaml_config, payload, lock_state
):
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config, payload, lock_state
) -> None:
"""Test the controlling state via topic and JSON message."""
assert await async_setup_component(
hass,
@ -216,8 +216,8 @@ async def test_controlling_state_via_topic_and_json_message(
],
)
async def test_controlling_non_default_state_via_topic_and_json_message(
hass, mqtt_mock_entry_with_yaml_config, payload, lock_state
):
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config, payload, lock_state
) -> None:
"""Test the controlling state via topic and JSON message."""
assert await async_setup_component(
hass,
@ -252,8 +252,8 @@ async def test_controlling_non_default_state_via_topic_and_json_message(
async def test_sending_mqtt_commands_and_optimistic(
hass, mqtt_mock_entry_with_yaml_config
):
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test optimistic mode without state topic."""
assert await async_setup_component(
hass,
@ -300,8 +300,8 @@ async def test_sending_mqtt_commands_and_optimistic(
async def test_sending_mqtt_commands_with_template(
hass, mqtt_mock_entry_with_yaml_config
):
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test sending commands with template."""
assert await async_setup_component(
hass,
@ -361,8 +361,8 @@ async def test_sending_mqtt_commands_with_template(
async def test_sending_mqtt_commands_and_explicit_optimistic(
hass, mqtt_mock_entry_with_yaml_config
):
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test optimistic mode without state topic."""
assert await async_setup_component(
hass,
@ -411,8 +411,8 @@ async def test_sending_mqtt_commands_and_explicit_optimistic(
async def test_sending_mqtt_commands_support_open_and_optimistic(
hass, mqtt_mock_entry_with_yaml_config
):
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test open function of the lock without state topic."""
assert await async_setup_component(
hass,
@ -471,8 +471,8 @@ async def test_sending_mqtt_commands_support_open_and_optimistic(
async def test_sending_mqtt_commands_support_open_and_explicit_optimistic(
hass, mqtt_mock_entry_with_yaml_config
):
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test open function of the lock without state topic."""
assert await async_setup_component(
hass,
@ -639,29 +639,35 @@ async def test_sending_mqtt_commands_pessimistic(
async def test_availability_when_connection_lost(
hass, mqtt_mock_entry_with_yaml_config
):
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost(
hass, mqtt_mock_entry_with_yaml_config, lock.DOMAIN, DEFAULT_CONFIG
)
async def test_availability_without_topic(hass, mqtt_mock_entry_with_yaml_config):
async def test_availability_without_topic(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test availability without defined availability topic."""
await help_test_availability_without_topic(
hass, mqtt_mock_entry_with_yaml_config, lock.DOMAIN, DEFAULT_CONFIG
)
async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_config):
async def test_default_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test availability by default payload with defined topic."""
await help_test_default_availability_payload(
hass, mqtt_mock_entry_with_yaml_config, lock.DOMAIN, DEFAULT_CONFIG
)
async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_config):
async def test_custom_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test availability by custom payload with defined topic."""
await help_test_custom_availability_payload(
hass, mqtt_mock_entry_with_yaml_config, lock.DOMAIN, DEFAULT_CONFIG
@ -669,8 +675,8 @@ async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_confi
async def test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_with_yaml_config
):
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_with_yaml_config, lock.DOMAIN, DEFAULT_CONFIG
@ -678,8 +684,8 @@ async def test_setting_attribute_via_mqtt_json_message(
async def test_setting_blocked_attribute_via_mqtt_json_message(
hass, mqtt_mock_entry_no_yaml_config
):
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config
) -> None:
"""Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_blocked_attribute_via_mqtt_json_message(
hass,
@ -690,7 +696,9 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
)
async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_config):
async def test_setting_attribute_with_template(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template(
hass, mqtt_mock_entry_with_yaml_config, lock.DOMAIN, DEFAULT_CONFIG
@ -698,8 +706,8 @@ async def test_setting_attribute_with_template(hass, mqtt_mock_entry_with_yaml_c
async def test_update_with_json_attrs_not_dict(
hass, mqtt_mock_entry_with_yaml_config, caplog
):
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config, caplog
) -> None:
"""Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_not_dict(
hass,
@ -711,8 +719,8 @@ async def test_update_with_json_attrs_not_dict(
async def test_update_with_json_attrs_bad_json(
hass, mqtt_mock_entry_with_yaml_config, caplog
):
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config, caplog
) -> None:
"""Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_json(
hass,
@ -723,14 +731,16 @@ async def test_update_with_json_attrs_bad_json(
)
async def test_discovery_update_attr(hass, mqtt_mock_entry_no_yaml_config, caplog):
async def test_discovery_update_attr(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config, caplog
) -> None:
"""Test update of discovered MQTTAttributes."""
await help_test_discovery_update_attr(
hass, mqtt_mock_entry_no_yaml_config, caplog, lock.DOMAIN, DEFAULT_CONFIG
)
async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config):
async def test_unique_id(hass: HomeAssistant, mqtt_mock_entry_with_yaml_config) -> None:
"""Test unique id option only creates one lock per unique_id."""
config = {
mqtt.DOMAIN: {
@ -755,7 +765,9 @@ async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config):
)
async def test_discovery_removal_lock(hass, mqtt_mock_entry_no_yaml_config, caplog):
async def test_discovery_removal_lock(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config, caplog
) -> None:
"""Test removal of discovered lock."""
data = '{ "name": "test",' ' "command_topic": "test_topic" }'
await help_test_discovery_removal(
@ -763,7 +775,9 @@ async def test_discovery_removal_lock(hass, mqtt_mock_entry_no_yaml_config, capl
)
async def test_discovery_update_lock(hass, mqtt_mock_entry_no_yaml_config, caplog):
async def test_discovery_update_lock(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config, caplog
) -> None:
"""Test update of discovered lock."""
config1 = {
"name": "Beer",
@ -783,8 +797,8 @@ async def test_discovery_update_lock(hass, mqtt_mock_entry_no_yaml_config, caplo
async def test_discovery_update_unchanged_lock(
hass, mqtt_mock_entry_no_yaml_config, caplog
):
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config, caplog
) -> None:
"""Test update of discovered lock."""
data1 = (
'{ "name": "Beer",'
@ -805,7 +819,9 @@ async def test_discovery_update_unchanged_lock(
@pytest.mark.no_fail_on_log_exception
async def test_discovery_broken(hass, mqtt_mock_entry_no_yaml_config, caplog):
async def test_discovery_broken(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config, caplog
) -> None:
"""Test handling of bad discovery message."""
data1 = '{ "name": "Beer" }'
data2 = '{ "name": "Milk",' ' "command_topic": "test_topic" }'
@ -814,49 +830,63 @@ async def test_discovery_broken(hass, mqtt_mock_entry_no_yaml_config, caplog):
)
async def test_entity_device_info_with_connection(hass, mqtt_mock_entry_no_yaml_config):
async def test_entity_device_info_with_connection(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config
) -> None:
"""Test MQTT lock device registry integration."""
await help_test_entity_device_info_with_connection(
hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG
)
async def test_entity_device_info_with_identifier(hass, mqtt_mock_entry_no_yaml_config):
async def test_entity_device_info_with_identifier(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config
) -> None:
"""Test MQTT lock device registry integration."""
await help_test_entity_device_info_with_identifier(
hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG
)
async def test_entity_device_info_update(hass, mqtt_mock_entry_no_yaml_config):
async def test_entity_device_info_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config
) -> None:
"""Test device registry update."""
await help_test_entity_device_info_update(
hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG
)
async def test_entity_device_info_remove(hass, mqtt_mock_entry_no_yaml_config):
async def test_entity_device_info_remove(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config
) -> None:
"""Test device registry remove."""
await help_test_entity_device_info_remove(
hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG
)
async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_config):
async def test_entity_id_update_subscriptions(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test MQTT subscriptions are managed when entity_id is updated."""
await help_test_entity_id_update_subscriptions(
hass, mqtt_mock_entry_with_yaml_config, lock.DOMAIN, DEFAULT_CONFIG
)
async def test_entity_id_update_discovery_update(hass, mqtt_mock_entry_no_yaml_config):
async def test_entity_id_update_discovery_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config
) -> None:
"""Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update(
hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG
)
async def test_entity_debug_info_message(hass, mqtt_mock_entry_no_yaml_config):
async def test_entity_debug_info_message(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config
) -> None:
"""Test MQTT debug info."""
await help_test_entity_debug_info_message(
hass,
@ -881,7 +911,7 @@ async def test_entity_debug_info_message(hass, mqtt_mock_entry_no_yaml_config):
],
)
async def test_publishing_with_custom_encoding(
hass,
hass: HomeAssistant,
mqtt_mock_entry_with_yaml_config,
caplog,
service,
@ -889,7 +919,7 @@ async def test_publishing_with_custom_encoding(
parameters,
payload,
template,
):
) -> None:
"""Test publishing MQTT payload with different encoding."""
domain = lock.DOMAIN
config = DEFAULT_CONFIG
@ -908,7 +938,9 @@ async def test_publishing_with_custom_encoding(
)
async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path):
async def test_reloadable(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config, caplog, tmp_path
) -> None:
"""Test reloading the MQTT platform."""
domain = lock.DOMAIN
config = DEFAULT_CONFIG
@ -924,14 +956,14 @@ async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_pa
],
)
async def test_encoding_subscribable_topics(
hass,
hass: HomeAssistant,
mqtt_mock_entry_with_yaml_config,
caplog,
topic,
value,
attribute,
attribute_value,
):
) -> None:
"""Test handling of incoming encoded payload."""
await help_test_encoding_subscribable_topics(
hass,
@ -946,14 +978,18 @@ async def test_encoding_subscribable_topics(
)
async def test_setup_manual_entity_from_yaml(hass, caplog, tmp_path):
async def test_setup_manual_entity_from_yaml(
hass: HomeAssistant, caplog, tmp_path
) -> None:
"""Test setup manual configured MQTT entity."""
platform = lock.DOMAIN
await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
assert hass.states.get(f"{platform}.test")
async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path):
async def test_unload_entry(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config, tmp_path
) -> None:
"""Test unloading the config entry."""
domain = lock.DOMAIN
config = DEFAULT_CONFIG