Add support for DNS host names (#104)

This commit is contained in:
K Henriksson
2018-01-17 13:03:19 -08:00
committed by Teemu R
parent a426488449
commit d40fff4f9e
7 changed files with 37 additions and 31 deletions

View File

@@ -32,7 +32,7 @@ class TPLinkSmartHomeProtocol:
Request information from a TP-Link SmartHome Device and return the
response.
:param str host: ip address of the device
:param str host: host name or ip address of the device
:param int port: port on the device (default: 9999)
:param request: command to send to the device (can be either dict or
json string)
@@ -41,10 +41,9 @@ class TPLinkSmartHomeProtocol:
if isinstance(request, dict):
request = json.dumps(request)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(TPLinkSmartHomeProtocol.DEFAULT_TIMEOUT)
timeout = TPLinkSmartHomeProtocol.DEFAULT_TIMEOUT
try:
sock.connect((host, port))
sock = socket.create_connection((host, port), timeout)
_LOGGER.debug("> (%i) %s", len(request), request)
sock.send(TPLinkSmartHomeProtocol.encrypt(request))