mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Improve type hints in iotawatt tests (#121505)
This commit is contained in:
parent
10ee554f1f
commit
19e272a901
@ -1,16 +1,18 @@
|
|||||||
"""Test fixtures for IoTaWatt."""
|
"""Test fixtures for IoTaWatt."""
|
||||||
|
|
||||||
from unittest.mock import AsyncMock, patch
|
from collections.abc import Generator
|
||||||
|
from unittest.mock import AsyncMock, MagicMock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.iotawatt import DOMAIN
|
from homeassistant.components.iotawatt import DOMAIN
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def entry(hass):
|
def entry(hass: HomeAssistant) -> MockConfigEntry:
|
||||||
"""Mock config entry added to HA."""
|
"""Mock config entry added to HA."""
|
||||||
entry = MockConfigEntry(domain=DOMAIN, data={"host": "1.2.3.4"})
|
entry = MockConfigEntry(domain=DOMAIN, data={"host": "1.2.3.4"})
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
@ -18,7 +20,7 @@ def entry(hass):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_iotawatt(entry):
|
def mock_iotawatt(entry: MockConfigEntry) -> Generator[MagicMock]:
|
||||||
"""Mock iotawatt."""
|
"""Mock iotawatt."""
|
||||||
with patch("homeassistant.components.iotawatt.coordinator.Iotawatt") as mock:
|
with patch("homeassistant.components.iotawatt.coordinator.Iotawatt") as mock:
|
||||||
instance = mock.return_value
|
instance = mock.return_value
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
"""Test init."""
|
"""Test init."""
|
||||||
|
|
||||||
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntryState
|
from homeassistant.config_entries import ConfigEntryState
|
||||||
@ -8,8 +10,12 @@ from homeassistant.setup import async_setup_component
|
|||||||
|
|
||||||
from . import INPUT_SENSOR
|
from . import INPUT_SENSOR
|
||||||
|
|
||||||
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
async def test_setup_unload(hass: HomeAssistant, mock_iotawatt, entry) -> None:
|
|
||||||
|
async def test_setup_unload(
|
||||||
|
hass: HomeAssistant, mock_iotawatt: MagicMock, entry: MockConfigEntry
|
||||||
|
) -> None:
|
||||||
"""Test we can setup and unload an entry."""
|
"""Test we can setup and unload an entry."""
|
||||||
mock_iotawatt.getSensors.return_value["sensors"]["my_sensor_key"] = INPUT_SENSOR
|
mock_iotawatt.getSensors.return_value["sensors"]["my_sensor_key"] = INPUT_SENSOR
|
||||||
assert await async_setup_component(hass, "iotawatt", {})
|
assert await async_setup_component(hass, "iotawatt", {})
|
||||||
@ -18,7 +24,7 @@ async def test_setup_unload(hass: HomeAssistant, mock_iotawatt, entry) -> None:
|
|||||||
|
|
||||||
|
|
||||||
async def test_setup_connection_failed(
|
async def test_setup_connection_failed(
|
||||||
hass: HomeAssistant, mock_iotawatt, entry
|
hass: HomeAssistant, mock_iotawatt: MagicMock, entry: MockConfigEntry
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test connection error during startup."""
|
"""Test connection error during startup."""
|
||||||
mock_iotawatt.connect.side_effect = httpx.ConnectError("")
|
mock_iotawatt.connect.side_effect = httpx.ConnectError("")
|
||||||
@ -27,7 +33,9 @@ async def test_setup_connection_failed(
|
|||||||
assert entry.state is ConfigEntryState.SETUP_RETRY
|
assert entry.state is ConfigEntryState.SETUP_RETRY
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_auth_failed(hass: HomeAssistant, mock_iotawatt, entry) -> None:
|
async def test_setup_auth_failed(
|
||||||
|
hass: HomeAssistant, mock_iotawatt: MagicMock, entry: MockConfigEntry
|
||||||
|
) -> None:
|
||||||
"""Test auth error during startup."""
|
"""Test auth error during startup."""
|
||||||
mock_iotawatt.connect.return_value = False
|
mock_iotawatt.connect.return_value = False
|
||||||
assert await async_setup_component(hass, "iotawatt", {})
|
assert await async_setup_component(hass, "iotawatt", {})
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
"""Test setting up sensors."""
|
"""Test setting up sensors."""
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
from freezegun.api import FrozenDateTimeFactory
|
from freezegun.api import FrozenDateTimeFactory
|
||||||
|
|
||||||
@ -25,7 +26,7 @@ from tests.common import async_fire_time_changed
|
|||||||
|
|
||||||
|
|
||||||
async def test_sensor_type_input(
|
async def test_sensor_type_input(
|
||||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory, mock_iotawatt
|
hass: HomeAssistant, freezer: FrozenDateTimeFactory, mock_iotawatt: MagicMock
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test input sensors work."""
|
"""Test input sensors work."""
|
||||||
assert await async_setup_component(hass, "iotawatt", {})
|
assert await async_setup_component(hass, "iotawatt", {})
|
||||||
@ -60,7 +61,7 @@ async def test_sensor_type_input(
|
|||||||
|
|
||||||
|
|
||||||
async def test_sensor_type_output(
|
async def test_sensor_type_output(
|
||||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory, mock_iotawatt
|
hass: HomeAssistant, freezer: FrozenDateTimeFactory, mock_iotawatt: MagicMock
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Tests the sensor type of Output."""
|
"""Tests the sensor type of Output."""
|
||||||
mock_iotawatt.getSensors.return_value["sensors"]["my_watthour_sensor_key"] = (
|
mock_iotawatt.getSensors.return_value["sensors"]["my_watthour_sensor_key"] = (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user