Skip to content

Commit

Permalink
Rename wemo coordinator module (#117437)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet committed May 14, 2024
1 parent 223bf99 commit 458cc83
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 27 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/wemo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
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.
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/wemo/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
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(
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/wemo/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def __post_init__(self) -> None:
)


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
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/wemo/device_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
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}

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/wemo/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
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__)

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/wemo/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

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
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/wemo/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

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
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/wemo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

if TYPE_CHECKING: # Avoid circular dependencies.
from . import HostPortTuple, WemoDiscovery, WemoDispatcher
from .wemo_device import DeviceCoordinator
from .coordinator import DeviceCoordinator


@dataclass
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/wemo/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
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)
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/wemo/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
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
Expand Down
8 changes: 4 additions & 4 deletions tests/components/wemo/entity_test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
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,
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/components/wemo/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
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
Expand Down Expand Up @@ -50,15 +51,15 @@ 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


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 = {}

Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down

0 comments on commit 458cc83

Please sign in to comment.