Improve type hints in rainmachine tests (#123881)

This commit is contained in:
epenet 2024-08-14 12:52:09 +02:00 committed by GitHub
parent 6626c63bb5
commit d50bac3b3e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,5 +1,6 @@
"""Define test fixtures for RainMachine.""" """Define test fixtures for RainMachine."""
from collections.abc import AsyncGenerator
import json import json
from typing import Any from typing import Any
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
@ -8,19 +9,20 @@ import pytest
from homeassistant.components.rainmachine import DOMAIN from homeassistant.components.rainmachine import DOMAIN
from homeassistant.const import CONF_IP_ADDRESS, CONF_PASSWORD, CONF_PORT, CONF_SSL from homeassistant.const import CONF_IP_ADDRESS, CONF_PASSWORD, CONF_PORT, CONF_SSL
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from tests.common import MockConfigEntry, load_fixture from tests.common import MockConfigEntry, load_fixture
@pytest.fixture(name="client") @pytest.fixture(name="client")
def client_fixture(controller, controller_mac): def client_fixture(controller: AsyncMock, controller_mac: str) -> AsyncMock:
"""Define a regenmaschine client.""" """Define a regenmaschine client."""
return AsyncMock(load_local=AsyncMock(), controllers={controller_mac: controller}) return AsyncMock(load_local=AsyncMock(), controllers={controller_mac: controller})
@pytest.fixture(name="config") @pytest.fixture(name="config")
def config_fixture(hass): def config_fixture() -> dict[str, Any]:
"""Define a config entry data fixture.""" """Define a config entry data fixture."""
return { return {
CONF_IP_ADDRESS: "192.168.1.100", CONF_IP_ADDRESS: "192.168.1.100",
@ -31,7 +33,9 @@ def config_fixture(hass):
@pytest.fixture(name="config_entry") @pytest.fixture(name="config_entry")
def config_entry_fixture(hass, config, controller_mac): def config_entry_fixture(
hass: HomeAssistant, config: dict[str, Any], controller_mac: str
) -> MockConfigEntry:
"""Define a config entry fixture.""" """Define a config entry fixture."""
entry = MockConfigEntry( entry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,
@ -78,7 +82,7 @@ def controller_fixture(
@pytest.fixture(name="controller_mac") @pytest.fixture(name="controller_mac")
def controller_mac_fixture(): def controller_mac_fixture() -> str:
"""Define a controller MAC address.""" """Define a controller MAC address."""
return "aa:bb:cc:dd:ee:ff" return "aa:bb:cc:dd:ee:ff"
@ -145,7 +149,9 @@ def data_zones_fixture():
@pytest.fixture(name="setup_rainmachine") @pytest.fixture(name="setup_rainmachine")
async def setup_rainmachine_fixture(hass, client, config): async def setup_rainmachine_fixture(
hass: HomeAssistant, client: AsyncMock, config: dict[str, Any]
) -> AsyncGenerator[None]:
"""Define a fixture to set up RainMachine.""" """Define a fixture to set up RainMachine."""
with ( with (
patch("homeassistant.components.rainmachine.Client", return_value=client), patch("homeassistant.components.rainmachine.Client", return_value=client),