Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions custom_components/xtend_tuya/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
"""Support for Tuya Smart devices."""

import socket

# save the original DNS lookup function
_original_getaddrinfo = socket.getaddrinfo

def _getaddrinfo_ipv4_only(host, port, family=0, type=0, proto=0, flags=0):
"""
IPv6 sniper: If the request is going to a tuya server,
force it to use IPv4 (AF_INET) to prevent IPv6 timeout
"""
if host and ("tuya" in host or "tinytuya" in host):
return _original_getaddrinfo(host, port, socket.AF_INET, type, proto, flags)
return _original_getaddrinfo(host, port, family, type, proto, flags)

# Replace the global function with the sniper
socket.getaddrinfo = _getaddrinfo_ipv4_only

from __future__ import annotations
import logging
import asyncio
Expand Down