mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Add missing hass type hint in component tests (i) (#124216)
This commit is contained in:
parent
057f31132b
commit
f0af33bd2b
@ -30,7 +30,7 @@ from .conftest import get_aqualink_device, get_aqualink_system
|
|||||||
from tests.common import async_fire_time_changed
|
from tests.common import async_fire_time_changed
|
||||||
|
|
||||||
|
|
||||||
async def _ffwd_next_update_interval(hass):
|
async def _ffwd_next_update_interval(hass: HomeAssistant) -> None:
|
||||||
now = dt_util.utcnow()
|
now = dt_util.utcnow()
|
||||||
async_fire_time_changed(hass, now + UPDATE_INTERVAL)
|
async_fire_time_changed(hass, now + UPDATE_INTERVAL)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -6,19 +6,19 @@ components. Instead call the service directly.
|
|||||||
|
|
||||||
from homeassistant.components.image_processing import DOMAIN, SERVICE_SCAN
|
from homeassistant.components.image_processing import DOMAIN, SERVICE_SCAN
|
||||||
from homeassistant.const import ATTR_ENTITY_ID, ENTITY_MATCH_ALL
|
from homeassistant.const import ATTR_ENTITY_ID, ENTITY_MATCH_ALL
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.loader import bind_hass
|
from homeassistant.loader import bind_hass
|
||||||
|
|
||||||
|
|
||||||
@bind_hass
|
@bind_hass
|
||||||
def scan(hass, entity_id=ENTITY_MATCH_ALL):
|
def scan(hass: HomeAssistant, entity_id: str = ENTITY_MATCH_ALL) -> None:
|
||||||
"""Force process of all cameras or given entity."""
|
"""Force process of all cameras or given entity."""
|
||||||
hass.add_job(async_scan, hass, entity_id)
|
hass.add_job(async_scan, hass, entity_id)
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
@bind_hass
|
@bind_hass
|
||||||
def async_scan(hass, entity_id=ENTITY_MATCH_ALL):
|
def async_scan(hass: HomeAssistant, entity_id: str = ENTITY_MATCH_ALL) -> None:
|
||||||
"""Force process of all cameras or given entity."""
|
"""Force process of all cameras or given entity."""
|
||||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
|
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
|
||||||
hass.async_create_task(hass.services.async_call(DOMAIN, SERVICE_SCAN, data))
|
hass.async_create_task(hass.services.async_call(DOMAIN, SERVICE_SCAN, data))
|
||||||
|
@ -35,13 +35,15 @@ def aiohttp_unused_port_factory(
|
|||||||
return unused_tcp_port_factory
|
return unused_tcp_port_factory
|
||||||
|
|
||||||
|
|
||||||
def get_url(hass):
|
def get_url(hass: HomeAssistant) -> str:
|
||||||
"""Return camera url."""
|
"""Return camera url."""
|
||||||
state = hass.states.get("camera.demo_camera")
|
state = hass.states.get("camera.demo_camera")
|
||||||
return f"{hass.config.internal_url}{state.attributes.get(ATTR_ENTITY_PICTURE)}"
|
return f"{hass.config.internal_url}{state.attributes.get(ATTR_ENTITY_PICTURE)}"
|
||||||
|
|
||||||
|
|
||||||
async def setup_image_processing(hass, aiohttp_unused_port_factory):
|
async def setup_image_processing(
|
||||||
|
hass: HomeAssistant, aiohttp_unused_port_factory: Callable[[], int]
|
||||||
|
) -> None:
|
||||||
"""Set up things to be run when tests are started."""
|
"""Set up things to be run when tests are started."""
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
@ -55,7 +57,7 @@ async def setup_image_processing(hass, aiohttp_unused_port_factory):
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
|
||||||
async def setup_image_processing_face(hass):
|
async def setup_image_processing_face(hass: HomeAssistant) -> None:
|
||||||
"""Set up things to be run when tests are started."""
|
"""Set up things to be run when tests are started."""
|
||||||
config = {ip.DOMAIN: {"platform": "demo"}, "camera": {"platform": "demo"}}
|
config = {ip.DOMAIN: {"platform": "demo"}, "camera": {"platform": "demo"}}
|
||||||
|
|
||||||
@ -93,7 +95,7 @@ async def test_setup_component_with_service(hass: HomeAssistant) -> None:
|
|||||||
async def test_get_image_from_camera(
|
async def test_get_image_from_camera(
|
||||||
mock_camera_read,
|
mock_camera_read,
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
aiohttp_unused_port_factory,
|
aiohttp_unused_port_factory: Callable[[], int],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Grab an image from camera entity."""
|
"""Grab an image from camera entity."""
|
||||||
await setup_image_processing(hass, aiohttp_unused_port_factory)
|
await setup_image_processing(hass, aiohttp_unused_port_factory)
|
||||||
@ -116,7 +118,7 @@ async def test_get_image_from_camera(
|
|||||||
async def test_get_image_without_exists_camera(
|
async def test_get_image_without_exists_camera(
|
||||||
mock_image,
|
mock_image,
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
aiohttp_unused_port_factory,
|
aiohttp_unused_port_factory: Callable[[], int],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Try to get image without exists camera."""
|
"""Try to get image without exists camera."""
|
||||||
await setup_image_processing(hass, aiohttp_unused_port_factory)
|
await setup_image_processing(hass, aiohttp_unused_port_factory)
|
||||||
@ -191,7 +193,7 @@ async def test_face_event_call_no_confidence(
|
|||||||
@pytest.mark.usefixtures("enable_custom_integrations")
|
@pytest.mark.usefixtures("enable_custom_integrations")
|
||||||
async def test_update_missing_camera(
|
async def test_update_missing_camera(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
aiohttp_unused_port_factory,
|
aiohttp_unused_port_factory: Callable[[], int],
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test when entity does not set camera."""
|
"""Test when entity does not set camera."""
|
||||||
|
@ -334,7 +334,9 @@ async def test_invalid_config(
|
|||||||
assert not await async_setup_component(hass, influxdb.DOMAIN, config)
|
assert not await async_setup_component(hass, influxdb.DOMAIN, config)
|
||||||
|
|
||||||
|
|
||||||
async def _setup(hass, mock_influx_client, config_ext, get_write_api):
|
async def _setup(
|
||||||
|
hass: HomeAssistant, mock_influx_client, config_ext, get_write_api
|
||||||
|
) -> None:
|
||||||
"""Prepare client for next test and return event handler method."""
|
"""Prepare client for next test and return event handler method."""
|
||||||
config = {
|
config = {
|
||||||
"influxdb": {
|
"influxdb": {
|
||||||
|
@ -25,7 +25,7 @@ from homeassistant.components.influxdb.const import (
|
|||||||
)
|
)
|
||||||
from homeassistant.components.influxdb.sensor import PLATFORM_SCHEMA
|
from homeassistant.components.influxdb.sensor import PLATFORM_SCHEMA
|
||||||
from homeassistant.const import STATE_UNKNOWN
|
from homeassistant.const import STATE_UNKNOWN
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant, State
|
||||||
from homeassistant.helpers.entity_platform import PLATFORM_NOT_READY_BASE_WAIT_TIME
|
from homeassistant.helpers.entity_platform import PLATFORM_NOT_READY_BASE_WAIT_TIME
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
@ -190,7 +190,9 @@ def _set_query_mock_v2(
|
|||||||
return query_api
|
return query_api
|
||||||
|
|
||||||
|
|
||||||
async def _setup(hass, config_ext, queries, expected_sensors):
|
async def _setup(
|
||||||
|
hass: HomeAssistant, config_ext, queries, expected_sensors
|
||||||
|
) -> list[State]:
|
||||||
"""Create client and test expected sensors."""
|
"""Create client and test expected sensors."""
|
||||||
config = {
|
config = {
|
||||||
DOMAIN: config_ext,
|
DOMAIN: config_ext,
|
||||||
|
@ -79,7 +79,9 @@ def storage_setup(hass: HomeAssistant, hass_storage: dict[str, Any]):
|
|||||||
return _storage
|
return _storage
|
||||||
|
|
||||||
|
|
||||||
async def async_set_date_and_time(hass, entity_id, dt_value):
|
async def async_set_date_and_time(
|
||||||
|
hass: HomeAssistant, entity_id: str, dt_value: datetime.datetime
|
||||||
|
) -> None:
|
||||||
"""Set date and / or time of input_datetime."""
|
"""Set date and / or time of input_datetime."""
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
@ -93,7 +95,9 @@ async def async_set_date_and_time(hass, entity_id, dt_value):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def async_set_datetime(hass, entity_id, dt_value):
|
async def async_set_datetime(
|
||||||
|
hass: HomeAssistant, entity_id: str, dt_value: datetime.datetime
|
||||||
|
) -> None:
|
||||||
"""Set date and / or time of input_datetime."""
|
"""Set date and / or time of input_datetime."""
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
@ -103,7 +107,9 @@ async def async_set_datetime(hass, entity_id, dt_value):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def async_set_timestamp(hass, entity_id, timestamp):
|
async def async_set_timestamp(
|
||||||
|
hass: HomeAssistant, entity_id: str, timestamp: float
|
||||||
|
) -> None:
|
||||||
"""Set date and / or time of input_datetime."""
|
"""Set date and / or time of input_datetime."""
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
@ -65,7 +65,7 @@ def storage_setup(hass: HomeAssistant, hass_storage: dict[str, Any]):
|
|||||||
return _storage
|
return _storage
|
||||||
|
|
||||||
|
|
||||||
async def set_value(hass, entity_id, value):
|
async def set_value(hass: HomeAssistant, entity_id: str, value: str) -> None:
|
||||||
"""Set input_number to value.
|
"""Set input_number to value.
|
||||||
|
|
||||||
This is a legacy helper method. Do not use it for new tests.
|
This is a legacy helper method. Do not use it for new tests.
|
||||||
@ -78,7 +78,7 @@ async def set_value(hass, entity_id, value):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def increment(hass, entity_id):
|
async def increment(hass: HomeAssistant, entity_id: str) -> None:
|
||||||
"""Increment value of entity.
|
"""Increment value of entity.
|
||||||
|
|
||||||
This is a legacy helper method. Do not use it for new tests.
|
This is a legacy helper method. Do not use it for new tests.
|
||||||
@ -88,7 +88,7 @@ async def increment(hass, entity_id):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def decrement(hass, entity_id):
|
async def decrement(hass: HomeAssistant, entity_id: str) -> None:
|
||||||
"""Decrement value of entity.
|
"""Decrement value of entity.
|
||||||
|
|
||||||
This is a legacy helper method. Do not use it for new tests.
|
This is a legacy helper method. Do not use it for new tests.
|
||||||
|
@ -71,7 +71,7 @@ def storage_setup(hass: HomeAssistant, hass_storage: dict[str, Any]):
|
|||||||
return _storage
|
return _storage
|
||||||
|
|
||||||
|
|
||||||
async def async_set_value(hass, entity_id, value):
|
async def async_set_value(hass: HomeAssistant, entity_id: str, value: str) -> None:
|
||||||
"""Set input_text to value."""
|
"""Set input_text to value."""
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
"""Test the Insteon All-Link Database APIs."""
|
"""Test the Insteon All-Link Database APIs."""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
from typing import Any
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from pyinsteon import pub
|
from pyinsteon import pub
|
||||||
@ -23,7 +24,7 @@ from homeassistant.core import HomeAssistant
|
|||||||
from .mock_devices import MockDevices
|
from .mock_devices import MockDevices
|
||||||
|
|
||||||
from tests.common import load_fixture
|
from tests.common import load_fixture
|
||||||
from tests.typing import WebSocketGenerator
|
from tests.typing import MockHAClientWebSocket, WebSocketGenerator
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="aldb_data", scope="module")
|
@pytest.fixture(name="aldb_data", scope="module")
|
||||||
@ -32,7 +33,9 @@ def aldb_data_fixture():
|
|||||||
return json.loads(load_fixture("insteon/aldb_data.json"))
|
return json.loads(load_fixture("insteon/aldb_data.json"))
|
||||||
|
|
||||||
|
|
||||||
async def _setup(hass, hass_ws_client, aldb_data):
|
async def _setup(
|
||||||
|
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, aldb_data: dict[str, Any]
|
||||||
|
) -> tuple[MockHAClientWebSocket, MockDevices]:
|
||||||
"""Set up tests."""
|
"""Set up tests."""
|
||||||
ws_client = await hass_ws_client(hass)
|
ws_client = await hass_ws_client(hass)
|
||||||
devices = MockDevices()
|
devices = MockDevices()
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
"""Test the Insteon properties APIs."""
|
"""Test the Insteon properties APIs."""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
from typing import Any
|
||||||
from unittest.mock import AsyncMock, patch
|
from unittest.mock import AsyncMock, patch
|
||||||
|
|
||||||
from pyinsteon.config import MOMENTARY_DELAY, RELAY_MODE, TOGGLE_BUTTON
|
from pyinsteon.config import MOMENTARY_DELAY, RELAY_MODE, TOGGLE_BUTTON
|
||||||
@ -26,7 +27,7 @@ from homeassistant.core import HomeAssistant
|
|||||||
from .mock_devices import MockDevices
|
from .mock_devices import MockDevices
|
||||||
|
|
||||||
from tests.common import load_fixture
|
from tests.common import load_fixture
|
||||||
from tests.typing import WebSocketGenerator
|
from tests.typing import MockHAClientWebSocket, WebSocketGenerator
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="kpl_properties_data", scope="module")
|
@pytest.fixture(name="kpl_properties_data", scope="module")
|
||||||
@ -41,7 +42,12 @@ def iolinc_properties_data_fixture():
|
|||||||
return json.loads(load_fixture("insteon/iolinc_properties.json"))
|
return json.loads(load_fixture("insteon/iolinc_properties.json"))
|
||||||
|
|
||||||
|
|
||||||
async def _setup(hass, hass_ws_client, address, properties_data):
|
async def _setup(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
hass_ws_client: WebSocketGenerator,
|
||||||
|
address: str,
|
||||||
|
properties_data: dict[str, Any],
|
||||||
|
) -> tuple[MockHAClientWebSocket, MockDevices]:
|
||||||
"""Set up tests."""
|
"""Set up tests."""
|
||||||
ws_client = await hass_ws_client(hass)
|
ws_client = await hass_ws_client(hass)
|
||||||
devices = MockDevices()
|
devices = MockDevices()
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
"""Test the config flow for the Insteon integration."""
|
"""Test the config flow for the Insteon integration."""
|
||||||
|
|
||||||
from unittest.mock import patch
|
from collections.abc import Callable
|
||||||
|
from typing import Any
|
||||||
|
from unittest.mock import AsyncMock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from voluptuous_serialize import convert
|
from voluptuous_serialize import convert
|
||||||
@ -14,7 +16,7 @@ from homeassistant.components.insteon.config_flow import (
|
|||||||
STEP_PLM_MANUALLY,
|
STEP_PLM_MANUALLY,
|
||||||
)
|
)
|
||||||
from homeassistant.components.insteon.const import CONF_HUB_VERSION, DOMAIN
|
from homeassistant.components.insteon.const import CONF_HUB_VERSION, DOMAIN
|
||||||
from homeassistant.config_entries import ConfigEntryState
|
from homeassistant.config_entries import ConfigEntryState, ConfigFlowResult
|
||||||
from homeassistant.const import CONF_DEVICE, CONF_HOST
|
from homeassistant.const import CONF_DEVICE, CONF_HOST
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import FlowResultType
|
from homeassistant.data_entry_flow import FlowResultType
|
||||||
@ -60,7 +62,7 @@ async def mock_failed_connection(*args, **kwargs):
|
|||||||
raise ConnectionError("Connection failed")
|
raise ConnectionError("Connection failed")
|
||||||
|
|
||||||
|
|
||||||
async def _init_form(hass, modem_type):
|
async def _init_form(hass: HomeAssistant, modem_type: str) -> ConfigFlowResult:
|
||||||
"""Run the user form."""
|
"""Run the user form."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
@ -73,7 +75,12 @@ async def _init_form(hass, modem_type):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def _device_form(hass, flow_id, connection, user_input):
|
async def _device_form(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
flow_id: str,
|
||||||
|
connection: Callable[..., Any],
|
||||||
|
user_input: dict[str, Any] | None,
|
||||||
|
) -> tuple[ConfigFlowResult, AsyncMock]:
|
||||||
"""Test the PLM, Hub v1 or Hub v2 form."""
|
"""Test the PLM, Hub v1 or Hub v2 form."""
|
||||||
with (
|
with (
|
||||||
patch(
|
patch(
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
"""Tests for iZone."""
|
"""Tests for iZone."""
|
||||||
|
|
||||||
|
from collections.abc import Callable
|
||||||
|
from typing import Any
|
||||||
from unittest.mock import Mock, patch
|
from unittest.mock import Mock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@ -12,7 +14,7 @@ from homeassistant.helpers.dispatcher import async_dispatcher_send
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_disco():
|
def mock_disco() -> Mock:
|
||||||
"""Mock discovery service."""
|
"""Mock discovery service."""
|
||||||
disco = Mock()
|
disco = Mock()
|
||||||
disco.pi_disco = Mock()
|
disco.pi_disco = Mock()
|
||||||
@ -20,15 +22,15 @@ def mock_disco():
|
|||||||
return disco
|
return disco
|
||||||
|
|
||||||
|
|
||||||
def _mock_start_discovery(hass, mock_disco):
|
def _mock_start_discovery(hass: HomeAssistant, mock_disco: Mock) -> Callable[..., Mock]:
|
||||||
def do_disovered(*args):
|
def do_disovered(*args: Any) -> Mock:
|
||||||
async_dispatcher_send(hass, DISPATCH_CONTROLLER_DISCOVERED, True)
|
async_dispatcher_send(hass, DISPATCH_CONTROLLER_DISCOVERED, True)
|
||||||
return mock_disco
|
return mock_disco
|
||||||
|
|
||||||
return do_disovered
|
return do_disovered
|
||||||
|
|
||||||
|
|
||||||
async def test_not_found(hass: HomeAssistant, mock_disco) -> None:
|
async def test_not_found(hass: HomeAssistant, mock_disco: Mock) -> None:
|
||||||
"""Test not finding iZone controller."""
|
"""Test not finding iZone controller."""
|
||||||
|
|
||||||
with (
|
with (
|
||||||
@ -56,7 +58,7 @@ async def test_not_found(hass: HomeAssistant, mock_disco) -> None:
|
|||||||
stop_disco.assert_called_once()
|
stop_disco.assert_called_once()
|
||||||
|
|
||||||
|
|
||||||
async def test_found(hass: HomeAssistant, mock_disco) -> None:
|
async def test_found(hass: HomeAssistant, mock_disco: Mock) -> None:
|
||||||
"""Test not finding iZone controller."""
|
"""Test not finding iZone controller."""
|
||||||
mock_disco.pi_disco.controllers["blah"] = object()
|
mock_disco.pi_disco.controllers["blah"] = object()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user