1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Add type hints to integration tests (d-e) (#87699)

This commit is contained in:
epenet
2023-02-08 13:01:44 +01:00
committed by GitHub
parent 5e214f2e43
commit 3052de3e8e
81 changed files with 765 additions and 450 deletions

View File

@@ -5,11 +5,12 @@ import random
from unittest.mock import patch
from homeassistant.const import UnitOfPower, UnitOfTime
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
import homeassistant.util.dt as dt_util
async def test_state(hass):
async def test_state(hass: HomeAssistant) -> None:
"""Test derivative sensor state."""
config = {
"sensor": {
@@ -81,7 +82,7 @@ async def setup_tests(hass, config, times, values, expected_state):
return state
async def test_dataSet1(hass):
async def test_dataSet1(hass: HomeAssistant) -> None:
"""Test derivative sensor state."""
await setup_tests(
hass,
@@ -92,7 +93,7 @@ async def test_dataSet1(hass):
)
async def test_dataSet2(hass):
async def test_dataSet2(hass: HomeAssistant) -> None:
"""Test derivative sensor state."""
await setup_tests(
hass,
@@ -103,7 +104,7 @@ async def test_dataSet2(hass):
)
async def test_dataSet3(hass):
async def test_dataSet3(hass: HomeAssistant) -> None:
"""Test derivative sensor state."""
state = await setup_tests(
hass,
@@ -116,7 +117,7 @@ async def test_dataSet3(hass):
assert state.attributes.get("unit_of_measurement") == f"/{UnitOfTime.SECONDS}"
async def test_dataSet4(hass):
async def test_dataSet4(hass: HomeAssistant) -> None:
"""Test derivative sensor state."""
await setup_tests(
hass,
@@ -127,7 +128,7 @@ async def test_dataSet4(hass):
)
async def test_dataSet5(hass):
async def test_dataSet5(hass: HomeAssistant) -> None:
"""Test derivative sensor state."""
await setup_tests(
hass,
@@ -138,12 +139,12 @@ async def test_dataSet5(hass):
)
async def test_dataSet6(hass):
async def test_dataSet6(hass: HomeAssistant) -> None:
"""Test derivative sensor state."""
await setup_tests(hass, {}, times=[0, 60], values=[0, 1 / 60], expected_state=1)
async def test_data_moving_average_for_discrete_sensor(hass):
async def test_data_moving_average_for_discrete_sensor(hass: HomeAssistant) -> None:
"""Test derivative sensor state."""
# We simulate the following situation:
# The temperature rises 1 °C per minute for 30 minutes long.
@@ -182,7 +183,7 @@ async def test_data_moving_average_for_discrete_sensor(hass):
assert abs(1 - derivative) <= 0.1 + 1e-6
async def test_data_moving_average_for_irregular_times(hass):
async def test_data_moving_average_for_irregular_times(hass: HomeAssistant) -> None:
"""Test derivative sensor state."""
# We simulate the following situation:
# The temperature rises 1 °C per minute for 30 minutes long.
@@ -225,7 +226,7 @@ async def test_data_moving_average_for_irregular_times(hass):
assert abs(0.1 - derivative) <= 0.01 + 1e-6
async def test_double_signal_after_delay(hass):
async def test_double_signal_after_delay(hass: HomeAssistant) -> None:
"""Test derivative sensor state."""
# The old algorithm would produce extreme values if, after a delay longer than the time window
# there would be two signals, a large spike would be produced. Check explicitly for this situation
@@ -266,7 +267,7 @@ async def test_double_signal_after_delay(hass):
previous = derivative
async def test_prefix(hass):
async def test_prefix(hass: HomeAssistant) -> None:
"""Test derivative sensor state using a power source."""
config = {
"sensor": {
@@ -309,7 +310,7 @@ async def test_prefix(hass):
assert state.attributes.get("unit_of_measurement") == f"kW/{UnitOfTime.HOURS}"
async def test_suffix(hass):
async def test_suffix(hass: HomeAssistant) -> None:
"""Test derivative sensor state using a network counter source."""
config = {
"sensor": {