Change locking boundaries for shared dict. Add a unit test.
[python_utils.git] / smart_home / outlets.py
index 68dfd2b8913216453a230ebdb2c2c90e6914e54a..c079cfd09d9cbbfbb8595379770ebc1c8d7497ae 100644 (file)
@@ -48,14 +48,16 @@ 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)
+        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)
+            logging_utils.hlog(msg)
             return False
     logger.debug(f'{command} succeeded.')
     return True
@@ -238,13 +240,13 @@ class GoogleOutlet(BaseOutlet):
 
 @decorator_utils.singleton
 class MerossWrapper(object):
-    """Note that instantiating this class causes HTTP traffic with an
-    external Meross server.  Meross blocks customers who hit their
-    servers too aggressively so MerossOutlet is lazy about creating
-    instances of this class.
+    """Global singleton helper class for MerossOutlets.  Note that
+    instantiating this class causes HTTP traffic with an external
+    Meross server.  Meross blocks customers who hit their servers too
+    aggressively so MerossOutlet is lazy about creating instances of
+    this class.
 
     """
-
     def __init__(self):
         self.loop = asyncio.get_event_loop()
         self.email = os.environ.get('MEROSS_EMAIL') or scott_secrets.MEROSS_EMAIL