Skip to content

Commit

Permalink
Use the IP address resolved by the transport
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
shreve committed Dec 2, 2024
1 parent 6c6e4a2 commit ef2f4f1
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pywizlight/bulb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit ef2f4f1

Please sign in to comment.