mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 01:38:02 +00:00
Improve type hints in insteon tests (#121504)
This commit is contained in:
parent
1aa9588dcb
commit
3059bf0536
@ -1,7 +1,8 @@
|
||||
"""Test the Insteon Scenes APIs."""
|
||||
|
||||
import json
|
||||
from collections.abc import Generator
|
||||
import os
|
||||
from typing import Any
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
from pyinsteon.constants import ResponseStatus
|
||||
@ -11,21 +12,22 @@ import pytest
|
||||
from homeassistant.components.insteon.api import async_load_api, scenes
|
||||
from homeassistant.components.insteon.const import ID, TYPE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.util.json import JsonArrayType
|
||||
|
||||
from .mock_devices import MockDevices
|
||||
|
||||
from tests.common import load_fixture
|
||||
from tests.typing import WebSocketGenerator
|
||||
from tests.common import load_json_array_fixture
|
||||
from tests.typing import MockHAClientWebSocket, WebSocketGenerator
|
||||
|
||||
|
||||
@pytest.fixture(name="scene_data", scope="module")
|
||||
def aldb_data_fixture():
|
||||
def aldb_data_fixture() -> JsonArrayType:
|
||||
"""Load the controller state fixture data."""
|
||||
return json.loads(load_fixture("insteon/scene_data.json"))
|
||||
return load_json_array_fixture("insteon/scene_data.json")
|
||||
|
||||
|
||||
@pytest.fixture(name="remove_json")
|
||||
def remove_insteon_devices_json(hass):
|
||||
def remove_insteon_devices_json(hass: HomeAssistant) -> Generator[None]:
|
||||
"""Fixture to remove insteon_devices.json at the end of the test."""
|
||||
yield
|
||||
file = os.path.join(hass.config.config_dir, "insteon_devices.json")
|
||||
@ -33,7 +35,7 @@ def remove_insteon_devices_json(hass):
|
||||
os.remove(file)
|
||||
|
||||
|
||||
def _scene_to_array(scene):
|
||||
def _scene_to_array(scene: dict[str, Any]) -> list[dict[str, Any]]:
|
||||
"""Convert a scene object to a dictionary."""
|
||||
scene_list = []
|
||||
for device, links in scene["devices"].items():
|
||||
@ -47,7 +49,9 @@ def _scene_to_array(scene):
|
||||
return scene_list
|
||||
|
||||
|
||||
async def _setup(hass, hass_ws_client, scene_data):
|
||||
async def _setup(
|
||||
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, scene_data: JsonArrayType
|
||||
) -> tuple[MockHAClientWebSocket, MockDevices]:
|
||||
"""Set up tests."""
|
||||
ws_client = await hass_ws_client(hass)
|
||||
devices = MockDevices()
|
||||
@ -63,7 +67,7 @@ async def _setup(hass, hass_ws_client, scene_data):
|
||||
# This tests needs to be adjusted to remove lingering tasks
|
||||
@pytest.mark.parametrize("expected_lingering_tasks", [True])
|
||||
async def test_get_scenes(
|
||||
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, scene_data
|
||||
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, scene_data: JsonArrayType
|
||||
) -> None:
|
||||
"""Test getting all Insteon scenes."""
|
||||
ws_client, devices = await _setup(hass, hass_ws_client, scene_data)
|
||||
@ -79,7 +83,7 @@ async def test_get_scenes(
|
||||
# This tests needs to be adjusted to remove lingering tasks
|
||||
@pytest.mark.parametrize("expected_lingering_tasks", [True])
|
||||
async def test_get_scene(
|
||||
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, scene_data
|
||||
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, scene_data: JsonArrayType
|
||||
) -> None:
|
||||
"""Test getting an Insteon scene."""
|
||||
ws_client, devices = await _setup(hass, hass_ws_client, scene_data)
|
||||
@ -93,8 +97,11 @@ async def test_get_scene(
|
||||
|
||||
# This tests needs to be adjusted to remove lingering tasks
|
||||
@pytest.mark.parametrize("expected_lingering_tasks", [True])
|
||||
@pytest.mark.usefixtures("remove_json")
|
||||
async def test_save_scene(
|
||||
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, scene_data, remove_json
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
scene_data: JsonArrayType,
|
||||
) -> None:
|
||||
"""Test saving an Insteon scene."""
|
||||
ws_client, devices = await _setup(hass, hass_ws_client, scene_data)
|
||||
@ -125,8 +132,11 @@ async def test_save_scene(
|
||||
|
||||
# This tests needs to be adjusted to remove lingering tasks
|
||||
@pytest.mark.parametrize("expected_lingering_tasks", [True])
|
||||
@pytest.mark.usefixtures("remove_json")
|
||||
async def test_save_new_scene(
|
||||
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, scene_data, remove_json
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
scene_data: JsonArrayType,
|
||||
) -> None:
|
||||
"""Test saving a new Insteon scene."""
|
||||
ws_client, devices = await _setup(hass, hass_ws_client, scene_data)
|
||||
@ -157,8 +167,11 @@ async def test_save_new_scene(
|
||||
|
||||
# This tests needs to be adjusted to remove lingering tasks
|
||||
@pytest.mark.parametrize("expected_lingering_tasks", [True])
|
||||
@pytest.mark.usefixtures("remove_json")
|
||||
async def test_save_scene_error(
|
||||
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, scene_data, remove_json
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
scene_data: JsonArrayType,
|
||||
) -> None:
|
||||
"""Test saving an Insteon scene with error."""
|
||||
ws_client, devices = await _setup(hass, hass_ws_client, scene_data)
|
||||
@ -189,8 +202,11 @@ async def test_save_scene_error(
|
||||
|
||||
# This tests needs to be adjusted to remove lingering tasks
|
||||
@pytest.mark.parametrize("expected_lingering_tasks", [True])
|
||||
@pytest.mark.usefixtures("remove_json")
|
||||
async def test_delete_scene(
|
||||
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, scene_data, remove_json
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
scene_data: JsonArrayType,
|
||||
) -> None:
|
||||
"""Test delete an Insteon scene."""
|
||||
ws_client, devices = await _setup(hass, hass_ws_client, scene_data)
|
||||
|
Loading…
x
Reference in New Issue
Block a user