diff options
| author | Scott <[email protected]> | 2022-01-11 13:33:24 -0800 |
|---|---|---|
| committer | Scott <[email protected]> | 2022-01-11 13:33:24 -0800 |
| commit | b454ad295eb3024a238d32bf2aef1ebc3c496b44 (patch) | |
| tree | 89368a7cdad571da9e2c7297190fdce48eb3feb9 /smart_home | |
| parent | d2478310649d51e14f8ece57651ca9d925d98793 (diff) | |
Start using warnings from stdlib.
Diffstat (limited to 'smart_home')
| -rw-r--r-- | smart_home/lights.py | 13 | ||||
| -rw-r--r-- | smart_home/outlets.py | 13 | ||||
| -rw-r--r-- | smart_home/registry.py | 13 |
3 files changed, 26 insertions, 13 deletions
diff --git a/smart_home/lights.py b/smart_home/lights.py index e23569a..44b3634 100644 --- a/smart_home/lights.py +++ b/smart_home/lights.py @@ -11,6 +11,7 @@ import re import subprocess import sys from typing import Any, Dict, List, Optional, Tuple +import warnings from overrides import overrides import tinytuya as tt @@ -46,14 +47,18 @@ def tplink_light_command(command: str) -> bool: result = os.system(command) signal = result & 0xFF if signal != 0: - logger.warning(f'{command} died with signal {signal}') - logging_utils.hlog("%s died with signal %d" % (command, signal)) + msg = f'{command} died with signal {signal}' + logger.warning(msg) + warnings.warn(msg) + logging_utils.hlog(msg) return False else: exit_value = result >> 8 if exit_value != 0: - logger.warning(f'{command} failed, exited {exit_value}') - logging_utils.hlog("%s failed, exit %d" % (command, exit_value)) + msg = f'{command} failed, exited {exit_value}' + logger.warning(msg) + warnings.warn(msg) + logging_utils.hlog(msg) return False logger.debug(f'{command} succeeded.') return True diff --git a/smart_home/outlets.py b/smart_home/outlets.py index 8fd0948..6cc8d57 100644 --- a/smart_home/outlets.py +++ b/smart_home/outlets.py @@ -13,6 +13,7 @@ import re import subprocess import sys from typing import Any, Dict, List, Optional +import warnings from meross_iot.http_api import MerossHttpClient from meross_iot.manager import MerossManager @@ -48,14 +49,18 @@ def tplink_outlet_command(command: str) -> bool: result = os.system(command) signal = result & 0xFF if signal != 0: - logger.warning(f'{command} died with signal {signal}') - logging_utils.hlog("%s died with signal %d" % (command, signal)) + msg = f'{command} died with signal {signal}' + logger.warning(msg) + warnings.warn(msg) + logging_utils.hlog(msg) return False else: exit_value = result >> 8 if exit_value != 0: - logger.warning(f'{command} failed, exited {exit_value}') - logging_utils.hlog("%s failed, exit %d" % (command, exit_value)) + msg = f'{command} failed, exited {exit_value}' + logger.warning(msg) + warnings.warn(msg) + logging_utils.hlog(msg) return False logger.debug(f'{command} succeeded.') return True diff --git a/smart_home/registry.py b/smart_home/registry.py index 23584e1..20fb3f4 100644 --- a/smart_home/registry.py +++ b/smart_home/registry.py @@ -3,6 +3,7 @@ import logging import re from typing import List, Optional, Set +import warnings import argparse_utils import config @@ -63,7 +64,9 @@ class SmartHomeRegistry(object): try: (mac, name, keywords) = line.split(",") except ValueError: - logger.warning(f'SH-CONFIG> {line} is malformed?!') + msg = f'SH-CONFIG> {line} is malformed?!' + logger.warning(msg) + warnings.warn(msg) continue mac = mac.strip() name = name.strip() @@ -183,11 +186,11 @@ class SmartHomeRegistry(object): logger.debug(' ...an unknown device (should this be here?)') return device.Device(name, mac, kws) except Exception as e: - logger.warning( - f'Got exception {e} while trying to communicate with device {name}/{mac}.' - ) + logger.exception(e) return device.Device(name, mac, kws) - logger.warning(f'{mac} is not a known smart home device, returning None') + msg = f'{mac} is not a known smart home device, returning None' + logger.warning(msg) + warnings.warn(msg) return None def query(self, query: str) -> List[device.Device]: |
