Skip to content

Commit

Permalink
Add missing hass type hint in component tests (t) (#124274)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored Aug 20, 2024
1 parent 14775c8 commit 3dc83ef
Show file tree
Hide file tree
Showing 18 changed files with 186 additions and 126 deletions.
2 changes: 1 addition & 1 deletion tests/components/tasmota/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def disable_status_sensor(status_sensor_disabled):
yield


async def setup_tasmota_helper(hass):
async def setup_tasmota_helper(hass: HomeAssistant) -> None:
"""Set up Tasmota."""
hass.config.components.add("tasmota")

Expand Down
174 changes: 93 additions & 81 deletions tests/components/tasmota/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import copy
import json
from unittest.mock import ANY
from typing import Any
from unittest.mock import ANY, AsyncMock

from hatasmota.const import (
CONF_DEEP_SLEEP,
Expand All @@ -19,14 +20,15 @@
get_topic_tele_state,
get_topic_tele_will,
)
import pytest

from homeassistant.components.tasmota.const import DEFAULT_PREFIX, DOMAIN
from homeassistant.const import STATE_UNAVAILABLE
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr, entity_registry as er

from tests.common import async_fire_mqtt_message
from tests.typing import WebSocketGenerator
from tests.typing import MqttMockHAClient, MqttMockPahoClient, WebSocketGenerator

DEFAULT_CONFIG = {
"ip": "192.168.15.10",
Expand Down Expand Up @@ -125,14 +127,14 @@ async def remove_device(


async def help_test_availability_when_connection_lost(
hass,
mqtt_client_mock,
mqtt_mock,
domain,
config,
sensor_config=None,
object_id="tasmota_test",
):
hass: HomeAssistant,
mqtt_client_mock: MqttMockPahoClient,
mqtt_mock: MqttMockHAClient,
domain: str,
config: dict[str, Any],
sensor_config: dict[str, Any] | None = None,
object_id: str = "tasmota_test",
) -> None:
"""Test availability after MQTT disconnection.
This is a test helper for the TasmotaAvailability mixin.
Expand Down Expand Up @@ -191,14 +193,14 @@ async def help_test_availability_when_connection_lost(


async def help_test_deep_sleep_availability_when_connection_lost(
hass,
mqtt_client_mock,
mqtt_mock,
domain,
config,
sensor_config=None,
object_id="tasmota_test",
):
hass: HomeAssistant,
mqtt_client_mock: MqttMockPahoClient,
mqtt_mock: MqttMockHAClient,
domain: str,
config: dict[str, Any],
sensor_config: dict[str, Any] | None = None,
object_id: str = "tasmota_test",
) -> None:
"""Test availability after MQTT disconnection when deep sleep is enabled.
This is a test helper for the TasmotaAvailability mixin.
Expand Down Expand Up @@ -261,13 +263,13 @@ async def help_test_deep_sleep_availability_when_connection_lost(


async def help_test_availability(
hass,
mqtt_mock,
domain,
config,
sensor_config=None,
object_id="tasmota_test",
):
hass: HomeAssistant,
mqtt_mock: MqttMockHAClient,
domain: str,
config: dict[str, Any],
sensor_config: dict[str, Any] | None = None,
object_id: str = "tasmota_test",
) -> None:
"""Test availability.
This is a test helper for the TasmotaAvailability mixin.
Expand Down Expand Up @@ -309,13 +311,13 @@ async def help_test_availability(


async def help_test_deep_sleep_availability(
hass,
mqtt_mock,
domain,
config,
sensor_config=None,
object_id="tasmota_test",
):
hass: HomeAssistant,
mqtt_mock: MqttMockHAClient,
domain: str,
config: dict[str, Any],
sensor_config: dict[str, Any] | None = None,
object_id: str = "tasmota_test",
) -> None:
"""Test availability when deep sleep is enabled.
This is a test helper for the TasmotaAvailability mixin.
Expand Down Expand Up @@ -358,13 +360,13 @@ async def help_test_deep_sleep_availability(


async def help_test_availability_discovery_update(
hass,
mqtt_mock,
domain,
config,
sensor_config=None,
object_id="tasmota_test",
):
hass: HomeAssistant,
mqtt_mock: MqttMockHAClient,
domain: str,
config: dict[str, Any],
sensor_config: dict[str, Any] | None = None,
object_id: str = "tasmota_test",
) -> None:
"""Test update of discovered TasmotaAvailability.
This is a test helper for the TasmotaAvailability mixin.
Expand Down Expand Up @@ -434,15 +436,15 @@ async def help_test_availability_discovery_update(


async def help_test_availability_poll_state(
hass,
mqtt_client_mock,
mqtt_mock,
domain,
config,
poll_topic,
poll_payload,
sensor_config=None,
):
hass: HomeAssistant,
mqtt_client_mock: MqttMockPahoClient,
mqtt_mock: MqttMockHAClient,
domain: str,
config: dict[str, Any],
poll_topic: str,
poll_payload: str,
sensor_config: dict[str, Any] | None = None,
) -> None:
"""Test polling of state when device is available.
This is a test helper for the TasmotaAvailability mixin.
Expand Down Expand Up @@ -503,17 +505,17 @@ async def help_test_availability_poll_state(


async def help_test_discovery_removal(
hass,
mqtt_mock,
caplog,
domain,
config1,
config2,
sensor_config1=None,
sensor_config2=None,
object_id="tasmota_test",
name="Tasmota Test",
):
hass: HomeAssistant,
mqtt_mock: MqttMockHAClient,
caplog: pytest.LogCaptureFixture,
domain: str,
config1: dict[str, Any],
config2: dict[str, Any],
sensor_config1: dict[str, Any] | None = None,
sensor_config2: dict[str, Any] | None = None,
object_id: str = "tasmota_test",
name: str = "Tasmota Test",
) -> None:
"""Test removal of discovered entity."""
device_reg = dr.async_get(hass)
entity_reg = er.async_get(hass)
Expand Down Expand Up @@ -569,16 +571,16 @@ async def help_test_discovery_removal(


async def help_test_discovery_update_unchanged(
hass,
mqtt_mock,
caplog,
domain,
config,
discovery_update,
sensor_config=None,
object_id="tasmota_test",
name="Tasmota Test",
):
hass: HomeAssistant,
mqtt_mock: MqttMockHAClient,
caplog: pytest.LogCaptureFixture,
domain: str,
config: dict[str, Any],
discovery_update: AsyncMock,
sensor_config: dict[str, Any] | None = None,
object_id: str = "tasmota_test",
name: str = "Tasmota Test",
) -> None:
"""Test update of discovered component with and without changes.
This is a test helper for the MqttDiscoveryUpdate mixin.
Expand Down Expand Up @@ -623,8 +625,13 @@ async def help_test_discovery_update_unchanged(


async def help_test_discovery_device_remove(
hass, mqtt_mock, domain, unique_id, config, sensor_config=None
):
hass: HomeAssistant,
mqtt_mock: MqttMockHAClient,
domain: str,
unique_id: str,
config: dict[str, Any],
sensor_config: dict[str, Any] | None = None,
) -> None:
"""Test domain entity is removed when device is removed."""
device_reg = dr.async_get(hass)
entity_reg = er.async_get(hass)
Expand Down Expand Up @@ -659,14 +666,14 @@ async def help_test_discovery_device_remove(


async def help_test_entity_id_update_subscriptions(
hass,
mqtt_mock,
domain,
config,
topics=None,
sensor_config=None,
object_id="tasmota_test",
):
hass: HomeAssistant,
mqtt_mock: MqttMockHAClient,
domain: str,
config: dict[str, Any],
topics: list[str] | None = None,
sensor_config: dict[str, Any] | None = None,
object_id: str = "tasmota_test",
) -> None:
"""Test MQTT subscriptions are managed when entity_id is updated."""
entity_reg = er.async_get(hass)

Expand Down Expand Up @@ -711,8 +718,13 @@ async def help_test_entity_id_update_subscriptions(


async def help_test_entity_id_update_discovery_update(
hass, mqtt_mock, domain, config, sensor_config=None, object_id="tasmota_test"
):
hass: HomeAssistant,
mqtt_mock: MqttMockHAClient,
domain: str,
config: dict[str, Any],
sensor_config: dict[str, Any] | None = None,
object_id: str = "tasmota_test",
) -> None:
"""Test MQTT discovery update after entity_id is updated."""
entity_reg = er.async_get(hass)

Expand Down
5 changes: 4 additions & 1 deletion tests/components/tasmota/test_cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import copy
import json
from typing import Any
from unittest.mock import patch

from hatasmota.utils import (
Expand Down Expand Up @@ -464,7 +465,9 @@ async def test_controlling_state_via_mqtt_inverted(
assert state.attributes["current_position"] == 0


async def call_service(hass, entity_id, service, **kwargs):
async def call_service(
hass: HomeAssistant, entity_id: str, service: str, **kwargs: Any
) -> None:
"""Call a fan service."""
await hass.services.async_call(
cover.DOMAIN,
Expand Down
5 changes: 4 additions & 1 deletion tests/components/tasmota/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from unittest.mock import call

from homeassistant.components.tasmota.const import DEFAULT_PREFIX, DOMAIN
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr
from homeassistant.setup import async_setup_component
Expand Down Expand Up @@ -74,7 +75,9 @@ async def test_device_remove_non_tasmota_device(
"""Test removing a non Tasmota device through device registry."""
assert await async_setup_component(hass, "config", {})

async def async_remove_config_entry_device(hass, config_entry, device_entry):
async def async_remove_config_entry_device(
hass: HomeAssistant, config_entry: ConfigEntry, device_entry: dr.DeviceEntry
) -> bool:
return True

mock_integration(
Expand Down
16 changes: 14 additions & 2 deletions tests/components/tasmota/test_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import copy
import json
from typing import Any
from unittest.mock import patch

from hatasmota.const import CONF_MAC
Expand Down Expand Up @@ -1478,7 +1479,13 @@ async def test_relay_as_light(
assert state is not None


async def _test_split_light(hass, mqtt_mock, config, num_lights, num_switches):
async def _test_split_light(
hass: HomeAssistant,
mqtt_mock: MqttMockHAClient,
config: dict[str, Any],
num_lights: int,
num_switches: int,
) -> None:
"""Test multi-channel light split to single-channel dimmers."""
mac = config["mac"]

Expand Down Expand Up @@ -1553,7 +1560,12 @@ async def test_split_light2(
await _test_split_light(hass, mqtt_mock, config, 5, 2)


async def _test_unlinked_light(hass, mqtt_mock, config, num_switches):
async def _test_unlinked_light(
hass: HomeAssistant,
mqtt_mock: MqttMockHAClient,
config: dict[str, Any],
num_switches: int,
) -> None:
"""Test rgbww light split to rgb+ww."""
mac = config["mac"]
num_lights = 2
Expand Down
4 changes: 3 additions & 1 deletion tests/components/tellduslive/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
from tests.common import MockConfigEntry


def init_config_flow(hass, side_effect=None):
def init_config_flow(
hass: HomeAssistant, side_effect: type[Exception] | None = None
) -> config_flow.FlowHandler:
"""Init a configuration flow."""
flow = config_flow.FlowHandler()
flow.hass = hass
Expand Down
11 changes: 6 additions & 5 deletions tests/components/template/test_button.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""The tests for the Template button platform."""

import datetime as dt
from typing import Any

from freezegun.api import FrozenDateTimeFactory
import pytest
Expand Down Expand Up @@ -232,11 +233,11 @@ async def test_unique_id(hass: HomeAssistant) -> None:


def _verify(
hass,
expected_value,
attributes=None,
entity_id=_TEST_BUTTON,
):
hass: HomeAssistant,
expected_value: str,
attributes: dict[str, Any] | None = None,
entity_id: str = _TEST_BUTTON,
) -> None:
"""Verify button's state."""
attributes = attributes or {}
if CONF_FRIENDLY_NAME not in attributes:
Expand Down
Loading

0 comments on commit 3dc83ef

Please sign in to comment.