mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Add missing hass type hint in component tests (l) (#124220)
This commit is contained in:
parent
16e52f0427
commit
02139fcca6
@ -5,7 +5,7 @@ from __future__ import annotations
|
||||
from collections.abc import Callable
|
||||
import socket
|
||||
from typing import Any
|
||||
from unittest.mock import DEFAULT, patch
|
||||
from unittest.mock import DEFAULT, MagicMock, patch
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.lg_soundbar.const import DEFAULT_PORT, DOMAIN
|
||||
@ -17,8 +17,12 @@ from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
def setup_mock_temescal(
|
||||
hass, mock_temescal, mac_info_dev=None, product_info=None, info=None
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
mock_temescal: MagicMock,
|
||||
mac_info_dev: dict[str, Any] | None = None,
|
||||
product_info: dict[str, Any] | None = None,
|
||||
info: dict[str, Any] | None = None,
|
||||
) -> None:
|
||||
"""Set up a mock of the temescal object to craft our expected responses."""
|
||||
tmock = mock_temescal.temescal
|
||||
instance = tmock.return_value
|
||||
|
@ -33,6 +33,7 @@ from homeassistant.const import (
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.loader import bind_hass
|
||||
|
||||
from tests.common import MockToggleEntity
|
||||
@ -40,24 +41,24 @@ from tests.common import MockToggleEntity
|
||||
|
||||
@bind_hass
|
||||
def turn_on(
|
||||
hass,
|
||||
entity_id=ENTITY_MATCH_ALL,
|
||||
transition=None,
|
||||
brightness=None,
|
||||
brightness_pct=None,
|
||||
rgb_color=None,
|
||||
rgbw_color=None,
|
||||
rgbww_color=None,
|
||||
xy_color=None,
|
||||
hs_color=None,
|
||||
color_temp=None,
|
||||
kelvin=None,
|
||||
profile=None,
|
||||
flash=None,
|
||||
effect=None,
|
||||
color_name=None,
|
||||
white=None,
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
entity_id: str = ENTITY_MATCH_ALL,
|
||||
transition: float | None = None,
|
||||
brightness: int | None = None,
|
||||
brightness_pct: float | None = None,
|
||||
rgb_color: tuple[int, int, int] | None = None,
|
||||
rgbw_color: tuple[int, int, int, int] | None = None,
|
||||
rgbww_color: tuple[int, int, int, int, int] | None = None,
|
||||
xy_color: tuple[float, float] | None = None,
|
||||
hs_color: tuple[float, float] | None = None,
|
||||
color_temp: int | None = None,
|
||||
kelvin: int | None = None,
|
||||
profile: str | None = None,
|
||||
flash: str | None = None,
|
||||
effect: str | None = None,
|
||||
color_name: str | None = None,
|
||||
white: bool | None = None,
|
||||
) -> None:
|
||||
"""Turn all or specified light on."""
|
||||
hass.add_job(
|
||||
async_turn_on,
|
||||
@ -82,24 +83,24 @@ def turn_on(
|
||||
|
||||
|
||||
async def async_turn_on(
|
||||
hass,
|
||||
entity_id=ENTITY_MATCH_ALL,
|
||||
transition=None,
|
||||
brightness=None,
|
||||
brightness_pct=None,
|
||||
rgb_color=None,
|
||||
rgbw_color=None,
|
||||
rgbww_color=None,
|
||||
xy_color=None,
|
||||
hs_color=None,
|
||||
color_temp=None,
|
||||
kelvin=None,
|
||||
profile=None,
|
||||
flash=None,
|
||||
effect=None,
|
||||
color_name=None,
|
||||
white=None,
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
entity_id: str = ENTITY_MATCH_ALL,
|
||||
transition: float | None = None,
|
||||
brightness: int | None = None,
|
||||
brightness_pct: float | None = None,
|
||||
rgb_color: tuple[int, int, int] | None = None,
|
||||
rgbw_color: tuple[int, int, int, int] | None = None,
|
||||
rgbww_color: tuple[int, int, int, int, int] | None = None,
|
||||
xy_color: tuple[float, float] | None = None,
|
||||
hs_color: tuple[float, float] | None = None,
|
||||
color_temp: int | None = None,
|
||||
kelvin: int | None = None,
|
||||
profile: str | None = None,
|
||||
flash: str | None = None,
|
||||
effect: str | None = None,
|
||||
color_name: str | None = None,
|
||||
white: bool | None = None,
|
||||
) -> None:
|
||||
"""Turn all or specified light on."""
|
||||
data = {
|
||||
key: value
|
||||
@ -128,12 +129,22 @@ async def async_turn_on(
|
||||
|
||||
|
||||
@bind_hass
|
||||
def turn_off(hass, entity_id=ENTITY_MATCH_ALL, transition=None, flash=None):
|
||||
def turn_off(
|
||||
hass: HomeAssistant,
|
||||
entity_id: str = ENTITY_MATCH_ALL,
|
||||
transition: float | None = None,
|
||||
flash: str | None = None,
|
||||
) -> None:
|
||||
"""Turn all or specified light off."""
|
||||
hass.add_job(async_turn_off, hass, entity_id, transition, flash)
|
||||
|
||||
|
||||
async def async_turn_off(hass, entity_id=ENTITY_MATCH_ALL, transition=None, flash=None):
|
||||
async def async_turn_off(
|
||||
hass: HomeAssistant,
|
||||
entity_id: str = ENTITY_MATCH_ALL,
|
||||
transition: float | None = None,
|
||||
flash: str | None = None,
|
||||
) -> None:
|
||||
"""Turn all or specified light off."""
|
||||
data = {
|
||||
key: value
|
||||
@ -150,21 +161,21 @@ async def async_turn_off(hass, entity_id=ENTITY_MATCH_ALL, transition=None, flas
|
||||
|
||||
@bind_hass
|
||||
def toggle(
|
||||
hass,
|
||||
entity_id=ENTITY_MATCH_ALL,
|
||||
transition=None,
|
||||
brightness=None,
|
||||
brightness_pct=None,
|
||||
rgb_color=None,
|
||||
xy_color=None,
|
||||
hs_color=None,
|
||||
color_temp=None,
|
||||
kelvin=None,
|
||||
profile=None,
|
||||
flash=None,
|
||||
effect=None,
|
||||
color_name=None,
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
entity_id: str = ENTITY_MATCH_ALL,
|
||||
transition: float | None = None,
|
||||
brightness: int | None = None,
|
||||
brightness_pct: float | None = None,
|
||||
rgb_color: tuple[int, int, int] | None = None,
|
||||
xy_color: tuple[float, float] | None = None,
|
||||
hs_color: tuple[float, float] | None = None,
|
||||
color_temp: int | None = None,
|
||||
kelvin: int | None = None,
|
||||
profile: str | None = None,
|
||||
flash: str | None = None,
|
||||
effect: str | None = None,
|
||||
color_name: str | None = None,
|
||||
) -> None:
|
||||
"""Toggle all or specified light."""
|
||||
hass.add_job(
|
||||
async_toggle,
|
||||
@ -186,21 +197,21 @@ def toggle(
|
||||
|
||||
|
||||
async def async_toggle(
|
||||
hass,
|
||||
entity_id=ENTITY_MATCH_ALL,
|
||||
transition=None,
|
||||
brightness=None,
|
||||
brightness_pct=None,
|
||||
rgb_color=None,
|
||||
xy_color=None,
|
||||
hs_color=None,
|
||||
color_temp=None,
|
||||
kelvin=None,
|
||||
profile=None,
|
||||
flash=None,
|
||||
effect=None,
|
||||
color_name=None,
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
entity_id: str = ENTITY_MATCH_ALL,
|
||||
transition: float | None = None,
|
||||
brightness: int | None = None,
|
||||
brightness_pct: float | None = None,
|
||||
rgb_color: tuple[int, int, int] | None = None,
|
||||
xy_color: tuple[float, float] | None = None,
|
||||
hs_color: tuple[float, float] | None = None,
|
||||
color_temp: int | None = None,
|
||||
kelvin: int | None = None,
|
||||
profile: str | None = None,
|
||||
flash: str | None = None,
|
||||
effect: str | None = None,
|
||||
color_name: str | None = None,
|
||||
) -> None:
|
||||
"""Turn all or specified light on."""
|
||||
data = {
|
||||
key: value
|
||||
|
@ -5,6 +5,7 @@ from unittest.mock import AsyncMock, patch
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.light import Profiles
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
@ -12,7 +13,7 @@ def mock_light_profiles():
|
||||
"""Mock loading of profiles."""
|
||||
data = {}
|
||||
|
||||
def mock_profiles_class(hass):
|
||||
def mock_profiles_class(hass: HomeAssistant) -> Profiles:
|
||||
profiles = Profiles(hass)
|
||||
profiles.data = data
|
||||
profiles.async_initialize = AsyncMock()
|
||||
|
@ -2,8 +2,9 @@
|
||||
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
from typing import Any
|
||||
from unittest import mock
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
@ -30,7 +31,9 @@ ENTITY_OTHER_SWITCH = "switch.mock_switch_2"
|
||||
ENTITY_OTHER_SWITCH_NUMBER = 2
|
||||
|
||||
|
||||
async def simulate_press(hass, mock_litejet, number):
|
||||
async def simulate_press(
|
||||
hass: HomeAssistant, mock_litejet: MagicMock, number: int
|
||||
) -> None:
|
||||
"""Test to simulate a press."""
|
||||
_LOGGER.info("*** simulate press of %d", number)
|
||||
callback = mock_litejet.switch_pressed_callbacks.get(number)
|
||||
@ -43,7 +46,9 @@ async def simulate_press(hass, mock_litejet, number):
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
async def simulate_release(hass, mock_litejet, number):
|
||||
async def simulate_release(
|
||||
hass: HomeAssistant, mock_litejet: MagicMock, number: int
|
||||
) -> None:
|
||||
"""Test to simulate releasing."""
|
||||
_LOGGER.info("*** simulate release of %d", number)
|
||||
callback = mock_litejet.switch_released_callbacks.get(number)
|
||||
@ -56,7 +61,9 @@ async def simulate_release(hass, mock_litejet, number):
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
async def simulate_time(hass, mock_litejet, delta):
|
||||
async def simulate_time(
|
||||
hass: HomeAssistant, mock_litejet: MagicMock, delta: timedelta
|
||||
) -> None:
|
||||
"""Test to simulate time."""
|
||||
_LOGGER.info(
|
||||
"*** simulate time change by %s: %s", delta, mock_litejet.start_time + delta
|
||||
@ -72,7 +79,7 @@ async def simulate_time(hass, mock_litejet, delta):
|
||||
_LOGGER.info("*** done with now=%s", dt_util.utcnow())
|
||||
|
||||
|
||||
async def setup_automation(hass, trigger):
|
||||
async def setup_automation(hass: HomeAssistant, trigger: dict[str, Any]) -> None:
|
||||
"""Test setting up the automation."""
|
||||
await async_init_integration(hass, use_switch=True)
|
||||
assert await setup.async_setup_component(
|
||||
@ -95,7 +102,7 @@ async def setup_automation(hass, trigger):
|
||||
|
||||
|
||||
async def test_simple(
|
||||
hass: HomeAssistant, service_calls: list[ServiceCall], mock_litejet
|
||||
hass: HomeAssistant, service_calls: list[ServiceCall], mock_litejet: MagicMock
|
||||
) -> None:
|
||||
"""Test the simplest form of a LiteJet trigger."""
|
||||
await setup_automation(
|
||||
@ -110,7 +117,7 @@ async def test_simple(
|
||||
|
||||
|
||||
async def test_only_release(
|
||||
hass: HomeAssistant, service_calls: list[ServiceCall], mock_litejet
|
||||
hass: HomeAssistant, service_calls: list[ServiceCall], mock_litejet: MagicMock
|
||||
) -> None:
|
||||
"""Test the simplest form of a LiteJet trigger."""
|
||||
await setup_automation(
|
||||
@ -123,7 +130,7 @@ async def test_only_release(
|
||||
|
||||
|
||||
async def test_held_more_than_short(
|
||||
hass: HomeAssistant, service_calls: list[ServiceCall], mock_litejet
|
||||
hass: HomeAssistant, service_calls: list[ServiceCall], mock_litejet: MagicMock
|
||||
) -> None:
|
||||
"""Test a too short hold."""
|
||||
await setup_automation(
|
||||
@ -142,7 +149,7 @@ async def test_held_more_than_short(
|
||||
|
||||
|
||||
async def test_held_more_than_long(
|
||||
hass: HomeAssistant, service_calls: list[ServiceCall], mock_litejet
|
||||
hass: HomeAssistant, service_calls: list[ServiceCall], mock_litejet: MagicMock
|
||||
) -> None:
|
||||
"""Test a hold that is long enough."""
|
||||
await setup_automation(
|
||||
@ -164,7 +171,7 @@ async def test_held_more_than_long(
|
||||
|
||||
|
||||
async def test_held_less_than_short(
|
||||
hass: HomeAssistant, service_calls: list[ServiceCall], mock_litejet
|
||||
hass: HomeAssistant, service_calls: list[ServiceCall], mock_litejet: MagicMock
|
||||
) -> None:
|
||||
"""Test a hold that is short enough."""
|
||||
await setup_automation(
|
||||
@ -185,7 +192,7 @@ async def test_held_less_than_short(
|
||||
|
||||
|
||||
async def test_held_less_than_long(
|
||||
hass: HomeAssistant, service_calls: list[ServiceCall], mock_litejet
|
||||
hass: HomeAssistant, service_calls: list[ServiceCall], mock_litejet: MagicMock
|
||||
) -> None:
|
||||
"""Test a hold that is too long."""
|
||||
await setup_automation(
|
||||
@ -206,7 +213,7 @@ async def test_held_less_than_long(
|
||||
|
||||
|
||||
async def test_held_in_range_short(
|
||||
hass: HomeAssistant, service_calls: list[ServiceCall], mock_litejet
|
||||
hass: HomeAssistant, service_calls: list[ServiceCall], mock_litejet: MagicMock
|
||||
) -> None:
|
||||
"""Test an in-range trigger with a too short hold."""
|
||||
await setup_automation(
|
||||
@ -226,7 +233,7 @@ async def test_held_in_range_short(
|
||||
|
||||
|
||||
async def test_held_in_range_just_right(
|
||||
hass: HomeAssistant, service_calls: list[ServiceCall], mock_litejet
|
||||
hass: HomeAssistant, service_calls: list[ServiceCall], mock_litejet: MagicMock
|
||||
) -> None:
|
||||
"""Test an in-range trigger with a just right hold."""
|
||||
await setup_automation(
|
||||
@ -249,7 +256,7 @@ async def test_held_in_range_just_right(
|
||||
|
||||
|
||||
async def test_held_in_range_long(
|
||||
hass: HomeAssistant, service_calls: list[ServiceCall], mock_litejet
|
||||
hass: HomeAssistant, service_calls: list[ServiceCall], mock_litejet: MagicMock
|
||||
) -> None:
|
||||
"""Test an in-range trigger with a too long hold."""
|
||||
await setup_automation(
|
||||
@ -271,7 +278,7 @@ async def test_held_in_range_long(
|
||||
|
||||
|
||||
async def test_reload(
|
||||
hass: HomeAssistant, service_calls: list[ServiceCall], mock_litejet
|
||||
hass: HomeAssistant, service_calls: list[ServiceCall], mock_litejet: MagicMock
|
||||
) -> None:
|
||||
"""Test reloading automation."""
|
||||
await setup_automation(
|
||||
|
@ -524,7 +524,7 @@ async def test_exclude_described_event(
|
||||
entity_id2 = "automation.included_rule"
|
||||
entity_id3 = "sensor.excluded_domain"
|
||||
|
||||
def _describe(event):
|
||||
def _describe(event: Event) -> dict[str, str]:
|
||||
"""Describe an event."""
|
||||
return {
|
||||
"name": "Test Name",
|
||||
@ -532,7 +532,12 @@ async def test_exclude_described_event(
|
||||
"entity_id": event.data[ATTR_ENTITY_ID],
|
||||
}
|
||||
|
||||
def async_describe_events(hass, async_describe_event):
|
||||
def async_describe_events(
|
||||
hass: HomeAssistant,
|
||||
async_describe_event: Callable[
|
||||
[str, str, Callable[[Event], dict[str, str]]], None
|
||||
],
|
||||
) -> None:
|
||||
"""Mock to describe events."""
|
||||
async_describe_event("automation", "some_automation_event", _describe)
|
||||
async_describe_event("sensor", "some_event", _describe)
|
||||
|
@ -226,7 +226,7 @@ async def test_can_set_level_from_store(
|
||||
_reset_logging()
|
||||
|
||||
|
||||
async def _assert_log_levels(hass):
|
||||
async def _assert_log_levels(hass: HomeAssistant) -> None:
|
||||
assert logging.getLogger(UNCONFIG_NS).level == logging.NOTSET
|
||||
assert logging.getLogger(UNCONFIG_NS).isEnabledFor(logging.CRITICAL) is True
|
||||
assert (
|
||||
|
@ -98,7 +98,7 @@ MOCK_BUTTON_DEVICES = [
|
||||
]
|
||||
|
||||
|
||||
async def _async_setup_lutron_with_picos(hass):
|
||||
async def _async_setup_lutron_with_picos(hass: HomeAssistant) -> str:
|
||||
"""Setups a lutron bridge with picos."""
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
|
Loading…
x
Reference in New Issue
Block a user