mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 23:27:37 +00:00
Improve type hints in onewire tests (#134993)
This commit is contained in:
parent
e99aaed7fa
commit
f8618e65f6
@ -7,7 +7,7 @@ from pyownet.protocol import ConnError
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.onewire.const import DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_USER, ConfigEntry
|
||||
from homeassistant.config_entries import SOURCE_USER
|
||||
from homeassistant.const import CONF_HOST, CONF_PORT
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
@ -32,7 +32,7 @@ def get_device_id(request: pytest.FixtureRequest) -> str:
|
||||
|
||||
|
||||
@pytest.fixture(name="config_entry")
|
||||
def get_config_entry(hass: HomeAssistant) -> ConfigEntry:
|
||||
def get_config_entry(hass: HomeAssistant) -> MockConfigEntry:
|
||||
"""Create and register mock config entry."""
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
@ -54,14 +54,14 @@ def get_config_entry(hass: HomeAssistant) -> ConfigEntry:
|
||||
|
||||
|
||||
@pytest.fixture(name="owproxy")
|
||||
def get_owproxy() -> MagicMock:
|
||||
def get_owproxy() -> Generator[MagicMock]:
|
||||
"""Mock owproxy."""
|
||||
with patch("homeassistant.components.onewire.onewirehub.protocol.proxy") as owproxy:
|
||||
yield owproxy
|
||||
|
||||
|
||||
@pytest.fixture(name="owproxy_with_connerror")
|
||||
def get_owproxy_with_connerror() -> MagicMock:
|
||||
def get_owproxy_with_connerror() -> Generator[MagicMock]:
|
||||
"""Mock owproxy."""
|
||||
with patch(
|
||||
"homeassistant.components.onewire.onewirehub.protocol.proxy",
|
||||
|
@ -6,13 +6,14 @@ from unittest.mock import MagicMock, patch
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
|
||||
from . import setup_owproxy_mock_devices
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def override_platforms() -> Generator[None]:
|
||||
@ -23,7 +24,7 @@ def override_platforms() -> Generator[None]:
|
||||
|
||||
async def test_binary_sensors(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: MockConfigEntry,
|
||||
owproxy: MagicMock,
|
||||
device_id: str,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
|
@ -11,7 +11,7 @@ from homeassistant.components.onewire.const import (
|
||||
INPUT_ENTRY_DEVICE_SELECTION,
|
||||
MANUFACTURER_MAXIM,
|
||||
)
|
||||
from homeassistant.config_entries import SOURCE_USER, ConfigEntry
|
||||
from homeassistant.config_entries import SOURCE_USER
|
||||
from homeassistant.const import CONF_HOST, CONF_PORT
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
@ -24,7 +24,8 @@ pytestmark = pytest.mark.usefixtures("mock_setup_entry")
|
||||
|
||||
@pytest.fixture
|
||||
async def filled_device_registry(
|
||||
hass: HomeAssistant, config_entry: ConfigEntry, device_registry: dr.DeviceRegistry
|
||||
config_entry: MockConfigEntry,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
) -> dr.DeviceRegistry:
|
||||
"""Fill device registry with mock devices."""
|
||||
for key in ("28.111111111111", "28.222222222222", "28.222222222223"):
|
||||
@ -81,7 +82,7 @@ async def test_user_flow(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> No
|
||||
|
||||
|
||||
async def test_user_duplicate(
|
||||
hass: HomeAssistant, config_entry: ConfigEntry, mock_setup_entry: AsyncMock
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, mock_setup_entry: AsyncMock
|
||||
) -> None:
|
||||
"""Test user duplicate flow."""
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
@ -178,7 +179,7 @@ async def test_reconfigure_duplicate(
|
||||
|
||||
@pytest.mark.usefixtures("filled_device_registry")
|
||||
async def test_user_options_clear(
|
||||
hass: HomeAssistant, config_entry: ConfigEntry
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test clearing the options."""
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
@ -202,7 +203,7 @@ async def test_user_options_clear(
|
||||
|
||||
@pytest.mark.usefixtures("filled_device_registry")
|
||||
async def test_user_options_empty_selection(
|
||||
hass: HomeAssistant, config_entry: ConfigEntry
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test leaving the selection of devices empty."""
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
@ -227,7 +228,7 @@ async def test_user_options_empty_selection(
|
||||
|
||||
@pytest.mark.usefixtures("filled_device_registry")
|
||||
async def test_user_options_set_single(
|
||||
hass: HomeAssistant, config_entry: ConfigEntry
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test configuring a single device."""
|
||||
# Clear config options to certify functionality when starting from scratch
|
||||
@ -265,7 +266,7 @@ async def test_user_options_set_single(
|
||||
|
||||
async def test_user_options_set_multiple(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: MockConfigEntry,
|
||||
filled_device_registry: dr.DeviceRegistry,
|
||||
) -> None:
|
||||
"""Test configuring multiple consecutive devices in a row."""
|
||||
@ -328,7 +329,7 @@ async def test_user_options_set_multiple(
|
||||
|
||||
|
||||
async def test_user_options_no_devices(
|
||||
hass: HomeAssistant, config_entry: ConfigEntry
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test that options does not change when no devices are available."""
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
@ -6,12 +6,12 @@ from unittest.mock import MagicMock, patch
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import setup_owproxy_mock_devices
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
@ -40,7 +40,7 @@ DEVICE_DETAILS = {
|
||||
@pytest.mark.parametrize("device_id", ["EF.111111111113"], indirect=True)
|
||||
async def test_entry_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: MockConfigEntry,
|
||||
hass_client: ClientSessionGenerator,
|
||||
owproxy: MagicMock,
|
||||
device_id: str,
|
||||
|
@ -7,7 +7,7 @@ from pyownet import protocol
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.onewire.const import DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntry, ConfigEntryState
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
@ -15,11 +15,14 @@ from homeassistant.setup import async_setup_component
|
||||
|
||||
from . import setup_owproxy_mock_devices
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.typing import WebSocketGenerator
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("owproxy_with_connerror")
|
||||
async def test_connect_failure(hass: HomeAssistant, config_entry: ConfigEntry) -> None:
|
||||
async def test_connect_failure(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test connection failure raises ConfigEntryNotReady."""
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
@ -29,7 +32,7 @@ async def test_connect_failure(hass: HomeAssistant, config_entry: ConfigEntry) -
|
||||
|
||||
|
||||
async def test_listing_failure(
|
||||
hass: HomeAssistant, config_entry: ConfigEntry, owproxy: MagicMock
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, owproxy: MagicMock
|
||||
) -> None:
|
||||
"""Test listing failure raises ConfigEntryNotReady."""
|
||||
owproxy.return_value.dir.side_effect = protocol.OwnetError()
|
||||
@ -42,7 +45,7 @@ async def test_listing_failure(
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("owproxy")
|
||||
async def test_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> None:
|
||||
async def test_unload_entry(hass: HomeAssistant, config_entry: MockConfigEntry) -> None:
|
||||
"""Test being able to unload an entry."""
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
@ -57,7 +60,7 @@ async def test_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> N
|
||||
|
||||
|
||||
async def test_update_options(
|
||||
hass: HomeAssistant, config_entry: ConfigEntry, owproxy: MagicMock
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, owproxy: MagicMock
|
||||
) -> None:
|
||||
"""Test update options triggers reload."""
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
@ -81,7 +84,7 @@ async def test_update_options(
|
||||
async def test_registry_cleanup(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: MockConfigEntry,
|
||||
owproxy: MagicMock,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
) -> None:
|
||||
|
@ -9,7 +9,6 @@ from pyownet.protocol import OwnetError
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
@ -17,6 +16,8 @@ from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
from . import setup_owproxy_mock_devices
|
||||
from .const import ATTR_INJECT_READS, MOCK_OWPROXY_DEVICES
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def override_platforms() -> Generator[None]:
|
||||
@ -27,7 +28,7 @@ def override_platforms() -> Generator[None]:
|
||||
|
||||
async def test_sensors(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: MockConfigEntry,
|
||||
owproxy: MagicMock,
|
||||
device_id: str,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
@ -66,7 +67,7 @@ async def test_sensors(
|
||||
@pytest.mark.parametrize("device_id", ["12.111111111111"])
|
||||
async def test_tai8570_sensors(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: MockConfigEntry,
|
||||
owproxy: MagicMock,
|
||||
device_id: str,
|
||||
entity_registry: er.EntityRegistry,
|
||||
|
@ -7,7 +7,6 @@ import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
SERVICE_TOGGLE,
|
||||
@ -20,6 +19,8 @@ from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
|
||||
from . import setup_owproxy_mock_devices
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def override_platforms() -> Generator[None]:
|
||||
@ -30,7 +31,7 @@ def override_platforms() -> Generator[None]:
|
||||
|
||||
async def test_switches(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: MockConfigEntry,
|
||||
owproxy: MagicMock,
|
||||
device_id: str,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
@ -70,7 +71,7 @@ async def test_switches(
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||
async def test_switch_toggle(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: MockConfigEntry,
|
||||
owproxy: MagicMock,
|
||||
device_id: str,
|
||||
) -> None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user