From 87349c35f47b1c7390090cc0e6912bc96b9f93bf Mon Sep 17 00:00:00 2001 From: infy1995 Date: Mon, 23 Nov 2026 09:43:34 +0100 Subject: [PATCH] chore(v1): drop the duplicate status read-back close test Follow-up to #1067, where the maintainer noted that test_init.py is redundant because test_status.py already covers closing the status trait. Closing through PropertiesApi.close() is now covered in test_status.py as well. --- tests/devices/traits/v1/test_init.py | 55 -------------------------- tests/devices/traits/v1/test_status.py | 12 ++++++ 2 files changed, 12 insertions(+), 55 deletions(-) delete mode 100644 tests/devices/traits/v1/test_init.py diff --git a/tests/devices/traits/v1/test_init.py b/tests/devices/traits/v1/test_init.py deleted file mode 100644 index 23299efe6..000000000 --- a/tests/devices/traits/v1/test_init.py +++ /dev/null @@ -1,55 +0,0 @@ -"""Tests for the V1 trait properties API.""" - -import asyncio -from collections.abc import Callable -from typing import Any -from unittest.mock import AsyncMock, Mock - -import pytest - -from roborock.data import HomeData, HomeDataDevice, HomeDataProduct -from roborock.devices.cache import DeviceCache -from roborock.devices.traits import v1 -from roborock.devices.traits.v1 import status as status_module -from roborock.roborock_message import RoborockDataProtocol - -DELAY = 0.01 - - -async def test_close_cancels_status_read_back( - device_info: HomeDataDevice, - products: list[HomeDataProduct], - trait_home_data: HomeData, - device_cache: DeviceCache, - monkeypatch: pytest.MonkeyPatch, -) -> None: - """Closing the properties API stops a status read-back that a push scheduled.""" - monkeypatch.setattr(status_module, "_STATUS_REFRESH_DELAY", DELAY) - product = next(p for p in products if p.id == device_info.product_id) - listeners: list[Callable[[dict[RoborockDataProtocol, Any]], None]] = [] - - def add_dps_listener(listener: Callable[[dict[RoborockDataProtocol, Any]], None]) -> Callable[[], None]: - listeners.append(listener) - return Mock() - - api = v1.create( - device_info.duid, - product, - trait_home_data, - AsyncMock(), - AsyncMock(), - AsyncMock(), - AsyncMock(), - add_dps_listener, - AsyncMock(), - device_cache=device_cache, - ) - api.discover_features = AsyncMock() # type: ignore[method-assign] - api.status.refresh_and_notify = AsyncMock() # type: ignore[method-assign] - await api.start() - - listeners[0]({RoborockDataProtocol.FAN_POWER: 101}) - api.close() - - await asyncio.sleep(DELAY * 8) - api.status.refresh_and_notify.assert_not_awaited() # type: ignore[attr-defined] diff --git a/tests/devices/traits/v1/test_status.py b/tests/devices/traits/v1/test_status.py index bfd0a08c5..c8e63e4cc 100644 --- a/tests/devices/traits/v1/test_status.py +++ b/tests/devices/traits/v1/test_status.py @@ -1207,6 +1207,18 @@ async def test_close_cancels_pending_read_back(status_trait: StatusTrait, read_b status_trait.refresh_and_notify.assert_not_awaited() # type: ignore[attr-defined] +async def test_properties_api_close_cancels_pending_read_back( + device: RoborockDevice, status_trait: StatusTrait, read_back: asyncio.Event +) -> None: + """Closing the properties API stops a read-back that a push scheduled.""" + assert device.v1_properties + status_trait.update_from_dps({RoborockDataProtocol.FAN_POWER: 101}) + device.v1_properties.close() + + await asyncio.sleep(READ_BACK_SETTLE) + status_trait.refresh_and_notify.assert_not_awaited() # type: ignore[attr-defined] + + async def test_close_cancels_in_flight_read_back(status_trait: StatusTrait, read_back: asyncio.Event) -> None: """Closing while a read-back is running cancels it.""" started = asyncio.Event()