Skip to content

Commit

Permalink
Handle CancelledError when stopping
Browse files Browse the repository at this point in the history
When stopping the integration, we expect that a CancelledError will
be thrown, so catch it and continue as normal.

Issue #1974
  • Loading branch information
make-all committed Jun 4, 2024
1 parent a5f9b28 commit 0b691a7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions custom_components/tuya_local/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import asyncio
from asyncio.exceptions import CancelledError
import logging
from threading import Lock
from time import time
Expand Down Expand Up @@ -191,7 +192,10 @@ def register_entity(self, entity):
async def async_unregister_entity(self, entity):
self._children.remove(entity)
if not self._children:
await self.async_stop()
try:
await self.async_stop()
except CancelledError:
pass

async def receive_loop(self):
"""Coroutine wrapper for async_receive generator."""
Expand Down Expand Up @@ -320,7 +324,7 @@ async def async_receive(self):

await asyncio.sleep(0.1 if self.has_returned_state else 5)

except asyncio.CancelledError:
except CancelledError:
self._running = False
# Close the persistent connection when exiting the loop
self._api.set_socketPersistent(False)
Expand Down

0 comments on commit 0b691a7

Please sign in to comment.