mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 06:47:09 +00:00
Improve type hints in ambient_station tests (#119230)
This commit is contained in:
parent
c03f9d264e
commit
06c1c435d1
@ -1,24 +1,31 @@
|
|||||||
"""Define test fixtures for Ambient PWS."""
|
"""Define test fixtures for Ambient PWS."""
|
||||||
|
|
||||||
import json
|
from typing import Any
|
||||||
from unittest.mock import AsyncMock, Mock, patch
|
from unittest.mock import AsyncMock, Mock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from typing_extensions import Generator
|
||||||
|
|
||||||
from homeassistant.components.ambient_station.const import CONF_APP_KEY, DOMAIN
|
from homeassistant.components.ambient_station.const import CONF_APP_KEY, DOMAIN
|
||||||
from homeassistant.const import CONF_API_KEY
|
from homeassistant.const import CONF_API_KEY
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.util.json import JsonArrayType, JsonObjectType
|
||||||
|
|
||||||
from tests.common import MockConfigEntry, load_fixture
|
from tests.common import (
|
||||||
|
MockConfigEntry,
|
||||||
|
load_json_array_fixture,
|
||||||
|
load_json_object_fixture,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="api")
|
@pytest.fixture(name="api")
|
||||||
def api_fixture(hass, data_devices):
|
def api_fixture(data_devices: JsonArrayType) -> Mock:
|
||||||
"""Define a mock API object."""
|
"""Define a mock API object."""
|
||||||
return Mock(get_devices=AsyncMock(return_value=data_devices))
|
return Mock(get_devices=AsyncMock(return_value=data_devices))
|
||||||
|
|
||||||
|
|
||||||
@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_API_KEY: "12345abcde12345abcde",
|
CONF_API_KEY: "12345abcde12345abcde",
|
||||||
@ -27,7 +34,9 @@ def config_fixture(hass):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="config_entry")
|
@pytest.fixture(name="config_entry")
|
||||||
def config_entry_fixture(hass, config):
|
def config_entry_fixture(
|
||||||
|
hass: HomeAssistant, config: dict[str, Any]
|
||||||
|
) -> MockConfigEntry:
|
||||||
"""Define a config entry fixture."""
|
"""Define a config entry fixture."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
@ -39,19 +48,19 @@ def config_entry_fixture(hass, config):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="data_devices", scope="package")
|
@pytest.fixture(name="data_devices", scope="package")
|
||||||
def data_devices_fixture():
|
def data_devices_fixture() -> JsonArrayType:
|
||||||
"""Define devices data."""
|
"""Define devices data."""
|
||||||
return json.loads(load_fixture("devices.json", "ambient_station"))
|
return load_json_array_fixture("devices.json", "ambient_station")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="data_station", scope="package")
|
@pytest.fixture(name="data_station", scope="package")
|
||||||
def data_station_fixture():
|
def data_station_fixture() -> JsonObjectType:
|
||||||
"""Define station data."""
|
"""Define station data."""
|
||||||
return json.loads(load_fixture("station_data.json", "ambient_station"))
|
return load_json_object_fixture("station_data.json", "ambient_station")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="mock_aioambient")
|
@pytest.fixture(name="mock_aioambient")
|
||||||
async def mock_aioambient_fixture(api):
|
def mock_aioambient_fixture(api: Mock) -> Generator[None]:
|
||||||
"""Define a fixture to patch aioambient."""
|
"""Define a fixture to patch aioambient."""
|
||||||
with (
|
with (
|
||||||
patch(
|
patch(
|
||||||
@ -64,7 +73,9 @@ async def mock_aioambient_fixture(api):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="setup_config_entry")
|
@pytest.fixture(name="setup_config_entry")
|
||||||
async def setup_config_entry_fixture(hass, config_entry, mock_aioambient):
|
async def setup_config_entry_fixture(
|
||||||
|
hass: HomeAssistant, config_entry: MockConfigEntry, mock_aioambient: None
|
||||||
|
) -> None:
|
||||||
"""Define a fixture to set up ambient_station."""
|
"""Define a fixture to set up ambient_station."""
|
||||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user