diff --git a/custom_components/tuya_local/device.py b/custom_components/tuya_local/device.py index 1d333c58a0..79a3b30d43 100644 --- a/custom_components/tuya_local/device.py +++ b/custom_components/tuya_local/device.py @@ -3,6 +3,7 @@ """ import asyncio +from asyncio.exceptions import CancelledError import logging from threading import Lock from time import time @@ -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.""" @@ -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)