From 458cc838cf0566118a75aa047c94b46a934353fd Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 14 May 2024 20:21:50 +0200 Subject: [PATCH] Rename wemo coordinator module (#117437) --- homeassistant/components/wemo/__init__.py | 2 +- .../components/wemo/binary_sensor.py | 2 +- homeassistant/components/wemo/config_flow.py | 2 +- .../wemo/{wemo_device.py => coordinator.py} | 2 +- .../components/wemo/device_trigger.py | 2 +- homeassistant/components/wemo/entity.py | 2 +- homeassistant/components/wemo/fan.py | 2 +- homeassistant/components/wemo/light.py | 2 +- homeassistant/components/wemo/models.py | 2 +- homeassistant/components/wemo/sensor.py | 2 +- homeassistant/components/wemo/switch.py | 2 +- tests/components/wemo/entity_test_helpers.py | 8 +++---- tests/components/wemo/test_config_flow.py | 2 +- ...est_wemo_device.py => test_coordinator.py} | 21 +++++++++---------- 14 files changed, 26 insertions(+), 27 deletions(-) rename homeassistant/components/wemo/{wemo_device.py => coordinator.py} (99%) rename tests/components/wemo/{test_wemo_device.py => test_coordinator.py} (92%) diff --git a/homeassistant/components/wemo/__init__.py b/homeassistant/components/wemo/__init__.py index 97c487fc41d..822bf65fdc4 100644 --- a/homeassistant/components/wemo/__init__.py +++ b/homeassistant/components/wemo/__init__.py @@ -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. diff --git a/homeassistant/components/wemo/binary_sensor.py b/homeassistant/components/wemo/binary_sensor.py index 396a555e4f4..f2bcb04d96f 100644 --- a/homeassistant/components/wemo/binary_sensor.py +++ b/homeassistant/components/wemo/binary_sensor.py @@ -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( diff --git a/homeassistant/components/wemo/config_flow.py b/homeassistant/components/wemo/config_flow.py index 97a9eb34057..10a9bf5604b 100644 --- a/homeassistant/components/wemo/config_flow.py +++ b/homeassistant/components/wemo/config_flow.py @@ -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: diff --git a/homeassistant/components/wemo/wemo_device.py b/homeassistant/components/wemo/coordinator.py similarity index 99% rename from homeassistant/components/wemo/wemo_device.py rename to homeassistant/components/wemo/coordinator.py index fcecf1027a6..3e8d87d6300 100644 --- a/homeassistant/components/wemo/wemo_device.py +++ b/homeassistant/components/wemo/coordinator.py @@ -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 diff --git a/homeassistant/components/wemo/device_trigger.py b/homeassistant/components/wemo/device_trigger.py index d9cadcdd576..560c95523cd 100644 --- a/homeassistant/components/wemo/device_trigger.py +++ b/homeassistant/components/wemo/device_trigger.py @@ -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} diff --git a/homeassistant/components/wemo/entity.py b/homeassistant/components/wemo/entity.py index a6fe677d357..809ebcc7a1a 100644 --- a/homeassistant/components/wemo/entity.py +++ b/homeassistant/components/wemo/entity.py @@ -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__) diff --git a/homeassistant/components/wemo/fan.py b/homeassistant/components/wemo/fan.py index 89b20bdde25..3ef8aa67a3d 100644 --- a/homeassistant/components/wemo/fan.py +++ b/homeassistant/components/wemo/fan.py @@ -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 diff --git a/homeassistant/components/wemo/light.py b/homeassistant/components/wemo/light.py index 00c5204eba9..26dec417631 100644 --- a/homeassistant/components/wemo/light.py +++ b/homeassistant/components/wemo/light.py @@ -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 diff --git a/homeassistant/components/wemo/models.py b/homeassistant/components/wemo/models.py index ee12ccbf846..59de2d2152c 100644 --- a/homeassistant/components/wemo/models.py +++ b/homeassistant/components/wemo/models.py @@ -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 diff --git a/homeassistant/components/wemo/sensor.py b/homeassistant/components/wemo/sensor.py index 555e2591832..90e3546eaf7 100644 --- a/homeassistant/components/wemo/sensor.py +++ b/homeassistant/components/wemo/sensor.py @@ -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) diff --git a/homeassistant/components/wemo/switch.py b/homeassistant/components/wemo/switch.py index 14e3013afc1..3f7bb08b704 100644 --- a/homeassistant/components/wemo/switch.py +++ b/homeassistant/components/wemo/switch.py @@ -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 diff --git a/tests/components/wemo/entity_test_helpers.py b/tests/components/wemo/entity_test_helpers.py index fd2bbed4371..6700b00ec38 100644 --- a/tests/components/wemo/entity_test_helpers.py +++ b/tests/components/wemo/entity_test_helpers.py @@ -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) diff --git a/tests/components/wemo/test_config_flow.py b/tests/components/wemo/test_config_flow.py index 6eaa32b960e..1f89c26e4d1 100644 --- a/tests/components/wemo/test_config_flow.py +++ b/tests/components/wemo/test_config_flow.py @@ -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 diff --git a/tests/components/wemo/test_wemo_device.py b/tests/components/wemo/test_coordinator.py similarity index 92% rename from tests/components/wemo/test_wemo_device.py rename to tests/components/wemo/test_coordinator.py index 7d23b590b57..2ef096d2228 100644 --- a/tests/components/wemo/test_wemo_device.py +++ b/tests/components/wemo/test_coordinator.py @@ -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()