Skip to content

Commit 74db834

Browse files
authored
Small cleanups to the BaseManager (#35)
1 parent 874b43b commit 74db834

File tree

1 file changed

+26
-33
lines changed

1 file changed

+26
-33
lines changed

onvif/client.py

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -415,59 +415,48 @@ def closed(self) -> bool:
415415
"""Return True if the manager is closed."""
416416
return not self._subscription or self._subscription.transport.client.is_closed
417417

418-
@abstractmethod
419-
async def _start(self) -> float:
420-
"""Setup the processor.
421-
422-
Returns the next renewal call at time.
423-
424-
"""
425-
426-
async def _set_synchronization_point(self, service: ONVIFService) -> float:
427-
"""Set the synchronization point."""
428-
try:
429-
await service.SetSynchronizationPoint()
430-
except (Fault, asyncio.TimeoutError, TransportError, TypeError):
431-
logger.debug("%s: SetSynchronizationPoint failed", self._service.url)
432-
433418
async def start(self) -> None:
434-
"""Setup the notification processor."""
419+
"""Setup the manager."""
435420
renewal_call_at = await self._start()
436421
self._schedule_subscription_renew(renewal_call_at)
437422
return self._subscription
438423

439424
def pause(self) -> None:
440-
"""Pause the notification processor."""
425+
"""Pause the manager."""
441426
self._cancel_renewals()
442427

443428
def resume(self) -> None:
444-
"""Resume the notification processor."""
429+
"""Resume the manager."""
445430
self._schedule_subscription_renew(self._loop.time())
446431

447432
async def stop(self) -> None:
448-
"""Stop the notification processor."""
433+
"""Stop the manager."""
449434
logger.debug("%s: Stop the notification manager", self._device.host)
450435
self._cancel_renewals()
451436
assert self._subscription, "Call start first"
452437
await self._subscription.Unsubscribe()
453438

454439
async def shutdown(self) -> None:
455-
"""Shutdown the notification processor."""
440+
"""Shutdown the manager.
441+
442+
This method is irreversible.
443+
"""
456444
self._shutdown = True
457445
if self._restart_or_renew_task:
458446
self._restart_or_renew_task.cancel()
459447
logger.debug("%s: Shutdown the notification manager", self._device.host)
460448
await self.stop()
461449

462-
async def renew(self) -> float:
463-
"""Renew the notification subscription."""
464-
device = self._device
465-
logger.debug("%s: Renew the notification manager", device.host)
466-
return self._calculate_next_renewal_call_at(
467-
await self._subscription.Renew(
468-
device.get_next_termination_time(self._interval)
469-
)
470-
)
450+
@abstractmethod
451+
async def _start(self) -> float:
452+
"""Setup the processor. Returns the next renewal call at time."""
453+
454+
async def _set_synchronization_point(self, service: ONVIFService) -> float:
455+
"""Set the synchronization point."""
456+
try:
457+
await service.SetSynchronizationPoint()
458+
except (Fault, asyncio.TimeoutError, TransportError, TypeError):
459+
logger.debug("%s: SetSynchronizationPoint failed", self._service.url)
471460

472461
def _cancel_renewals(self) -> None:
473462
"""Cancel any pending renewals."""
@@ -516,7 +505,13 @@ async def _restart_subscription(self) -> bool:
516505
@retry_connection_error()
517506
async def _call_subscription_renew(self) -> float:
518507
"""Call notify subscription Renew."""
519-
return await self.renew()
508+
device = self._device
509+
logger.debug("%s: Renew the notification manager", device.host)
510+
return self._calculate_next_renewal_call_at(
511+
await self._subscription.Renew(
512+
device.get_next_termination_time(self._interval)
513+
)
514+
)
520515

521516
async def _renew_subscription(self) -> float | None:
522517
"""Renew notify subscription."""
@@ -533,9 +528,7 @@ async def _renew_subscription(self) -> float | None:
533528
)
534529
return None
535530

536-
async def _renew_or_restart_subscription(
537-
self, now: dt.datetime | None = None
538-
) -> None:
531+
async def _renew_or_restart_subscription(self) -> None:
539532
"""Renew or start notify subscription."""
540533
if self._shutdown:
541534
return

0 commit comments

Comments
 (0)