mirror of
https://github.com/home-assistant/core.git
synced 2025-08-01 03:35:09 +02:00
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:
@@ -41,7 +41,7 @@ from homeassistant.const import (
|
||||
STATE_UNKNOWN,
|
||||
Platform,
|
||||
)
|
||||
import homeassistant.core as ha
|
||||
from homeassistant.core import HomeAssistant, State
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .test_common import (
|
||||
@@ -126,7 +126,7 @@ def light_platform_only():
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_setup_fails(hass, caplog, test_config):
|
||||
async def test_setup_fails(hass: HomeAssistant, caplog, test_config) -> None:
|
||||
"""Test that setup fails with missing required configuration items."""
|
||||
assert not await async_setup_component(
|
||||
hass,
|
||||
@@ -136,7 +136,7 @@ async def test_setup_fails(hass, caplog, test_config):
|
||||
assert "Invalid config for [mqtt]" in caplog.text
|
||||
|
||||
|
||||
async def test_rgb_light(hass, mqtt_mock_entry_with_yaml_config):
|
||||
async def test_rgb_light(hass: HomeAssistant, mqtt_mock_entry_with_yaml_config) -> None:
|
||||
"""Test RGB light flags brightness support."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@@ -167,7 +167,9 @@ async def test_rgb_light(hass, mqtt_mock_entry_with_yaml_config):
|
||||
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == expected_features
|
||||
|
||||
|
||||
async def test_state_change_via_topic(hass, mqtt_mock_entry_with_yaml_config):
|
||||
async def test_state_change_via_topic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
|
||||
) -> None:
|
||||
"""Test state change via topic."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@@ -221,8 +223,8 @@ async def test_state_change_via_topic(hass, mqtt_mock_entry_with_yaml_config):
|
||||
|
||||
|
||||
async def test_state_brightness_color_effect_temp_change_via_topic(
|
||||
hass, mqtt_mock_entry_with_yaml_config
|
||||
):
|
||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
|
||||
) -> None:
|
||||
"""Test state, bri, color, effect, color temp change."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@@ -332,10 +334,10 @@ async def test_state_brightness_color_effect_temp_change_via_topic(
|
||||
|
||||
|
||||
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 of command in optimistic mode."""
|
||||
fake_state = ha.State(
|
||||
fake_state = State(
|
||||
"light.test",
|
||||
"on",
|
||||
{
|
||||
@@ -474,8 +476,8 @@ async def test_sending_mqtt_commands_and_optimistic(
|
||||
|
||||
|
||||
async def test_sending_mqtt_commands_non_optimistic_brightness_template(
|
||||
hass, mqtt_mock_entry_with_yaml_config
|
||||
):
|
||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
|
||||
) -> None:
|
||||
"""Test the sending of command in optimistic mode."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@@ -596,7 +598,7 @@ async def test_sending_mqtt_commands_non_optimistic_brightness_template(
|
||||
state = hass.states.get("light.test")
|
||||
|
||||
|
||||
async def test_effect(hass, mqtt_mock_entry_with_yaml_config):
|
||||
async def test_effect(hass: HomeAssistant, mqtt_mock_entry_with_yaml_config) -> None:
|
||||
"""Test effect sent over MQTT in optimistic mode."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@@ -649,7 +651,7 @@ async def test_effect(hass, mqtt_mock_entry_with_yaml_config):
|
||||
assert state.attributes.get("effect") == "colorloop"
|
||||
|
||||
|
||||
async def test_flash(hass, mqtt_mock_entry_with_yaml_config):
|
||||
async def test_flash(hass: HomeAssistant, mqtt_mock_entry_with_yaml_config) -> None:
|
||||
"""Test flash sent over MQTT in optimistic mode."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@@ -698,7 +700,9 @@ async def test_flash(hass, mqtt_mock_entry_with_yaml_config):
|
||||
assert state.state == STATE_ON
|
||||
|
||||
|
||||
async def test_transition(hass, mqtt_mock_entry_with_yaml_config):
|
||||
async def test_transition(
|
||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
|
||||
) -> None:
|
||||
"""Test for transition time being sent when included."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@@ -740,7 +744,9 @@ async def test_transition(hass, mqtt_mock_entry_with_yaml_config):
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
|
||||
async def test_invalid_values(hass, mqtt_mock_entry_with_yaml_config):
|
||||
async def test_invalid_values(
|
||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
|
||||
) -> None:
|
||||
"""Test that invalid values are ignored."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@@ -836,29 +842,35 @@ async def test_invalid_values(hass, mqtt_mock_entry_with_yaml_config):
|
||||
|
||||
|
||||
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, light.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, light.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, light.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, light.DOMAIN, DEFAULT_CONFIG
|
||||
@@ -866,8 +878,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, light.DOMAIN, DEFAULT_CONFIG
|
||||
@@ -875,8 +887,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,
|
||||
@@ -887,7 +899,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, light.DOMAIN, DEFAULT_CONFIG
|
||||
@@ -895,8 +909,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,
|
||||
@@ -908,8 +922,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,
|
||||
@@ -920,7 +934,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,
|
||||
@@ -931,7 +947,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 light per unique_id."""
|
||||
config = {
|
||||
mqtt.DOMAIN: {
|
||||
@@ -962,7 +978,9 @@ async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config):
|
||||
)
|
||||
|
||||
|
||||
async def test_discovery_removal(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
||||
async def test_discovery_removal(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config, caplog
|
||||
) -> None:
|
||||
"""Test removal of discovered mqtt_json lights."""
|
||||
data = (
|
||||
'{ "name": "test",'
|
||||
@@ -976,7 +994,9 @@ async def test_discovery_removal(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
||||
)
|
||||
|
||||
|
||||
async def test_discovery_update_light(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
||||
async def test_discovery_update_light(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config, caplog
|
||||
) -> None:
|
||||
"""Test update of discovered light."""
|
||||
config1 = {
|
||||
"name": "Beer",
|
||||
@@ -1000,8 +1020,8 @@ async def test_discovery_update_light(hass, mqtt_mock_entry_no_yaml_config, capl
|
||||
|
||||
|
||||
async def test_discovery_update_unchanged_light(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog
|
||||
):
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config, caplog
|
||||
) -> None:
|
||||
"""Test update of discovered light."""
|
||||
data1 = (
|
||||
'{ "name": "Beer",'
|
||||
@@ -1025,7 +1045,9 @@ async def test_discovery_update_unchanged_light(
|
||||
|
||||
|
||||
@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 = (
|
||||
@@ -1041,49 +1063,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 light device registry integration."""
|
||||
await help_test_entity_device_info_with_connection(
|
||||
hass, mqtt_mock_entry_no_yaml_config, light.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 light device registry integration."""
|
||||
await help_test_entity_device_info_with_identifier(
|
||||
hass, mqtt_mock_entry_no_yaml_config, light.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, light.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, light.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, light.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, light.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."""
|
||||
config = {
|
||||
mqtt.DOMAIN: {
|
||||
@@ -1106,7 +1142,9 @@ async def test_entity_debug_info_message(hass, mqtt_mock_entry_no_yaml_config):
|
||||
)
|
||||
|
||||
|
||||
async def test_max_mireds(hass, mqtt_mock_entry_with_yaml_config):
|
||||
async def test_max_mireds(
|
||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
|
||||
) -> None:
|
||||
"""Test setting min_mireds and max_mireds."""
|
||||
config = {
|
||||
light.DOMAIN: {
|
||||
@@ -1153,7 +1191,7 @@ async def test_max_mireds(hass, mqtt_mock_entry_with_yaml_config):
|
||||
],
|
||||
)
|
||||
async def test_publishing_with_custom_encoding(
|
||||
hass,
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_with_yaml_config,
|
||||
caplog,
|
||||
service,
|
||||
@@ -1163,7 +1201,7 @@ async def test_publishing_with_custom_encoding(
|
||||
template,
|
||||
tpl_par,
|
||||
tpl_output,
|
||||
):
|
||||
) -> None:
|
||||
"""Test publishing MQTT payload with different encoding."""
|
||||
domain = light.DOMAIN
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
@@ -1186,7 +1224,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 = light.DOMAIN
|
||||
config = DEFAULT_CONFIG
|
||||
@@ -1202,7 +1242,7 @@ 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,
|
||||
@@ -1210,7 +1250,7 @@ async def test_encoding_subscribable_topics(
|
||||
attribute,
|
||||
attribute_value,
|
||||
init_payload,
|
||||
):
|
||||
) -> None:
|
||||
"""Test handling of incoming encoded payload."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][light.DOMAIN])
|
||||
config["state_template"] = "{{ value }}"
|
||||
@@ -1228,14 +1268,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 = light.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 = light.DOMAIN
|
||||
config = DEFAULT_CONFIG
|
||||
|
Reference in New Issue
Block a user