Add missing hass type hint in component tests (a) (#124059)

This commit is contained in:
epenet 2024-08-16 17:07:57 +02:00 committed by GitHub
parent 115c5d1704
commit 2cd4456762
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 39 additions and 15 deletions

View file

@ -4,6 +4,7 @@ from unittest.mock import AsyncMock, patch
from homeassistant.components.advantage_air.const import DOMAIN
from homeassistant.const import CONF_IP_ADDRESS, CONF_PORT
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry, load_json_object_fixture
@ -43,7 +44,7 @@ def patch_update(return_value=True, side_effect=None):
)
async def add_mock_config(hass):
async def add_mock_config(hass: HomeAssistant) -> MockConfigEntry:
"""Create a fake Advantage Air Config Entry."""
entry = MockConfigEntry(
domain=DOMAIN,

View file

@ -13,6 +13,7 @@ from airthings_ble import (
from homeassistant.components.airthings_ble.const import DOMAIN
from homeassistant.components.bluetooth.models import BluetoothServiceInfoBleak
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import CONNECTION_BLUETOOTH, DeviceRegistry
from tests.common import MockConfigEntry, MockEntity
@ -225,7 +226,7 @@ VOC_V3 = MockEntity(
)
def create_entry(hass):
def create_entry(hass: HomeAssistant) -> MockConfigEntry:
"""Create a config entry."""
entry = MockConfigEntry(
domain=DOMAIN,

View file

@ -27,11 +27,14 @@ from homeassistant.const import (
STATE_ALARM_DISARMED,
STATE_ALARM_TRIGGERED,
)
from homeassistant.core import HomeAssistant
from tests.common import MockEntity
async def async_alarm_disarm(hass, code=None, entity_id=ENTITY_MATCH_ALL):
async def async_alarm_disarm(
hass: HomeAssistant, code: str | None = None, entity_id: str = ENTITY_MATCH_ALL
) -> None:
"""Send the alarm the command for disarm."""
data = {}
if code:
@ -42,7 +45,9 @@ async def async_alarm_disarm(hass, code=None, entity_id=ENTITY_MATCH_ALL):
await hass.services.async_call(DOMAIN, SERVICE_ALARM_DISARM, data, blocking=True)
async def async_alarm_arm_home(hass, code=None, entity_id=ENTITY_MATCH_ALL):
async def async_alarm_arm_home(
hass: HomeAssistant, code: str | None = None, entity_id: str = ENTITY_MATCH_ALL
) -> None:
"""Send the alarm the command for disarm."""
data = {}
if code:
@ -53,7 +58,9 @@ async def async_alarm_arm_home(hass, code=None, entity_id=ENTITY_MATCH_ALL):
await hass.services.async_call(DOMAIN, SERVICE_ALARM_ARM_HOME, data, blocking=True)
async def async_alarm_arm_away(hass, code=None, entity_id=ENTITY_MATCH_ALL):
async def async_alarm_arm_away(
hass: HomeAssistant, code: str | None = None, entity_id: str = ENTITY_MATCH_ALL
) -> None:
"""Send the alarm the command for disarm."""
data = {}
if code:
@ -64,7 +71,9 @@ async def async_alarm_arm_away(hass, code=None, entity_id=ENTITY_MATCH_ALL):
await hass.services.async_call(DOMAIN, SERVICE_ALARM_ARM_AWAY, data, blocking=True)
async def async_alarm_arm_night(hass, code=None, entity_id=ENTITY_MATCH_ALL):
async def async_alarm_arm_night(
hass: HomeAssistant, code: str | None = None, entity_id: str = ENTITY_MATCH_ALL
) -> None:
"""Send the alarm the command for disarm."""
data = {}
if code:
@ -75,7 +84,9 @@ async def async_alarm_arm_night(hass, code=None, entity_id=ENTITY_MATCH_ALL):
await hass.services.async_call(DOMAIN, SERVICE_ALARM_ARM_NIGHT, data, blocking=True)
async def async_alarm_arm_vacation(hass, code=None, entity_id=ENTITY_MATCH_ALL):
async def async_alarm_arm_vacation(
hass: HomeAssistant, code: str | None = None, entity_id: str = ENTITY_MATCH_ALL
) -> None:
"""Send the alarm the command for vacation mode."""
data = {}
if code:
@ -88,7 +99,9 @@ async def async_alarm_arm_vacation(hass, code=None, entity_id=ENTITY_MATCH_ALL):
)
async def async_alarm_trigger(hass, code=None, entity_id=ENTITY_MATCH_ALL):
async def async_alarm_trigger(
hass: HomeAssistant, code: str | None = None, entity_id: str = ENTITY_MATCH_ALL
) -> None:
"""Send the alarm the command for disarm."""
data = {}
if code:
@ -99,7 +112,9 @@ async def async_alarm_trigger(hass, code=None, entity_id=ENTITY_MATCH_ALL):
await hass.services.async_call(DOMAIN, SERVICE_ALARM_TRIGGER, data, blocking=True)
async def async_alarm_arm_custom_bypass(hass, code=None, entity_id=ENTITY_MATCH_ALL):
async def async_alarm_arm_custom_bypass(
hass: HomeAssistant, code: str | None = None, entity_id: str = ENTITY_MATCH_ALL
) -> None:
"""Send the alarm the command for disarm."""
data = {}
if code:

View file

@ -3,8 +3,9 @@
from __future__ import annotations
from asyncio import AbstractEventLoop
from collections.abc import Callable
from collections.abc import Callable, Generator
from dataclasses import dataclass
from typing import Any
from unittest.mock import patch
import pytest
@ -41,7 +42,7 @@ class MockKafkaClient:
@pytest.fixture(name="mock_client")
def mock_client_fixture():
def mock_client_fixture() -> Generator[MockKafkaClient]:
"""Mock the apache kafka client."""
with (
patch(f"{PRODUCER_PATH}.start") as start,
@ -89,7 +90,7 @@ async def test_full_config(hass: HomeAssistant, mock_client: MockKafkaClient) ->
mock_client.start.assert_called_once()
async def _setup(hass, filter_config):
async def _setup(hass: HomeAssistant, filter_config: dict[str, Any]) -> None:
"""Shared set up for filtering tests."""
config = {apache_kafka.DOMAIN: {"filter": filter_config}}
config[apache_kafka.DOMAIN].update(MIN_CONFIG)
@ -98,7 +99,9 @@ async def _setup(hass, filter_config):
await hass.async_block_till_done()
async def _run_filter_tests(hass, tests, mock_client):
async def _run_filter_tests(
hass: HomeAssistant, tests: list[FilterTest], mock_client: MockKafkaClient
) -> None:
"""Run a series of filter tests on apache kafka."""
for test in tests:
hass.states.async_set(test.id, STATE_ON)

View file

@ -13,6 +13,7 @@ from homeassistant.auth.models import (
TOKEN_TYPE_LONG_LIVED_ACCESS_TOKEN,
TOKEN_TYPE_NORMAL,
Credentials,
RefreshToken,
)
from homeassistant.components import auth
from homeassistant.core import HomeAssistant
@ -37,7 +38,7 @@ def mock_credential():
)
async def async_setup_user_refresh_token(hass):
async def async_setup_user_refresh_token(hass: HomeAssistant) -> RefreshToken:
"""Create a testing user with a connected credential."""
user = await hass.auth.async_create_user("Test User")

View file

@ -1,6 +1,7 @@
"""Tests for the link user flow."""
from http import HTTPStatus
from typing import Any
from unittest.mock import patch
from homeassistant.core import HomeAssistant
@ -11,7 +12,9 @@ from tests.common import CLIENT_ID, CLIENT_REDIRECT_URI
from tests.typing import ClientSessionGenerator
async def async_get_code(hass, aiohttp_client):
async def async_get_code(
hass: HomeAssistant, aiohttp_client: ClientSessionGenerator
) -> dict[str, Any]:
"""Return authorization code for link user tests."""
config = [
{