Skip to content

Commit

Permalink
Fix reuse_port unsupported on windows #273
Browse files Browse the repository at this point in the history
  • Loading branch information
xZetsubou committed Jun 24, 2024
1 parent a76f58a commit f9b7b99
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions custom_components/localtuya/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Maintained by @xZetsubou
"""

import os
import asyncio
import json
import logging
Expand Down Expand Up @@ -66,14 +67,15 @@ def __init__(self, callback=None):
async def start(self):
"""Start discovery by listening to broadcasts."""
loop = asyncio.get_running_loop()
op_reuse_port = {"reuse_port": True} if os.name != "nt" else {}
listener = loop.create_datagram_endpoint(
lambda: self, local_addr=("0.0.0.0", 6666), reuse_port=True
lambda: self, local_addr=("0.0.0.0", 6666), **op_reuse_port
)
encrypted_listener = loop.create_datagram_endpoint(
lambda: self, local_addr=("0.0.0.0", 6667), reuse_port=True
lambda: self, local_addr=("0.0.0.0", 6667), **op_reuse_port
)
# tuyaApp_encrypted_listener = loop.create_datagram_endpoint(
# lambda: self, local_addr=("0.0.0.0", 7000), reuse_port=True
# lambda: self, local_addr=("0.0.0.0", 7000), **op_reuse_port
# )
self._listeners = await asyncio.gather(listener, encrypted_listener)
_LOGGER.debug("Listening to broadcasts on UDP port 6666, 6667")
Expand Down

0 comments on commit f9b7b99

Please sign in to comment.