Add type hints to integration tests (part 22) (#88234)

This commit is contained in:
epenet
2023-02-16 14:08:03 +01:00
committed by GitHub
parent 567c7f4f99
commit 88cfbf6a34
50 changed files with 1269 additions and 559 deletions

View File

@@ -9,10 +9,12 @@ from hatasmota.utils import (
get_topic_tele_state,
get_topic_tele_will,
)
import pytest
from homeassistant.components.light import LightEntityFeature
from homeassistant.components.tasmota.const import DEFAULT_PREFIX
from homeassistant.const import ATTR_ASSUMED_STATE, STATE_OFF, STATE_ON, Platform
from homeassistant.core import HomeAssistant
from .test_common import (
DEFAULT_CONFIG,
@@ -29,9 +31,12 @@ from .test_common import (
from tests.common import async_fire_mqtt_message
from tests.components.light import common
from tests.typing import MqttMockHAClient, MqttMockPahoClient
async def test_attributes_on_off(hass, mqtt_mock, setup_tasmota):
async def test_attributes_on_off(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
) -> None:
"""Test state update via MQTT."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["rl"][0] = 1
@@ -57,7 +62,9 @@ async def test_attributes_on_off(hass, mqtt_mock, setup_tasmota):
assert state.attributes.get("color_mode") == "onoff"
async def test_attributes_dimmer_tuya(hass, mqtt_mock, setup_tasmota):
async def test_attributes_dimmer_tuya(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
) -> None:
"""Test state update via MQTT."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["rl"][0] = 2
@@ -84,7 +91,9 @@ async def test_attributes_dimmer_tuya(hass, mqtt_mock, setup_tasmota):
assert state.attributes.get("color_mode") == "brightness"
async def test_attributes_dimmer(hass, mqtt_mock, setup_tasmota):
async def test_attributes_dimmer(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
) -> None:
"""Test state update via MQTT."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["rl"][0] = 2
@@ -110,7 +119,9 @@ async def test_attributes_dimmer(hass, mqtt_mock, setup_tasmota):
assert state.attributes.get("color_mode") == "brightness"
async def test_attributes_ct(hass, mqtt_mock, setup_tasmota):
async def test_attributes_ct(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
) -> None:
"""Test state update via MQTT."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["rl"][0] = 2
@@ -136,7 +147,9 @@ async def test_attributes_ct(hass, mqtt_mock, setup_tasmota):
assert state.attributes.get("color_mode") == "color_temp"
async def test_attributes_ct_reduced(hass, mqtt_mock, setup_tasmota):
async def test_attributes_ct_reduced(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
) -> None:
"""Test state update via MQTT."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["rl"][0] = 2
@@ -163,7 +176,9 @@ async def test_attributes_ct_reduced(hass, mqtt_mock, setup_tasmota):
assert state.attributes.get("color_mode") == "color_temp"
async def test_attributes_rgb(hass, mqtt_mock, setup_tasmota):
async def test_attributes_rgb(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
) -> None:
"""Test state update via MQTT."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["rl"][0] = 2
@@ -198,7 +213,9 @@ async def test_attributes_rgb(hass, mqtt_mock, setup_tasmota):
assert state.attributes.get("color_mode") == "hs"
async def test_attributes_rgbw(hass, mqtt_mock, setup_tasmota):
async def test_attributes_rgbw(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
) -> None:
"""Test state update via MQTT."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["rl"][0] = 2
@@ -233,7 +250,9 @@ async def test_attributes_rgbw(hass, mqtt_mock, setup_tasmota):
assert state.attributes.get("color_mode") == "hs"
async def test_attributes_rgbww(hass, mqtt_mock, setup_tasmota):
async def test_attributes_rgbww(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
) -> None:
"""Test state update via MQTT."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["rl"][0] = 2
@@ -268,7 +287,9 @@ async def test_attributes_rgbww(hass, mqtt_mock, setup_tasmota):
assert state.attributes.get("color_mode") == "color_temp"
async def test_attributes_rgbww_reduced(hass, mqtt_mock, setup_tasmota):
async def test_attributes_rgbww_reduced(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
) -> None:
"""Test state update via MQTT."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["rl"][0] = 2
@@ -304,7 +325,9 @@ async def test_attributes_rgbww_reduced(hass, mqtt_mock, setup_tasmota):
assert state.attributes.get("color_mode") == "color_temp"
async def test_controlling_state_via_mqtt_on_off(hass, mqtt_mock, setup_tasmota):
async def test_controlling_state_via_mqtt_on_off(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
) -> None:
"""Test state update via MQTT."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["rl"][0] = 1
@@ -353,7 +376,9 @@ async def test_controlling_state_via_mqtt_on_off(hass, mqtt_mock, setup_tasmota)
assert "color_mode" not in state.attributes
async def test_controlling_state_via_mqtt_ct(hass, mqtt_mock, setup_tasmota):
async def test_controlling_state_via_mqtt_ct(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
) -> None:
"""Test state update via MQTT."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["rl"][0] = 2
@@ -416,7 +441,9 @@ async def test_controlling_state_via_mqtt_ct(hass, mqtt_mock, setup_tasmota):
assert state.attributes.get("color_mode") == "color_temp"
async def test_controlling_state_via_mqtt_rgbw(hass, mqtt_mock, setup_tasmota):
async def test_controlling_state_via_mqtt_rgbw(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
) -> None:
"""Test state update via MQTT."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["rl"][0] = 2
@@ -515,7 +542,9 @@ async def test_controlling_state_via_mqtt_rgbw(hass, mqtt_mock, setup_tasmota):
assert state.state == STATE_OFF
async def test_controlling_state_via_mqtt_rgbww(hass, mqtt_mock, setup_tasmota):
async def test_controlling_state_via_mqtt_rgbww(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
) -> None:
"""Test state update via MQTT."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["rl"][0] = 2
@@ -614,7 +643,9 @@ async def test_controlling_state_via_mqtt_rgbww(hass, mqtt_mock, setup_tasmota):
assert state.state == STATE_OFF
async def test_controlling_state_via_mqtt_rgbww_tuya(hass, mqtt_mock, setup_tasmota):
async def test_controlling_state_via_mqtt_rgbww_tuya(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
) -> None:
"""Test state update via MQTT."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["rl"][0] = 2
@@ -723,7 +754,9 @@ async def test_controlling_state_via_mqtt_rgbww_tuya(hass, mqtt_mock, setup_tasm
assert state.state == STATE_OFF
async def test_sending_mqtt_commands_on_off(hass, mqtt_mock, setup_tasmota):
async def test_sending_mqtt_commands_on_off(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
) -> None:
"""Test the sending MQTT commands."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["rl"][0] = 1
@@ -764,7 +797,9 @@ async def test_sending_mqtt_commands_on_off(hass, mqtt_mock, setup_tasmota):
mqtt_mock.async_publish.reset_mock()
async def test_sending_mqtt_commands_rgbww_tuya(hass, mqtt_mock, setup_tasmota):
async def test_sending_mqtt_commands_rgbww_tuya(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
) -> None:
"""Test the sending MQTT commands."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["rl"][0] = 2
@@ -812,7 +847,9 @@ async def test_sending_mqtt_commands_rgbww_tuya(hass, mqtt_mock, setup_tasmota):
)
async def test_sending_mqtt_commands_rgbw_legacy(hass, mqtt_mock, setup_tasmota):
async def test_sending_mqtt_commands_rgbw_legacy(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
) -> None:
"""Test the sending MQTT commands."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["sw"] = "9.4.0.3" # RGBW support was added in 9.4.0.4
@@ -910,7 +947,9 @@ async def test_sending_mqtt_commands_rgbw_legacy(hass, mqtt_mock, setup_tasmota)
mqtt_mock.async_publish.reset_mock()
async def test_sending_mqtt_commands_rgbw(hass, mqtt_mock, setup_tasmota):
async def test_sending_mqtt_commands_rgbw(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
) -> None:
"""Test the sending MQTT commands."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["rl"][0] = 2
@@ -1007,7 +1046,9 @@ async def test_sending_mqtt_commands_rgbw(hass, mqtt_mock, setup_tasmota):
mqtt_mock.async_publish.reset_mock()
async def test_sending_mqtt_commands_rgbww(hass, mqtt_mock, setup_tasmota):
async def test_sending_mqtt_commands_rgbww(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
) -> None:
"""Test the sending MQTT commands."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["rl"][0] = 2
@@ -1082,7 +1123,9 @@ async def test_sending_mqtt_commands_rgbww(hass, mqtt_mock, setup_tasmota):
mqtt_mock.async_publish.reset_mock()
async def test_sending_mqtt_commands_power_unlinked(hass, mqtt_mock, setup_tasmota):
async def test_sending_mqtt_commands_power_unlinked(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
) -> None:
"""Test the sending MQTT commands to a light with unlinked dimlevel and power."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["rl"][0] = 2
@@ -1134,7 +1177,9 @@ async def test_sending_mqtt_commands_power_unlinked(hass, mqtt_mock, setup_tasmo
mqtt_mock.async_publish.reset_mock()
async def test_transition(hass, mqtt_mock, setup_tasmota):
async def test_transition(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
) -> None:
"""Test transition commands."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["rl"][0] = 2
@@ -1324,7 +1369,9 @@ async def test_transition(hass, mqtt_mock, setup_tasmota):
mqtt_mock.async_publish.reset_mock()
async def test_transition_fixed(hass, mqtt_mock, setup_tasmota):
async def test_transition_fixed(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
) -> None:
"""Test transition commands."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["rl"][0] = 2
@@ -1398,7 +1445,9 @@ async def test_transition_fixed(hass, mqtt_mock, setup_tasmota):
mqtt_mock.async_publish.reset_mock()
async def test_relay_as_light(hass, mqtt_mock, setup_tasmota):
async def test_relay_as_light(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
) -> None:
"""Test relay show up as light in light mode."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["rl"][0] = 1
@@ -1459,7 +1508,9 @@ async def _test_split_light(hass, mqtt_mock, config, num_lights, num_switches):
)
async def test_split_light(hass, mqtt_mock, setup_tasmota):
async def test_split_light(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
) -> None:
"""Test multi-channel light split to single-channel dimmers."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["rl"][0] = 2
@@ -1473,7 +1524,9 @@ async def test_split_light(hass, mqtt_mock, setup_tasmota):
await _test_split_light(hass, mqtt_mock, config, 5, 0)
async def test_split_light2(hass, mqtt_mock, setup_tasmota):
async def test_split_light2(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
) -> None:
"""Test multi-channel light split to single-channel dimmers."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["rl"][0] = 1
@@ -1531,7 +1584,9 @@ async def _test_unlinked_light(hass, mqtt_mock, config, num_switches):
)
async def test_unlinked_light(hass, mqtt_mock, setup_tasmota):
async def test_unlinked_light(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
) -> None:
"""Test rgbww light split to rgb+ww."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["rl"][0] = 2
@@ -1542,7 +1597,9 @@ async def test_unlinked_light(hass, mqtt_mock, setup_tasmota):
await _test_unlinked_light(hass, mqtt_mock, config, 0)
async def test_unlinked_light2(hass, mqtt_mock, setup_tasmota):
async def test_unlinked_light2(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
) -> None:
"""Test rgbww light split to rgb+ww."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["rl"][0] = 1
@@ -1556,8 +1613,11 @@ async def test_unlinked_light2(hass, mqtt_mock, setup_tasmota):
async def test_discovery_update_reconfigure_light(
hass, mqtt_mock, caplog, setup_tasmota
):
hass: HomeAssistant,
mqtt_mock: MqttMockHAClient,
caplog: pytest.LogCaptureFixture,
setup_tasmota,
) -> None:
"""Test reconfigure of discovered light."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["rl"][0] = 2
@@ -1587,8 +1647,11 @@ async def test_discovery_update_reconfigure_light(
async def test_availability_when_connection_lost(
hass, mqtt_client_mock, mqtt_mock, setup_tasmota
):
hass: HomeAssistant,
mqtt_client_mock: MqttMockPahoClient,
mqtt_mock: MqttMockHAClient,
setup_tasmota,
) -> None:
"""Test availability after MQTT disconnection."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["rl"][0] = 2
@@ -1598,7 +1661,9 @@ async def test_availability_when_connection_lost(
)
async def test_availability(hass, mqtt_mock, setup_tasmota):
async def test_availability(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
) -> None:
"""Test availability."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["rl"][0] = 2
@@ -1606,7 +1671,9 @@ async def test_availability(hass, mqtt_mock, setup_tasmota):
await help_test_availability(hass, mqtt_mock, Platform.LIGHT, config)
async def test_availability_discovery_update(hass, mqtt_mock, setup_tasmota):
async def test_availability_discovery_update(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
) -> None:
"""Test availability discovery update."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["rl"][0] = 2
@@ -1617,8 +1684,11 @@ async def test_availability_discovery_update(hass, mqtt_mock, setup_tasmota):
async def test_availability_poll_state(
hass, mqtt_client_mock, mqtt_mock, setup_tasmota
):
hass: HomeAssistant,
mqtt_client_mock: MqttMockPahoClient,
mqtt_mock: MqttMockHAClient,
setup_tasmota,
) -> None:
"""Test polling after MQTT connection (re)established."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["rl"][0] = 2
@@ -1629,7 +1699,12 @@ async def test_availability_poll_state(
)
async def test_discovery_removal_light(hass, mqtt_mock, caplog, setup_tasmota):
async def test_discovery_removal_light(
hass: HomeAssistant,
mqtt_mock: MqttMockHAClient,
caplog: pytest.LogCaptureFixture,
setup_tasmota,
) -> None:
"""Test removal of discovered light."""
config1 = copy.deepcopy(DEFAULT_CONFIG)
config1["rl"][0] = 2
@@ -1643,7 +1718,12 @@ async def test_discovery_removal_light(hass, mqtt_mock, caplog, setup_tasmota):
)
async def test_discovery_removal_relay_as_light(hass, mqtt_mock, caplog, setup_tasmota):
async def test_discovery_removal_relay_as_light(
hass: HomeAssistant,
mqtt_mock: MqttMockHAClient,
caplog: pytest.LogCaptureFixture,
setup_tasmota,
) -> None:
"""Test removal of discovered relay as light."""
config1 = copy.deepcopy(DEFAULT_CONFIG)
config1["rl"][0] = 1
@@ -1658,8 +1738,11 @@ async def test_discovery_removal_relay_as_light(hass, mqtt_mock, caplog, setup_t
async def test_discovery_removal_relay_as_light2(
hass, mqtt_mock, caplog, setup_tasmota
):
hass: HomeAssistant,
mqtt_mock: MqttMockHAClient,
caplog: pytest.LogCaptureFixture,
setup_tasmota,
) -> None:
"""Test removal of discovered relay as light."""
config1 = copy.deepcopy(DEFAULT_CONFIG)
config1["rl"][0] = 1
@@ -1673,7 +1756,12 @@ async def test_discovery_removal_relay_as_light2(
)
async def test_discovery_update_unchanged_light(hass, mqtt_mock, caplog, setup_tasmota):
async def test_discovery_update_unchanged_light(
hass: HomeAssistant,
mqtt_mock: MqttMockHAClient,
caplog: pytest.LogCaptureFixture,
setup_tasmota,
) -> None:
"""Test update of discovered light."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["rl"][0] = 2
@@ -1686,7 +1774,9 @@ async def test_discovery_update_unchanged_light(hass, mqtt_mock, caplog, setup_t
)
async def test_discovery_device_remove(hass, mqtt_mock, setup_tasmota):
async def test_discovery_device_remove(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
) -> None:
"""Test device registry remove."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["rl"][0] = 2
@@ -1697,7 +1787,9 @@ async def test_discovery_device_remove(hass, mqtt_mock, setup_tasmota):
)
async def test_discovery_device_remove_relay_as_light(hass, mqtt_mock, setup_tasmota):
async def test_discovery_device_remove_relay_as_light(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
) -> None:
"""Test device registry remove."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["rl"][0] = 1
@@ -1708,7 +1800,9 @@ async def test_discovery_device_remove_relay_as_light(hass, mqtt_mock, setup_tas
)
async def test_entity_id_update_subscriptions(hass, mqtt_mock, setup_tasmota):
async def test_entity_id_update_subscriptions(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
) -> None:
"""Test MQTT subscriptions are managed when entity_id is updated."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["rl"][0] = 2
@@ -1723,7 +1817,9 @@ async def test_entity_id_update_subscriptions(hass, mqtt_mock, setup_tasmota):
)
async def test_entity_id_update_discovery_update(hass, mqtt_mock, setup_tasmota):
async def test_entity_id_update_discovery_update(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
) -> None:
"""Test MQTT discovery update when entity_id is updated."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["rl"][0] = 2