Rename wemo coordinator module (#117437)

This commit is contained in:
epenet 2024-05-14 20:21:50 +02:00 committed by GitHub
parent 223bf99ac9
commit 458cc838cf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 26 additions and 27 deletions

View file

@ -20,8 +20,8 @@ from homeassistant.helpers.typing import ConfigType
from homeassistant.util.async_ import gather_with_limited_concurrency
from .const import DOMAIN
from .coordinator import DeviceCoordinator, async_register_device
from .models import WemoConfigEntryData, WemoData, async_wemo_data
from .wemo_device import DeviceCoordinator, async_register_device
# Max number of devices to initialize at once. This limit is in place to
# avoid tying up too many executor threads with WeMo device setup.

View file

@ -8,8 +8,8 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import async_wemo_dispatcher_connect
from .coordinator import DeviceCoordinator
from .entity import WemoBinaryStateEntity, WemoEntity
from .wemo_device import DeviceCoordinator
async def async_setup_entry(

View file

@ -13,7 +13,7 @@ from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.config_entry_flow import DiscoveryFlowHandler
from .const import DOMAIN
from .wemo_device import Options, OptionsValidationError
from .coordinator import Options, OptionsValidationError
async def _async_has_devices(hass: HomeAssistant) -> bool:

View file

@ -88,7 +88,7 @@ class Options:
)
class DeviceCoordinator(DataUpdateCoordinator[None]): # pylint: disable=hass-enforce-coordinator-module
class DeviceCoordinator(DataUpdateCoordinator[None]):
"""Home Assistant wrapper for a pyWeMo device."""
options: Options | None = None

View file

@ -13,7 +13,7 @@ from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
from homeassistant.helpers.typing import ConfigType
from .const import DOMAIN as WEMO_DOMAIN, WEMO_SUBSCRIPTION_EVENT
from .wemo_device import async_get_coordinator
from .coordinator import async_get_coordinator
TRIGGER_TYPES = {EVENT_TYPE_LONG_PRESS}

View file

@ -11,7 +11,7 @@ from pywemo.exceptions import ActionException
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .wemo_device import DeviceCoordinator
from .coordinator import DeviceCoordinator
_LOGGER = logging.getLogger(__name__)

View file

@ -22,8 +22,8 @@ from homeassistant.util.scaling import int_states_in_range
from . import async_wemo_dispatcher_connect
from .const import SERVICE_RESET_FILTER_LIFE, SERVICE_SET_HUMIDITY
from .coordinator import DeviceCoordinator
from .entity import WemoBinaryStateEntity
from .wemo_device import DeviceCoordinator
SCAN_INTERVAL = timedelta(seconds=10)
PARALLEL_UPDATES = 0

View file

@ -23,8 +23,8 @@ import homeassistant.util.color as color_util
from . import async_wemo_dispatcher_connect
from .const import DOMAIN as WEMO_DOMAIN
from .coordinator import DeviceCoordinator
from .entity import WemoBinaryStateEntity, WemoEntity
from .wemo_device import DeviceCoordinator
# The WEMO_ constants below come from pywemo itself
WEMO_OFF = 0

View file

@ -12,7 +12,7 @@ from .const import DOMAIN
if TYPE_CHECKING: # Avoid circular dependencies.
from . import HostPortTuple, WemoDiscovery, WemoDispatcher
from .wemo_device import DeviceCoordinator
from .coordinator import DeviceCoordinator
@dataclass

View file

@ -19,8 +19,8 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType
from . import async_wemo_dispatcher_connect
from .coordinator import DeviceCoordinator
from .entity import WemoEntity
from .wemo_device import DeviceCoordinator
@dataclass(frozen=True)

View file

@ -14,8 +14,8 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import async_wemo_dispatcher_connect
from .coordinator import DeviceCoordinator
from .entity import WemoBinaryStateEntity
from .wemo_device import DeviceCoordinator
SCAN_INTERVAL = timedelta(seconds=10)
PARALLEL_UPDATES = 0

View file

@ -7,7 +7,7 @@ import asyncio
import threading
from homeassistant.components.homeassistant import DOMAIN as HA_DOMAIN
from homeassistant.components.wemo import wemo_device
from homeassistant.components.wemo.coordinator import async_get_coordinator
from homeassistant.const import (
ATTR_ENTITY_ID,
SERVICE_TURN_OFF,
@ -94,7 +94,7 @@ async def test_async_update_locked_callback_and_update(
When a state update is received via a callback from the device at the same time
as hass is calling `async_update`, verify that only one of the updates proceeds.
"""
coordinator = wemo_device.async_get_coordinator(hass, wemo_entity.device_id)
coordinator = async_get_coordinator(hass, wemo_entity.device_id)
await async_setup_component(hass, HA_DOMAIN, {})
callback = _perform_registry_callback(coordinator)
update = _perform_async_update(coordinator)
@ -105,7 +105,7 @@ async def test_async_update_locked_multiple_updates(
hass: HomeAssistant, pywemo_device, wemo_entity
) -> None:
"""Test that two hass async_update state updates do not proceed at the same time."""
coordinator = wemo_device.async_get_coordinator(hass, wemo_entity.device_id)
coordinator = async_get_coordinator(hass, wemo_entity.device_id)
await async_setup_component(hass, HA_DOMAIN, {})
update = _perform_async_update(coordinator)
await _async_multiple_call_helper(hass, pywemo_device, update, update)
@ -115,7 +115,7 @@ async def test_async_update_locked_multiple_callbacks(
hass: HomeAssistant, pywemo_device, wemo_entity
) -> None:
"""Test that two device callback state updates do not proceed at the same time."""
coordinator = wemo_device.async_get_coordinator(hass, wemo_entity.device_id)
coordinator = async_get_coordinator(hass, wemo_entity.device_id)
await async_setup_component(hass, HA_DOMAIN, {})
callback = _perform_registry_callback(coordinator)
await _async_multiple_call_helper(hass, pywemo_device, callback, callback)

View file

@ -3,7 +3,7 @@
from dataclasses import asdict
from homeassistant.components.wemo.const import DOMAIN
from homeassistant.components.wemo.wemo_device import Options
from homeassistant.components.wemo.coordinator import Options
from homeassistant.config_entries import SOURCE_USER
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType

View file

@ -10,8 +10,9 @@ from pywemo.exceptions import ActionException, PyWeMoException
from pywemo.subscribe import EVENT_TYPE_LONG_PRESS
from homeassistant import runner
from homeassistant.components.wemo import CONF_DISCOVERY, CONF_STATIC, wemo_device
from homeassistant.components.wemo import CONF_DISCOVERY, CONF_STATIC
from homeassistant.components.wemo.const import DOMAIN, WEMO_SUBSCRIPTION_EVENT
from homeassistant.components.wemo.coordinator import Options, async_get_coordinator
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.update_coordinator import UpdateFailed
@ -50,7 +51,7 @@ async def test_async_register_device_longpress_fails(
await hass.async_block_till_done()
device_entries = list(device_registry.devices.values())
assert len(device_entries) == 1
device = wemo_device.async_get_coordinator(hass, device_entries[0].id)
device = async_get_coordinator(hass, device_entries[0].id)
assert device.supports_long_press is False
@ -58,7 +59,7 @@ async def test_long_press_event(
hass: HomeAssistant, pywemo_registry, wemo_entity
) -> None:
"""Device fires a long press event."""
device = wemo_device.async_get_coordinator(hass, wemo_entity.device_id)
device = async_get_coordinator(hass, wemo_entity.device_id)
got_event = asyncio.Event()
event_data = {}
@ -93,7 +94,7 @@ async def test_subscription_callback(
hass: HomeAssistant, pywemo_registry, wemo_entity
) -> None:
"""Device processes a registry subscription callback."""
device = wemo_device.async_get_coordinator(hass, wemo_entity.device_id)
device = async_get_coordinator(hass, wemo_entity.device_id)
device.last_update_success = False
got_callback = asyncio.Event()
@ -117,7 +118,7 @@ async def test_subscription_update_action_exception(
hass: HomeAssistant, pywemo_device, wemo_entity
) -> None:
"""Device handles ActionException on get_state properly."""
device = wemo_device.async_get_coordinator(hass, wemo_entity.device_id)
device = async_get_coordinator(hass, wemo_entity.device_id)
device.last_update_success = True
pywemo_device.subscription_update.return_value = False
@ -137,7 +138,7 @@ async def test_subscription_update_exception(
hass: HomeAssistant, pywemo_device, wemo_entity
) -> None:
"""Device handles Exception on get_state properly."""
device = wemo_device.async_get_coordinator(hass, wemo_entity.device_id)
device = async_get_coordinator(hass, wemo_entity.device_id)
device.last_update_success = True
pywemo_device.subscription_update.return_value = False
@ -157,7 +158,7 @@ async def test_async_update_data_subscribed(
hass: HomeAssistant, pywemo_registry, pywemo_device, wemo_entity
) -> None:
"""No update happens when the device is subscribed."""
device = wemo_device.async_get_coordinator(hass, wemo_entity.device_id)
device = async_get_coordinator(hass, wemo_entity.device_id)
pywemo_registry.is_subscribed.return_value = True
pywemo_device.get_state.reset_mock()
await device._async_update_data()
@ -196,9 +197,7 @@ async def test_options_enable_subscription_false(
config_entry = hass.config_entries.async_get_entry(wemo_entity.config_entry_id)
assert hass.config_entries.async_update_entry(
config_entry,
options=asdict(
wemo_device.Options(enable_subscription=False, enable_long_press=False)
),
options=asdict(Options(enable_subscription=False, enable_long_press=False)),
)
await hass.async_block_till_done()
pywemo_registry.unregister.assert_called_once_with(pywemo_device)
@ -208,7 +207,7 @@ async def test_options_enable_long_press_false(hass, pywemo_device, wemo_entity)
"""Test setting Options.enable_long_press = False."""
config_entry = hass.config_entries.async_get_entry(wemo_entity.config_entry_id)
assert hass.config_entries.async_update_entry(
config_entry, options=asdict(wemo_device.Options(enable_long_press=False))
config_entry, options=asdict(Options(enable_long_press=False))
)
await hass.async_block_till_done()
pywemo_device.remove_long_press_virtual_device.assert_called_once_with()