Skip to content

Commit

Permalink
Add missing hass type hint in history and recorder tests (home-assist…
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored Aug 19, 2024
1 parent 5470d14 commit c76d685
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 28 deletions.
14 changes: 5 additions & 9 deletions tests/components/history/test_init.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""The tests the History component."""

from datetime import timedelta
from datetime import datetime, timedelta
from http import HTTPStatus
import json
from unittest.mock import sentinel
Expand All @@ -13,7 +13,7 @@
from homeassistant.components.recorder.history import get_significant_states
from homeassistant.components.recorder.models import process_timestamp
from homeassistant.const import EVENT_HOMEASSISTANT_FINAL_WRITE
from homeassistant.core import HomeAssistant
from homeassistant.core import HomeAssistant, State
from homeassistant.helpers.json import JSONEncoder
from homeassistant.setup import async_setup_component
import homeassistant.util.dt as dt_util
Expand Down Expand Up @@ -291,13 +291,9 @@ async def set_state(state, **kwargs):
)


async def check_significant_states(hass, zero, four, states, config):
"""Check if significant states are retrieved."""
hist = get_significant_states(hass, zero, four)
assert_dict_of_states_equal_without_context_and_last_changed(states, hist)


async def async_record_states(hass):
async def async_record_states(
hass: HomeAssistant,
) -> tuple[datetime, datetime, dict[str, list[State | None]]]:
"""Record some test states.
We inject a bunch of state updates from media player, zone and
Expand Down
14 changes: 5 additions & 9 deletions tests/components/history/test_init_db_schema_30.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from datetime import timedelta
from datetime import datetime, timedelta
from http import HTTPStatus
import json
from unittest.mock import patch, sentinel
Expand All @@ -14,7 +14,7 @@
from homeassistant.components.recorder import Recorder
from homeassistant.components.recorder.history import get_significant_states
from homeassistant.components.recorder.models import process_timestamp
from homeassistant.core import HomeAssistant
from homeassistant.core import HomeAssistant, State
from homeassistant.helpers.json import JSONEncoder
from homeassistant.setup import async_setup_component
import homeassistant.util.dt as dt_util
Expand Down Expand Up @@ -309,13 +309,9 @@ async def set_state(state, **kwargs):
)


def check_significant_states(hass, zero, four, states, config):
"""Check if significant states are retrieved."""
hist = get_significant_states(hass, zero, four)
assert_dict_of_states_equal_without_context_and_last_changed(states, hist)


async def async_record_states(hass):
async def async_record_states(
hass: HomeAssistant,
) -> tuple[datetime, datetime, dict[str, list[State | None]]]:
"""Record some test states.
We inject a bunch of state updates from media player, zone and
Expand Down
8 changes: 6 additions & 2 deletions tests/components/recorder/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,16 @@ def assert_dict_of_states_equal_without_context_and_last_changed(
)


async def async_record_states(hass: HomeAssistant):
async def async_record_states(
hass: HomeAssistant,
) -> tuple[datetime, datetime, dict[str, list[State | None]]]:
"""Record some test states."""
return await hass.async_add_executor_job(record_states, hass)


def record_states(hass):
def record_states(
hass: HomeAssistant,
) -> tuple[datetime, datetime, dict[str, list[State | None]]]:
"""Record some test states.
We inject a bunch of state updates temperature sensors.
Expand Down
11 changes: 6 additions & 5 deletions tests/components/recorder/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,13 @@
STATE_LOCKED,
STATE_UNLOCKED,
)
from homeassistant.core import Context, CoreState, Event, HomeAssistant, callback
from homeassistant.core import Context, CoreState, Event, HomeAssistant, State, callback
from homeassistant.helpers import (
entity_registry as er,
issue_registry as ir,
recorder as recorder_helper,
)
from homeassistant.helpers.typing import ConfigType
from homeassistant.setup import async_setup_component
from homeassistant.util import dt as dt_util
from homeassistant.util.json import json_loads
Expand Down Expand Up @@ -123,7 +124,7 @@ def small_cache_size() -> Generator[None]:
yield


def _default_recorder(hass):
def _default_recorder(hass: HomeAssistant) -> Recorder:
"""Return a recorder with reasonable defaults."""
return Recorder(
hass,
Expand Down Expand Up @@ -581,7 +582,7 @@ async def test_saving_state_with_commit_interval_zero(
assert db_states[0].event_id is None


async def _add_entities(hass, entity_ids):
async def _add_entities(hass: HomeAssistant, entity_ids: list[str]) -> list[State]:
"""Add entities."""
attributes = {"test_attr": 5, "test_attr_10": "nice"}
for idx, entity_id in enumerate(entity_ids):
Expand All @@ -605,7 +606,7 @@ async def _add_entities(hass, entity_ids):
return states


def _state_with_context(hass, entity_id):
def _state_with_context(hass: HomeAssistant, entity_id: str) -> State | None:
# We don't restore context unless we need it by joining the
# events table on the event_id for state_changed events
return hass.states.get(entity_id)
Expand Down Expand Up @@ -1004,7 +1005,7 @@ async def test_defaults_set(hass: HomeAssistant) -> None:
"""Test the config defaults are set."""
recorder_config = None

async def mock_setup(hass, config):
async def mock_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Mock setup."""
nonlocal recorder_config
recorder_config = config["recorder"]
Expand Down
4 changes: 2 additions & 2 deletions tests/components/recorder/test_migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
States,
)
from homeassistant.components.recorder.util import session_scope
from homeassistant.core import HomeAssistant
from homeassistant.core import HomeAssistant, State
from homeassistant.helpers import recorder as recorder_helper
import homeassistant.util.dt as dt_util

Expand All @@ -47,7 +47,7 @@ async def mock_recorder_before_hass(
"""Set up recorder."""


def _get_native_states(hass, entity_id):
def _get_native_states(hass: HomeAssistant, entity_id: str) -> list[State]:
with session_scope(hass=hass, read_only=True) as session:
instance = recorder.get_instance(hass)
metadata_id = instance.states_meta_manager.get(entity_id, session, True)
Expand Down
4 changes: 3 additions & 1 deletion tests/components/recorder/test_purge.py
Original file line number Diff line number Diff line change
Expand Up @@ -1330,7 +1330,9 @@ def _add_db_entries(hass: HomeAssistant) -> None:
async def test_purge_entities(hass: HomeAssistant, recorder_mock: Recorder) -> None:
"""Test purging of specific entities."""

async def _purge_entities(hass, entity_ids, domains, entity_globs):
async def _purge_entities(
hass: HomeAssistant, entity_ids: str, domains: str, entity_globs: str
) -> None:
service_data = {
"entity_id": entity_ids,
"domains": domains,
Expand Down

0 comments on commit c76d685

Please sign in to comment.