mirror of
https://github.com/home-assistant/core.git
synced 2025-08-13 17:45:19 +02:00
Improve type hints in wemo tests (#123923)
* Improve type hints in wemo tests * typo
This commit is contained in:
@@ -1,13 +1,15 @@
|
|||||||
"""Fixtures for pywemo."""
|
"""Fixtures for pywemo."""
|
||||||
|
|
||||||
|
from collections.abc import Generator
|
||||||
import contextlib
|
import contextlib
|
||||||
from unittest.mock import create_autospec, patch
|
from unittest.mock import MagicMock, create_autospec, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import pywemo
|
import pywemo
|
||||||
|
|
||||||
from homeassistant.components.wemo import CONF_DISCOVERY, CONF_STATIC
|
from homeassistant.components.wemo import CONF_DISCOVERY, CONF_STATIC
|
||||||
from homeassistant.components.wemo.const import DOMAIN
|
from homeassistant.components.wemo.const import DOMAIN
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
@@ -22,13 +24,13 @@ MOCK_INSIGHT_STATE_THRESHOLD_POWER = 8.0
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="pywemo_model")
|
@pytest.fixture(name="pywemo_model")
|
||||||
def pywemo_model_fixture():
|
def pywemo_model_fixture() -> str:
|
||||||
"""Fixture containing a pywemo class name used by pywemo_device_fixture."""
|
"""Fixture containing a pywemo class name used by pywemo_device_fixture."""
|
||||||
return "LightSwitch"
|
return "LightSwitch"
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="pywemo_registry", autouse=True)
|
@pytest.fixture(name="pywemo_registry", autouse=True)
|
||||||
async def async_pywemo_registry_fixture():
|
def async_pywemo_registry_fixture() -> Generator[MagicMock]:
|
||||||
"""Fixture for SubscriptionRegistry instances."""
|
"""Fixture for SubscriptionRegistry instances."""
|
||||||
registry = create_autospec(pywemo.SubscriptionRegistry, instance=True)
|
registry = create_autospec(pywemo.SubscriptionRegistry, instance=True)
|
||||||
|
|
||||||
@@ -52,7 +54,9 @@ def pywemo_discovery_responder_fixture():
|
|||||||
|
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def create_pywemo_device(pywemo_registry, pywemo_model):
|
def create_pywemo_device(
|
||||||
|
pywemo_registry: MagicMock, pywemo_model: str
|
||||||
|
) -> pywemo.WeMoDevice:
|
||||||
"""Create a WeMoDevice instance."""
|
"""Create a WeMoDevice instance."""
|
||||||
cls = getattr(pywemo, pywemo_model)
|
cls = getattr(pywemo, pywemo_model)
|
||||||
device = create_autospec(cls, instance=True)
|
device = create_autospec(cls, instance=True)
|
||||||
@@ -90,14 +94,18 @@ def create_pywemo_device(pywemo_registry, pywemo_model):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="pywemo_device")
|
@pytest.fixture(name="pywemo_device")
|
||||||
def pywemo_device_fixture(pywemo_registry, pywemo_model):
|
def pywemo_device_fixture(
|
||||||
|
pywemo_registry: MagicMock, pywemo_model: str
|
||||||
|
) -> Generator[pywemo.WeMoDevice]:
|
||||||
"""Fixture for WeMoDevice instances."""
|
"""Fixture for WeMoDevice instances."""
|
||||||
with create_pywemo_device(pywemo_registry, pywemo_model) as pywemo_device:
|
with create_pywemo_device(pywemo_registry, pywemo_model) as pywemo_device:
|
||||||
yield pywemo_device
|
yield pywemo_device
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="pywemo_dli_device")
|
@pytest.fixture(name="pywemo_dli_device")
|
||||||
def pywemo_dli_device_fixture(pywemo_registry, pywemo_model):
|
def pywemo_dli_device_fixture(
|
||||||
|
pywemo_registry: MagicMock, pywemo_model: str
|
||||||
|
) -> Generator[pywemo.WeMoDevice]:
|
||||||
"""Fixture for Digital Loggers emulated instances."""
|
"""Fixture for Digital Loggers emulated instances."""
|
||||||
with create_pywemo_device(pywemo_registry, pywemo_model) as pywemo_dli_device:
|
with create_pywemo_device(pywemo_registry, pywemo_model) as pywemo_dli_device:
|
||||||
pywemo_dli_device.model_name = "DLI emulated Belkin Socket"
|
pywemo_dli_device.model_name = "DLI emulated Belkin Socket"
|
||||||
@@ -106,12 +114,14 @@ def pywemo_dli_device_fixture(pywemo_registry, pywemo_model):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="wemo_entity_suffix")
|
@pytest.fixture(name="wemo_entity_suffix")
|
||||||
def wemo_entity_suffix_fixture():
|
def wemo_entity_suffix_fixture() -> str:
|
||||||
"""Fixture to select a specific entity for wemo_entity."""
|
"""Fixture to select a specific entity for wemo_entity."""
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
async def async_create_wemo_entity(hass, pywemo_device, wemo_entity_suffix):
|
async def async_create_wemo_entity(
|
||||||
|
hass: HomeAssistant, pywemo_device: pywemo.WeMoDevice, wemo_entity_suffix: str
|
||||||
|
) -> er.RegistryEntry | None:
|
||||||
"""Create a hass entity for a wemo device."""
|
"""Create a hass entity for a wemo device."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
@@ -134,12 +144,16 @@ async def async_create_wemo_entity(hass, pywemo_device, wemo_entity_suffix):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="wemo_entity")
|
@pytest.fixture(name="wemo_entity")
|
||||||
async def async_wemo_entity_fixture(hass, pywemo_device, wemo_entity_suffix):
|
async def async_wemo_entity_fixture(
|
||||||
|
hass: HomeAssistant, pywemo_device: pywemo.WeMoDevice, wemo_entity_suffix: str
|
||||||
|
) -> er.RegistryEntry | None:
|
||||||
"""Fixture for a Wemo entity in hass."""
|
"""Fixture for a Wemo entity in hass."""
|
||||||
return await async_create_wemo_entity(hass, pywemo_device, wemo_entity_suffix)
|
return await async_create_wemo_entity(hass, pywemo_device, wemo_entity_suffix)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="wemo_dli_entity")
|
@pytest.fixture(name="wemo_dli_entity")
|
||||||
async def async_wemo_dli_entity_fixture(hass, pywemo_dli_device, wemo_entity_suffix):
|
async def async_wemo_dli_entity_fixture(
|
||||||
|
hass: HomeAssistant, pywemo_dli_device: pywemo.WeMoDevice, wemo_entity_suffix: str
|
||||||
|
) -> er.RegistryEntry | None:
|
||||||
"""Fixture for a Wemo entity in hass."""
|
"""Fixture for a Wemo entity in hass."""
|
||||||
return await async_create_wemo_entity(hass, pywemo_dli_device, wemo_entity_suffix)
|
return await async_create_wemo_entity(hass, pywemo_dli_device, wemo_entity_suffix)
|
||||||
|
Reference in New Issue
Block a user