Skip to content

Commit 8bbe767

Browse files
authored
Make set_synchronization_point a public function since it needs to be called after webhook setup (#39)
1 parent 6271bc6 commit 8bbe767

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

onvif/managers.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def __init__(
5252
self._shutdown = False
5353
self._subscription_lost_callback = subscription_lost_callback
5454
self._cancel_subscription_renew: asyncio.TimerHandle | None = None
55+
self._service: ONVIFService | None = None
5556

5657
@property
5758
def closed(self) -> bool:
@@ -94,10 +95,10 @@ async def shutdown(self) -> None:
9495
async def _start(self) -> float:
9596
"""Setup the processor. Returns the next renewal call at time."""
9697

97-
async def _set_synchronization_point(self, service: ONVIFService) -> float:
98+
async def set_synchronization_point(self) -> float:
9899
"""Set the synchronization point."""
99100
try:
100-
await service.SetSynchronizationPoint()
101+
await self._service.SetSynchronizationPoint()
101102
except (Fault, asyncio.TimeoutError, TransportError, TypeError):
102103
logger.debug("%s: SetSynchronizationPoint failed", self._service.url)
103104

@@ -229,12 +230,12 @@ async def _start(self) -> float:
229230
#
230231
# If this fails this is OK as it just means we will switch
231232
# to webhook later when the first notification is received.
232-
service = await self._device.create_onvif_service(
233+
self._service = await self._device.create_onvif_service(
233234
"pullpoint", port_type="NotificationConsumer"
234235
)
235-
self._operation = service.document.bindings[service.binding_name].get(
236-
"PullMessages"
237-
)
236+
self._operation = self._service.document.bindings[
237+
self._service.binding_name
238+
].get("PullMessages")
238239
self._subscription = await device.create_subscription_service(
239240
"NotificationConsumer"
240241
)
@@ -250,7 +251,6 @@ async def _start(self) -> float:
250251
)
251252
renewal_call_at = self._calculate_next_renewal_call_at(result)
252253
logger.debug("%s: Start the notification manager", self._device.host)
253-
await self._set_synchronization_point(service)
254254
return renewal_call_at
255255

256256
def process(self, content: bytes) -> Any | None:
@@ -273,16 +273,6 @@ def process(self, content: bytes) -> Any | None:
273273
class PullPointManager(BaseManager):
274274
"""Manager for PullPoint."""
275275

276-
def __init__(
277-
self,
278-
device: ONVIFCamera,
279-
interval: dt.timedelta,
280-
subscription_lost_callback: Callable[[], None],
281-
) -> None:
282-
"""Initialize the PullPoint processor."""
283-
super().__init__(device, interval, subscription_lost_callback)
284-
self._service: ONVIFService | None = None
285-
286276
async def _start(self) -> float:
287277
"""Start the PullPoint manager.
288278
@@ -318,7 +308,6 @@ async def _start(self) -> float:
318308
)
319309
renewal_call_at = self._calculate_next_renewal_call_at(result)
320310
logger.debug("%s: Start the notification manager", self._device.host)
321-
await self._set_synchronization_point(self._service)
322311
return renewal_call_at
323312

324313
def get_service(self) -> ONVIFService:

0 commit comments

Comments
 (0)