From ef2f4f1ab22b8bd43b3f61cb2cf8c28a8d59c3f1 Mon Sep 17 00:00:00 2001 From: Violet Shreve Date: Sun, 1 Dec 2024 21:57:24 -0500 Subject: [PATCH] Use the IP address resolved by the transport Hostname destination support fails because asyncio's DatagramTransport internally resolves hostnames to IP addresses and expects any call to sendto() to use that IP instead of the input hostname. This commit recognizes that resolution may have happened and updates self.ip and self.port to match the resolved address. --- pywizlight/bulb.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pywizlight/bulb.py b/pywizlight/bulb.py index e5ba2ea..d9b7b7e 100755 --- a/pywizlight/bulb.py +++ b/pywizlight/bulb.py @@ -484,6 +484,12 @@ async def _ensure_connection(self) -> None: self.transport = cast(asyncio.DatagramTransport, transport_proto[0]) self.protocol = cast(WizProtocol, transport_proto[1]) + # The transport expects us to send to the same address we connected to here + ip, port = self.transport.get_extra_info("peername") + if (self.ip, self.port) != (ip, port): + _LOGGER.debug("Resolved %s:%s to %s:%s", self.ip, self.port, ip, port) + self.ip, self.port = ip, port + def register(self) -> None: """Call register to keep alive push updates.""" if self.push_running: