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
31 changed files with 2673 additions and 1483 deletions

View File

@ -17,6 +17,7 @@ from homeassistant.const import (
STATE_UNKNOWN,
Platform,
)
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
from .test_common import (
@ -78,7 +79,9 @@ async def async_turn_off(hass, entity_id=ENTITY_MATCH_ALL) -> None:
await hass.services.async_call(siren.DOMAIN, SERVICE_TURN_OFF, data, blocking=True)
async def test_controlling_state_via_topic(hass, mqtt_mock_entry_with_yaml_config):
async def test_controlling_state_via_topic(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test the controlling state via topic."""
assert await async_setup_component(
hass,
@ -114,8 +117,8 @@ async def test_controlling_state_via_topic(hass, mqtt_mock_entry_with_yaml_confi
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 the sending MQTT commands in optimistic mode."""
assert await async_setup_component(
hass,
@ -158,8 +161,8 @@ async def test_sending_mqtt_commands_and_optimistic(
async def test_controlling_state_via_topic_and_json_message(
hass, mqtt_mock_entry_with_yaml_config, caplog
):
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config, caplog
) -> None:
"""Test the controlling state via topic and JSON message."""
assert await async_setup_component(
hass,
@ -199,8 +202,8 @@ async def test_controlling_state_via_topic_and_json_message(
async def test_controlling_state_and_attributes_with_json_message_without_template(
hass, mqtt_mock_entry_with_yaml_config, caplog
):
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config, caplog
) -> None:
"""Test the controlling state via topic and JSON message without a value template."""
assert await async_setup_component(
hass,
@ -279,8 +282,8 @@ async def test_controlling_state_and_attributes_with_json_message_without_templa
async def test_filtering_not_supported_attributes_optimistic(
hass, mqtt_mock_entry_with_yaml_config
):
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test setting attributes with support flags optimistic."""
config = {
"command_topic": "command-topic",
@ -364,8 +367,8 @@ async def test_filtering_not_supported_attributes_optimistic(
async def test_filtering_not_supported_attributes_via_state(
hass, mqtt_mock_entry_with_yaml_config
):
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test setting attributes with support flags via state."""
config = {
"command_topic": "command-topic",
@ -443,22 +446,26 @@ async def test_filtering_not_supported_attributes_via_state(
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, siren.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, siren.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."""
config = {
mqtt.DOMAIN: {
@ -483,7 +490,9 @@ async def test_default_availability_payload(hass, mqtt_mock_entry_with_yaml_conf
)
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."""
config = {
mqtt.DOMAIN: {
@ -508,7 +517,9 @@ async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_confi
)
async def test_custom_state_payload(hass, mqtt_mock_entry_with_yaml_config):
async def test_custom_state_payload(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test the state payload."""
assert await async_setup_component(
hass,
@ -546,8 +557,8 @@ async def test_custom_state_payload(hass, mqtt_mock_entry_with_yaml_config):
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, siren.DOMAIN, DEFAULT_CONFIG
@ -555,15 +566,17 @@ 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, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG, {}
)
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, siren.DOMAIN, DEFAULT_CONFIG
@ -571,8 +584,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,
@ -584,8 +597,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,
@ -596,7 +609,9 @@ 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,
@ -607,7 +622,7 @@ async def test_discovery_update_attr(hass, mqtt_mock_entry_no_yaml_config, caplo
)
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 siren per unique_id."""
config = {
mqtt.DOMAIN: {
@ -632,7 +647,9 @@ async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config):
)
async def test_discovery_removal_siren(hass, mqtt_mock_entry_no_yaml_config, caplog):
async def test_discovery_removal_siren(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config, caplog
) -> None:
"""Test removal of discovered siren."""
data = (
'{ "name": "test",'
@ -645,8 +662,8 @@ async def test_discovery_removal_siren(hass, mqtt_mock_entry_no_yaml_config, cap
async def test_discovery_update_siren_topic_template(
hass, mqtt_mock_entry_no_yaml_config, caplog
):
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config, caplog
) -> None:
"""Test update of discovered siren."""
config1 = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][siren.DOMAIN])
config2 = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][siren.DOMAIN])
@ -682,8 +699,8 @@ async def test_discovery_update_siren_topic_template(
async def test_discovery_update_siren_template(
hass, mqtt_mock_entry_no_yaml_config, caplog
):
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config, caplog
) -> None:
"""Test update of discovered siren."""
config1 = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][siren.DOMAIN])
config2 = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][siren.DOMAIN])
@ -716,7 +733,9 @@ async def test_discovery_update_siren_template(
)
async def test_command_templates(hass, mqtt_mock_entry_with_yaml_config, caplog):
async def test_command_templates(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config, caplog
) -> None:
"""Test siren with command templates optimistic."""
config1 = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][siren.DOMAIN])
config1["name"] = "Beer"
@ -797,8 +816,8 @@ async def test_command_templates(hass, mqtt_mock_entry_with_yaml_config, caplog)
async def test_discovery_update_unchanged_siren(
hass, mqtt_mock_entry_no_yaml_config, caplog
):
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config, caplog
) -> None:
"""Test update of discovered siren."""
data1 = (
'{ "name": "Beer",'
@ -820,7 +839,9 @@ async def test_discovery_update_unchanged_siren(
@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 = (
@ -833,49 +854,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 siren device registry integration."""
await help_test_entity_device_info_with_connection(
hass, mqtt_mock_entry_no_yaml_config, siren.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 siren device registry integration."""
await help_test_entity_device_info_with_identifier(
hass, mqtt_mock_entry_no_yaml_config, siren.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, siren.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, siren.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, siren.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, siren.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,
@ -907,7 +942,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,
@ -915,7 +950,7 @@ async def test_publishing_with_custom_encoding(
parameters,
payload,
template,
):
) -> None:
"""Test publishing MQTT payload with command templates and different encoding."""
domain = siren.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG)
@ -935,7 +970,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 = siren.DOMAIN
config = DEFAULT_CONFIG
@ -951,14 +988,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,
@ -973,14 +1010,16 @@ async def test_encoding_subscribable_topics(
)
async def test_setup_manual_entity_from_yaml(hass):
async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None:
"""Test setup manual configured MQTT entity."""
platform = siren.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 = siren.DOMAIN
config = DEFAULT_CONFIG