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

@@ -28,6 +28,7 @@ from homeassistant.components.climate import (
)
from homeassistant.components.mqtt.climate import MQTT_CLIMATE_ATTRIBUTES_BLOCKED
from homeassistant.const import ATTR_TEMPERATURE, Platform
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
from .test_common import (
@@ -100,7 +101,9 @@ def climate_platform_only():
yield
async def test_setup_params(hass, mqtt_mock_entry_with_yaml_config):
async def test_setup_params(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test the initial parameters."""
assert await async_setup_component(hass, mqtt.DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
@@ -117,7 +120,7 @@ async def test_setup_params(hass, mqtt_mock_entry_with_yaml_config):
assert state.attributes.get("max_humidity") == DEFAULT_MAX_HUMIDITY
async def test_preset_none_in_preset_modes(hass, caplog):
async def test_preset_none_in_preset_modes(hass: HomeAssistant, caplog) -> None:
"""Test the preset mode payload reset configuration."""
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][climate.DOMAIN])
config["preset_modes"].append("none")
@@ -139,7 +142,9 @@ async def test_preset_none_in_preset_modes(hass, caplog):
("hold_mode_state_template", "{{ value_json }}"),
],
)
async def test_preset_modes_deprecation_guard(hass, caplog, parameter, config_value):
async def test_preset_modes_deprecation_guard(
hass: HomeAssistant, caplog, parameter, config_value
) -> None:
"""Test the configuration for invalid legacy parameters."""
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][climate.DOMAIN])
config[parameter] = config_value
@@ -149,7 +154,9 @@ async def test_preset_modes_deprecation_guard(hass, caplog, parameter, config_va
assert f"[{parameter}] is an invalid option for [mqtt]. Check: mqtt->mqtt->climate->0->{parameter}"
async def test_supported_features(hass, mqtt_mock_entry_with_yaml_config):
async def test_supported_features(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test the supported_features."""
assert await async_setup_component(hass, mqtt.DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
@@ -169,7 +176,9 @@ async def test_supported_features(hass, mqtt_mock_entry_with_yaml_config):
assert state.attributes.get("supported_features") == support
async def test_get_hvac_modes(hass, mqtt_mock_entry_with_yaml_config):
async def test_get_hvac_modes(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test that the operation list returns the correct modes."""
assert await async_setup_component(hass, mqtt.DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
@@ -188,8 +197,8 @@ async def test_get_hvac_modes(hass, mqtt_mock_entry_with_yaml_config):
async def test_set_operation_bad_attr_and_state(
hass, mqtt_mock_entry_with_yaml_config, caplog
):
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config, caplog
) -> None:
"""Test setting operation mode without required attribute.
Also check the state.
@@ -210,7 +219,9 @@ async def test_set_operation_bad_attr_and_state(
assert state.state == "off"
async def test_set_operation(hass, mqtt_mock_entry_with_yaml_config):
async def test_set_operation(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test setting of new operation mode."""
assert await async_setup_component(hass, mqtt.DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
@@ -225,7 +236,9 @@ async def test_set_operation(hass, mqtt_mock_entry_with_yaml_config):
mqtt_mock.async_publish.assert_called_once_with("mode-topic", "cool", 0, False)
async def test_set_operation_pessimistic(hass, mqtt_mock_entry_with_yaml_config):
async def test_set_operation_pessimistic(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test setting operation mode in pessimistic mode."""
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
config["climate"]["mode_state_topic"] = "mode-state"
@@ -249,7 +262,9 @@ async def test_set_operation_pessimistic(hass, mqtt_mock_entry_with_yaml_config)
assert state.state == "cool"
async def test_set_operation_optimistic(hass, mqtt_mock_entry_with_yaml_config):
async def test_set_operation_optimistic(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test setting operation mode in optimistic mode."""
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
config["climate"]["mode_state_topic"] = "mode-state"
@@ -277,7 +292,9 @@ async def test_set_operation_optimistic(hass, mqtt_mock_entry_with_yaml_config):
# CONF_POWER_COMMAND_TOPIC, CONF_POWER_STATE_TOPIC and CONF_POWER_STATE_TEMPLATE are deprecated,
# support for CONF_POWER_STATE_TOPIC and CONF_POWER_STATE_TEMPLATE was already removed or never added
# support was deprecated with release 2023.2 and will be removed with release 2023.8
async def test_set_operation_with_power_command(hass, mqtt_mock_entry_with_yaml_config):
async def test_set_operation_with_power_command(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test setting of new operation mode with power command enabled."""
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
config["climate"]["power_command_topic"] = "power-command"
@@ -304,7 +321,9 @@ async def test_set_operation_with_power_command(hass, mqtt_mock_entry_with_yaml_
mqtt_mock.async_publish.reset_mock()
async def test_set_fan_mode_bad_attr(hass, mqtt_mock_entry_with_yaml_config, caplog):
async def test_set_fan_mode_bad_attr(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config, caplog
) -> None:
"""Test setting fan mode without required attribute."""
assert await async_setup_component(hass, mqtt.DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
@@ -321,7 +340,9 @@ async def test_set_fan_mode_bad_attr(hass, mqtt_mock_entry_with_yaml_config, cap
assert state.attributes.get("fan_mode") == "low"
async def test_set_fan_mode_pessimistic(hass, mqtt_mock_entry_with_yaml_config):
async def test_set_fan_mode_pessimistic(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test setting of new fan mode in pessimistic mode."""
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
config["climate"]["fan_mode_state_topic"] = "fan-state"
@@ -345,7 +366,9 @@ async def test_set_fan_mode_pessimistic(hass, mqtt_mock_entry_with_yaml_config):
assert state.attributes.get("fan_mode") == "high"
async def test_set_fan_mode_optimistic(hass, mqtt_mock_entry_with_yaml_config):
async def test_set_fan_mode_optimistic(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test setting of new fan mode in optimistic mode."""
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
config["climate"]["fan_mode_state_topic"] = "fan-state"
@@ -370,7 +393,9 @@ async def test_set_fan_mode_optimistic(hass, mqtt_mock_entry_with_yaml_config):
assert state.attributes.get("fan_mode") == "low"
async def test_set_fan_mode(hass, mqtt_mock_entry_with_yaml_config):
async def test_set_fan_mode(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test setting of new fan mode."""
assert await async_setup_component(hass, mqtt.DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
@@ -384,7 +409,9 @@ async def test_set_fan_mode(hass, mqtt_mock_entry_with_yaml_config):
assert state.attributes.get("fan_mode") == "high"
async def test_set_swing_mode_bad_attr(hass, mqtt_mock_entry_with_yaml_config, caplog):
async def test_set_swing_mode_bad_attr(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config, caplog
) -> None:
"""Test setting swing mode without required attribute."""
assert await async_setup_component(hass, mqtt.DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
@@ -401,7 +428,9 @@ async def test_set_swing_mode_bad_attr(hass, mqtt_mock_entry_with_yaml_config, c
assert state.attributes.get("swing_mode") == "off"
async def test_set_swing_pessimistic(hass, mqtt_mock_entry_with_yaml_config):
async def test_set_swing_pessimistic(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test setting swing mode in pessimistic mode."""
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
config["climate"]["swing_mode_state_topic"] = "swing-state"
@@ -425,7 +454,9 @@ async def test_set_swing_pessimistic(hass, mqtt_mock_entry_with_yaml_config):
assert state.attributes.get("swing_mode") == "on"
async def test_set_swing_optimistic(hass, mqtt_mock_entry_with_yaml_config):
async def test_set_swing_optimistic(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test setting swing mode in optimistic mode."""
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
config["climate"]["swing_mode_state_topic"] = "swing-state"
@@ -450,7 +481,7 @@ async def test_set_swing_optimistic(hass, mqtt_mock_entry_with_yaml_config):
assert state.attributes.get("swing_mode") == "off"
async def test_set_swing(hass, mqtt_mock_entry_with_yaml_config):
async def test_set_swing(hass: HomeAssistant, mqtt_mock_entry_with_yaml_config) -> None:
"""Test setting of new swing mode."""
assert await async_setup_component(hass, mqtt.DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
@@ -464,7 +495,9 @@ async def test_set_swing(hass, mqtt_mock_entry_with_yaml_config):
assert state.attributes.get("swing_mode") == "on"
async def test_set_target_temperature(hass, mqtt_mock_entry_with_yaml_config):
async def test_set_target_temperature(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test setting the target temperature."""
assert await async_setup_component(hass, mqtt.DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
@@ -501,7 +534,9 @@ async def test_set_target_temperature(hass, mqtt_mock_entry_with_yaml_config):
mqtt_mock.async_publish.reset_mock()
async def test_set_target_humidity(hass, mqtt_mock_entry_with_yaml_config):
async def test_set_target_humidity(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test setting the target humidity."""
assert await async_setup_component(hass, mqtt.DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
@@ -517,8 +552,8 @@ async def test_set_target_humidity(hass, mqtt_mock_entry_with_yaml_config):
async def test_set_target_temperature_pessimistic(
hass, mqtt_mock_entry_with_yaml_config
):
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test setting the target temperature."""
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
config["climate"]["temperature_state_topic"] = "temperature-state"
@@ -543,8 +578,8 @@ async def test_set_target_temperature_pessimistic(
async def test_set_target_temperature_optimistic(
hass, mqtt_mock_entry_with_yaml_config
):
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test setting the target temperature optimistic."""
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
config["climate"]["temperature_state_topic"] = "temperature-state"
@@ -569,7 +604,9 @@ async def test_set_target_temperature_optimistic(
assert state.attributes.get("temperature") == 18
async def test_set_target_temperature_low_high(hass, mqtt_mock_entry_with_yaml_config):
async def test_set_target_temperature_low_high(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test setting the low/high target temperature."""
assert await async_setup_component(hass, mqtt.DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
@@ -586,8 +623,8 @@ async def test_set_target_temperature_low_high(hass, mqtt_mock_entry_with_yaml_c
async def test_set_target_temperature_low_highpessimistic(
hass, mqtt_mock_entry_with_yaml_config
):
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test setting the low/high target temperature."""
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
config["climate"]["temperature_low_state_topic"] = "temperature-low-state"
@@ -626,8 +663,8 @@ async def test_set_target_temperature_low_highpessimistic(
async def test_set_target_temperature_low_high_optimistic(
hass, mqtt_mock_entry_with_yaml_config
):
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test setting the low/high target temperature optimistic."""
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
config["climate"]["optimistic"] = True
@@ -666,7 +703,9 @@ async def test_set_target_temperature_low_high_optimistic(
assert state.attributes.get("target_temp_high") == 25
async def test_set_target_humidity_optimistic(hass, mqtt_mock_entry_with_yaml_config):
async def test_set_target_humidity_optimistic(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test setting the target humidity optimistic."""
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
config["climate"]["target_humidity_state_topic"] = "humidity-state"
@@ -690,7 +729,9 @@ async def test_set_target_humidity_optimistic(hass, mqtt_mock_entry_with_yaml_co
assert state.attributes.get("humidity") == 53
async def test_set_target_humidity_pessimistic(hass, mqtt_mock_entry_with_yaml_config):
async def test_set_target_humidity_pessimistic(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test setting the target humidity."""
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
config["climate"]["target_humidity_state_topic"] = "humidity-state"
@@ -713,7 +754,9 @@ async def test_set_target_humidity_pessimistic(hass, mqtt_mock_entry_with_yaml_c
assert state.attributes.get("humidity") == 80
async def test_receive_mqtt_temperature(hass, mqtt_mock_entry_with_yaml_config):
async def test_receive_mqtt_temperature(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test getting the current temperature via MQTT."""
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
config["climate"]["current_temperature_topic"] = "current_temperature"
@@ -726,7 +769,9 @@ async def test_receive_mqtt_temperature(hass, mqtt_mock_entry_with_yaml_config):
assert state.attributes.get("current_temperature") == 47
async def test_receive_mqtt_humidity(hass, mqtt_mock_entry_with_yaml_config):
async def test_receive_mqtt_humidity(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test getting the current humidity via MQTT."""
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
config["climate"]["current_humidity_topic"] = "current_humidity"
@@ -739,7 +784,9 @@ async def test_receive_mqtt_humidity(hass, mqtt_mock_entry_with_yaml_config):
assert state.attributes.get("current_humidity") == 35
async def test_handle_target_humidity_received(hass, mqtt_mock_entry_with_yaml_config):
async def test_handle_target_humidity_received(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test setting the target humidity via MQTT."""
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
config["climate"]["target_humidity_state_topic"] = "humidity-state"
@@ -756,7 +803,9 @@ async def test_handle_target_humidity_received(hass, mqtt_mock_entry_with_yaml_c
assert state.attributes.get("humidity") == 65
async def test_handle_action_received(hass, mqtt_mock_entry_with_yaml_config):
async def test_handle_action_received(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test getting the action received via MQTT."""
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
config["climate"]["action_topic"] = "action"
@@ -780,8 +829,8 @@ async def test_handle_action_received(hass, mqtt_mock_entry_with_yaml_config):
async def test_set_preset_mode_optimistic(
hass, mqtt_mock_entry_with_yaml_config, caplog
):
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config, caplog
) -> None:
"""Test setting of the preset mode."""
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
assert await async_setup_component(hass, mqtt.DOMAIN, {mqtt.DOMAIN: config})
@@ -828,8 +877,8 @@ async def test_set_preset_mode_optimistic(
async def test_set_preset_mode_explicit_optimistic(
hass, mqtt_mock_entry_with_yaml_config, caplog
):
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config, caplog
) -> None:
"""Test setting of the preset mode."""
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
config["climate"]["optimistic"] = True
@@ -878,8 +927,8 @@ async def test_set_preset_mode_explicit_optimistic(
async def test_set_preset_mode_pessimistic(
hass, mqtt_mock_entry_with_yaml_config, caplog
):
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config, caplog
) -> None:
"""Test setting of the preset mode."""
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
config["climate"]["preset_mode_state_topic"] = "preset-mode-state"
@@ -924,7 +973,9 @@ async def test_set_preset_mode_pessimistic(
assert state.attributes.get("preset_mode") == "home"
async def test_set_aux_pessimistic(hass, mqtt_mock_entry_with_yaml_config):
async def test_set_aux_pessimistic(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test setting of the aux heating in pessimistic mode."""
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
config["climate"]["aux_state_topic"] = "aux-state"
@@ -952,7 +1003,7 @@ async def test_set_aux_pessimistic(hass, mqtt_mock_entry_with_yaml_config):
assert state.attributes.get("aux_heat") == "off"
async def test_set_aux(hass, mqtt_mock_entry_with_yaml_config):
async def test_set_aux(hass: HomeAssistant, mqtt_mock_entry_with_yaml_config) -> None:
"""Test setting of the aux heating."""
assert await async_setup_component(hass, mqtt.DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
@@ -973,29 +1024,35 @@ async def test_set_aux(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, climate.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, climate.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, climate.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, climate.DOMAIN, DEFAULT_CONFIG
@@ -1003,8 +1060,8 @@ async def test_custom_availability_payload(hass, mqtt_mock_entry_with_yaml_confi
async def test_get_target_temperature_low_high_with_templates(
hass, mqtt_mock_entry_with_yaml_config, caplog
):
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config, caplog
) -> None:
"""Test getting temperature high/low with templates."""
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
config["climate"]["temperature_low_state_topic"] = "temperature-state"
@@ -1040,7 +1097,9 @@ async def test_get_target_temperature_low_high_with_templates(
assert state.attributes.get("target_temp_high") == 1032
async def test_get_with_templates(hass, mqtt_mock_entry_with_yaml_config, caplog):
async def test_get_with_templates(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config, caplog
) -> None:
"""Test getting various attributes with templates."""
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
# By default, just unquote the JSON-strings
@@ -1157,7 +1216,9 @@ async def test_get_with_templates(hass, mqtt_mock_entry_with_yaml_config, caplog
assert state.attributes.get("hvac_action") == "cooling"
async def test_set_and_templates(hass, mqtt_mock_entry_with_yaml_config, caplog):
async def test_set_and_templates(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config, caplog
) -> None:
"""Test setting various attributes with templates."""
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
# Create simple templates
@@ -1245,7 +1306,9 @@ async def test_set_and_templates(hass, mqtt_mock_entry_with_yaml_config, caplog)
assert state.attributes.get("humidity") == 82
async def test_min_temp_custom(hass, mqtt_mock_entry_with_yaml_config):
async def test_min_temp_custom(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test a custom min temp."""
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
config["climate"]["min_temp"] = 26
@@ -1261,7 +1324,9 @@ async def test_min_temp_custom(hass, mqtt_mock_entry_with_yaml_config):
assert state.attributes.get("min_temp") == 26
async def test_max_temp_custom(hass, mqtt_mock_entry_with_yaml_config):
async def test_max_temp_custom(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test a custom max temp."""
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
config["climate"]["max_temp"] = 60
@@ -1277,7 +1342,9 @@ async def test_max_temp_custom(hass, mqtt_mock_entry_with_yaml_config):
assert max_temp == 60
async def test_min_humidity_custom(hass, mqtt_mock_entry_with_yaml_config):
async def test_min_humidity_custom(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test a custom min humidity."""
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
config["climate"]["min_humidity"] = 42
@@ -1293,7 +1360,9 @@ async def test_min_humidity_custom(hass, mqtt_mock_entry_with_yaml_config):
assert state.attributes.get("min_humidity") == 42
async def test_max_humidity_custom(hass, mqtt_mock_entry_with_yaml_config):
async def test_max_humidity_custom(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test a custom max humidity."""
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
config["climate"]["max_humidity"] = 58
@@ -1309,7 +1378,9 @@ async def test_max_humidity_custom(hass, mqtt_mock_entry_with_yaml_config):
assert max_humidity == 58
async def test_temp_step_custom(hass, mqtt_mock_entry_with_yaml_config):
async def test_temp_step_custom(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test a custom temp step."""
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
config["climate"]["temp_step"] = 0.01
@@ -1325,7 +1396,9 @@ async def test_temp_step_custom(hass, mqtt_mock_entry_with_yaml_config):
assert temp_step == 0.01
async def test_temperature_unit(hass, mqtt_mock_entry_with_yaml_config):
async def test_temperature_unit(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test that setting temperature unit converts temperature values."""
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
config["climate"]["temperature_unit"] = "F"
@@ -1342,8 +1415,8 @@ async def test_temperature_unit(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, climate.DOMAIN, DEFAULT_CONFIG
@@ -1351,8 +1424,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,
@@ -1363,7 +1436,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, climate.DOMAIN, DEFAULT_CONFIG
@@ -1371,8 +1446,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,
@@ -1384,8 +1459,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,
@@ -1396,7 +1471,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,
@@ -1407,7 +1484,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 climate per unique_id."""
config = {
mqtt.DOMAIN: {
@@ -1451,14 +1528,14 @@ async def test_unique_id(hass, mqtt_mock_entry_with_yaml_config):
],
)
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."""
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][climate.DOMAIN])
await help_test_encoding_subscribable_topics(
@@ -1474,7 +1551,9 @@ async def test_encoding_subscribable_topics(
)
async def test_discovery_removal_climate(hass, mqtt_mock_entry_no_yaml_config, caplog):
async def test_discovery_removal_climate(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config, caplog
) -> None:
"""Test removal of discovered climate."""
data = json.dumps(DEFAULT_CONFIG[mqtt.DOMAIN][climate.DOMAIN])
await help_test_discovery_removal(
@@ -1482,7 +1561,9 @@ async def test_discovery_removal_climate(hass, mqtt_mock_entry_no_yaml_config, c
)
async def test_discovery_update_climate(hass, mqtt_mock_entry_no_yaml_config, caplog):
async def test_discovery_update_climate(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config, caplog
) -> None:
"""Test update of discovered climate."""
config1 = {"name": "Beer"}
config2 = {"name": "Milk"}
@@ -1492,8 +1573,8 @@ async def test_discovery_update_climate(hass, mqtt_mock_entry_no_yaml_config, ca
async def test_discovery_update_unchanged_climate(
hass, mqtt_mock_entry_no_yaml_config, caplog
):
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config, caplog
) -> None:
"""Test update of discovered climate."""
data1 = '{ "name": "Beer" }'
with patch(
@@ -1510,7 +1591,9 @@ async def test_discovery_update_unchanged_climate(
@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", "power_command_topic": "test_topic#" }'
data2 = '{ "name": "Milk", "power_command_topic": "test_topic" }'
@@ -1519,35 +1602,45 @@ 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 climate device registry integration."""
await help_test_entity_device_info_with_connection(
hass, mqtt_mock_entry_no_yaml_config, climate.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 climate device registry integration."""
await help_test_entity_device_info_with_identifier(
hass, mqtt_mock_entry_no_yaml_config, climate.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, climate.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, climate.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."""
config = {
mqtt.DOMAIN: {
@@ -1567,14 +1660,18 @@ async def test_entity_id_update_subscriptions(hass, mqtt_mock_entry_with_yaml_co
)
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, climate.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: {
@@ -1597,7 +1694,9 @@ async def test_entity_debug_info_message(hass, mqtt_mock_entry_no_yaml_config):
)
async def test_precision_default(hass, mqtt_mock_entry_with_yaml_config):
async def test_precision_default(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test that setting precision to tenths works as intended."""
assert await async_setup_component(hass, mqtt.DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
@@ -1611,7 +1710,9 @@ async def test_precision_default(hass, mqtt_mock_entry_with_yaml_config):
mqtt_mock.async_publish.reset_mock()
async def test_precision_halves(hass, mqtt_mock_entry_with_yaml_config):
async def test_precision_halves(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test that setting precision to halves works as intended."""
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
config["climate"]["precision"] = 0.5
@@ -1627,7 +1728,9 @@ async def test_precision_halves(hass, mqtt_mock_entry_with_yaml_config):
mqtt_mock.async_publish.reset_mock()
async def test_precision_whole(hass, mqtt_mock_entry_with_yaml_config):
async def test_precision_whole(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
) -> None:
"""Test that setting precision to whole works as intended."""
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
config["climate"]["precision"] = 1.0
@@ -1727,7 +1830,7 @@ async def test_precision_whole(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,
@@ -1735,7 +1838,7 @@ async def test_publishing_with_custom_encoding(
parameters,
payload,
template,
):
) -> None:
"""Test publishing MQTT payload with different encoding."""
domain = climate.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG)
@@ -1801,7 +1904,9 @@ async def test_publishing_with_custom_encoding(
),
],
)
async def test_humidity_configuration_validity(hass, config, valid):
async def test_humidity_configuration_validity(
hass: HomeAssistant, config, valid
) -> None:
"""Test the validity of humidity configurations."""
assert (
await async_setup_component(
@@ -1813,7 +1918,9 @@ async def test_humidity_configuration_validity(hass, config, valid):
)
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 = climate.DOMAIN
config = DEFAULT_CONFIG
@@ -1822,14 +1929,16 @@ async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_pa
)
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 = climate.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 = climate.DOMAIN
config = DEFAULT_CONFIG