From 0874e359d47641911c6b800db33b673c9bfe063d Mon Sep 17 00:00:00 2001 From: Luke Bonaccorsi Date: Mon, 4 Sep 2023 12:37:11 +0100 Subject: [PATCH] Add error message for autodiscovery ports being used --- custom_components/robovac/tuyalocaldiscovery.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/custom_components/robovac/tuyalocaldiscovery.py b/custom_components/robovac/tuyalocaldiscovery.py index b3ca175..29994ae 100644 --- a/custom_components/robovac/tuyalocaldiscovery.py +++ b/custom_components/robovac/tuyalocaldiscovery.py @@ -11,6 +11,10 @@ _LOGGER = logging.getLogger(__name__) UDP_KEY = md5(b"yGAdlopoPVldABfn").digest() +class DiscoveryPortsNotAvailableException(Exception): + """This model is not supported""" + + class TuyaLocalDiscovery(asyncio.DatagramProtocol): def __init__(self, callback): self.devices = {} @@ -26,8 +30,13 @@ class TuyaLocalDiscovery(asyncio.DatagramProtocol): lambda: self, local_addr=("0.0.0.0", 6667), reuse_port=True ) - self._listeners = await asyncio.gather(listener, encrypted_listener) - _LOGGER.debug("Listening to broadcasts on UDP port 6666 and 6667") + try: + self._listeners = await asyncio.gather(listener, encrypted_listener) + _LOGGER.debug("Listening to broadcasts on UDP port 6666 and 6667") + except Exception as e: + raise DiscoveryPortsNotAvailableException( + "Ports 6666 and 6667 are needed for autodiscovery but are unavailable. This may be due to having the localtuya integration installed and it not allowing other integrations to use the same ports. A pull request has been raised to address this: https://github.com/rospogrigio/localtuya/pull/1481" + ) def close(self, *args, **kwargs): for transport, _ in self._listeners: