diff options
| author | Scott Gasch <[email protected]> | 2022-02-26 11:15:31 -0800 |
|---|---|---|
| committer | Scott Gasch <[email protected]> | 2022-02-26 11:15:31 -0800 |
| commit | 4863b00af3b2ddcfaa2e5f47fd6dd7e95c1eb6c5 (patch) | |
| tree | 438cd64bae8c3522275e8cb7340c09aa4898b8d2 /smart_home/tplink_utils.py | |
| parent | 84b6592ce26c6716d7cce86caa70a27862c293a3 (diff) | |
More work on tplink utils to avoid having to call tplink.py.
Diffstat (limited to 'smart_home/tplink_utils.py')
| -rw-r--r-- | smart_home/tplink_utils.py | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/smart_home/tplink_utils.py b/smart_home/tplink_utils.py index 9b8eb6d..053ce33 100644 --- a/smart_home/tplink_utils.py +++ b/smart_home/tplink_utils.py @@ -24,10 +24,7 @@ limitations under the License. import json import logging import os -import re import socket -import subprocess -import sys import time from struct import pack from typing import Dict, List, Optional, Tuple @@ -76,21 +73,14 @@ def tplink_command(command: str) -> bool: return True -@timeout(10.0, use_signals=False, error_message="Timed out waiting for tplink.py") -def tplink_get_info(cmd: str) -> Optional[Dict]: - logger.debug('Getting tplink device status via "%s"', cmd) - try: - out = subprocess.getoutput(cmd) - logger.debug('RAW OUT> %s', out) - out = re.sub("Sent:.*\n", "", out) - out = re.sub("Received: *", "", out) - info = json.loads(out)["system"]["get_sysinfo"] +def tplink_get_info(ip: str, port: int = 9999) -> Optional[Dict]: + success, response = communicate_with_device(ip, port, commands['info'], quiet=True) + if success: + assert len(response) == 1 + info = json.loads(response[0])["system"]["get_sysinfo"] logger.debug("%s", json.dumps(info, indent=4, sort_keys=True)) return info - except Exception as e: - logger.exception(e) - print(out, file=sys.stderr) - return None + return None def encrypt(string: str) -> bytes: |
