From fb81459133df8ecd96c5ec0d8423b4bf10cf072f Mon Sep 17 00:00:00 2001 From: fuatakgun Date: Sat, 25 Nov 2023 10:44:51 +0100 Subject: [PATCH] feat: recover p2p? --- .../eufy_security/eufy_security_api/camera.py | 10 +++++++++- .../eufy_security/eufy_security_api/p2p_streamer.py | 12 +++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/custom_components/eufy_security/eufy_security_api/camera.py b/custom_components/eufy_security/eufy_security_api/camera.py index eec2946..fe4373e 100644 --- a/custom_components/eufy_security/eufy_security_api/camera.py +++ b/custom_components/eufy_security/eufy_security_api/camera.py @@ -140,9 +140,17 @@ async def start_livestream(self) -> bool: self.stream_status = StreamStatus.STREAMING return True - async def check_and_stop_livestream(self): + async def check_and_stop_livestream(self, retry: bool): + _LOGGER.debug(f"check_and_stop_livestream - start - {retry}") if self.stream_status != StreamStatus.IDLE: await self.stop_livestream() + _LOGGER.debug(f"check_and_stop_livestream - cont - {retry}") + if retry is True: + _LOGGER.debug(f"check_and_stop_livestream - sleep 5 seconds - {retry}") + await asyncio.sleep(5) + _LOGGER.debug(f"check_and_stop_livestream - start live stream finish - {retry}") + await self.start_livestream() + _LOGGER.debug(f"check_and_stop_livestream - start live stream end - {retry}") async def stop_livestream(self): """Process stop p2p livestream call""" diff --git a/custom_components/eufy_security/eufy_security_api/p2p_streamer.py b/custom_components/eufy_security/eufy_security_api/p2p_streamer.py index 459c468..dc56f6b 100644 --- a/custom_components/eufy_security/eufy_security_api/p2p_streamer.py +++ b/custom_components/eufy_security/eufy_security_api/p2p_streamer.py @@ -85,13 +85,7 @@ async def start(self): p2p_thread.start() #asyncio.new_event_loop().create_task(self.write_bytes(self.camera.audio_queue)) - - async def stop(self): - await self.camera.check_and_stop_livestream() - - async def stop(self, retry: boolean): - await self.camera.check_and_stop_livestream() - await asyncio.sleep(5) - if retry is True: - await self.camera.start_livestream() + async def stop(self, retry): + _LOGGER.debug(f"p2p - initiate stop - {retry}") + await self.camera.check_and_stop_livestream(retry)