Skip to content

Commit 9d8d206

Browse files
committed
reintegrate delay_task call in order to let awake response finish first, otherwise the message sending queue crashes.
Remove node_ping as this was not benificial
1 parent 0227af4 commit 9d8d206

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

plugwise_usb/nodes/scan.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,13 +423,11 @@ async def _motion_state_update(
423423
]
424424
)
425425

426-
async def _run_awake_tasks(self) -> bool:
426+
async def _run_awake_tasks(self) -> None:
427427
"""Execute all awake tasks."""
428-
if not await super()._run_awake_tasks():
429-
return False
428+
await super()._run_awake_tasks()
430429
if self._motion_config.dirty:
431430
await self._configure_scan_task()
432-
return True
433431

434432
async def _configure_scan_task(self) -> bool:
435433
"""Configure Scan device settings. Returns True if successful."""

plugwise_usb/nodes/sed.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def __init__(
9191
# Configure SED
9292
self._battery_config = BatteryConfig()
9393
self._sed_node_info_update_task_scheduled = False
94+
self._delayed_task: Task[None] | None = None
9495

9596
self._last_awake: dict[NodeAwakeResponseType, datetime] = {}
9697
self._last_awake_reason: str = "Unknown"
@@ -123,6 +124,8 @@ async def unload(self) -> None:
123124
await self._awake_timer_task
124125
if self._awake_subscription is not None:
125126
self._awake_subscription()
127+
if self._delayed_task is not None and not self._delayed_task.done():
128+
await self._delayed_task
126129
await super().unload()
127130

128131
async def initialize(self) -> None:
@@ -420,7 +423,6 @@ async def _awake_response(self, response: PlugwiseResponse) -> bool:
420423
):
421424
return True
422425

423-
await self._run_awake_tasks()
424426
self._last_awake[response.awake_type] = response.timestamp
425427

426428
tasks: list[Coroutine[Any, Any, None]] = [
@@ -431,10 +433,12 @@ async def _awake_response(self, response: PlugwiseResponse) -> bool:
431433
),
432434
self.save_cache(),
433435
]
436+
self._delayed_task = self._loop.create_task(
437+
self._run_awake_tasks(), name=f"Delayed update for {self._mac_in_str}"
438+
)
434439
if response.awake_type == NodeAwakeResponseType.MAINTENANCE:
435440
self._last_awake_reason = "Maintenance"
436441
self._set_cache(CACHE_SED_AWAKE_REASON, "Maintenance")
437-
438442
if not self._maintenance_interval_restored_from_cache:
439443
self._detect_maintenance_interval(response.timestamp)
440444
if self._ping_at_awake:
@@ -543,6 +547,7 @@ async def _awake_timer(self) -> None:
543547

544548
async def _run_awake_tasks(self) -> None:
545549
"""Execute all awake tasks."""
550+
_LOGGER.debug("_run_awake_tasks | Device %s",self.name)
546551
if (
547552
self._sed_node_info_update_task_scheduled
548553
and await self.node_info_update(None) is not None

0 commit comments

Comments
 (0)