mirror of
https://github.com/python-kasa/python-kasa.git
synced 2024-12-22 19:23:34 +00:00
Add timeout to query (#19)
This commit is contained in:
parent
fd4e363f56
commit
1e01530447
@ -39,6 +39,8 @@ class TPLinkSmartHomeProtocol:
|
||||
request = json.dumps(request)
|
||||
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock.settimeout(5.0)
|
||||
try:
|
||||
sock.connect((host, port))
|
||||
|
||||
_LOGGER.debug("> (%i) %s", len(request), request)
|
||||
@ -51,6 +53,7 @@ class TPLinkSmartHomeProtocol:
|
||||
if not chunk:
|
||||
break
|
||||
|
||||
finally:
|
||||
sock.shutdown(socket.SHUT_RDWR)
|
||||
sock.close()
|
||||
|
||||
|
@ -103,7 +103,7 @@ class SmartPlug:
|
||||
request={target: {cmd: arg}}
|
||||
)
|
||||
except Exception as ex:
|
||||
raise SmartPlugException(ex)
|
||||
raise SmartPlugException(ex) from ex
|
||||
|
||||
result = response[target]
|
||||
if "err_code" in result and result["err_code"] != 0:
|
||||
|
Loading…
Reference in New Issue
Block a user