Adds doctests.
[python_utils.git] / smart_home / registry.py
index 2d23981d00ad9aaafef04a45c0761bd4cdefd5af..75fe05256cc9f51cdc06a497fe9304917a510218 100644 (file)
@@ -60,7 +60,12 @@ class SmartHomeRegistry(object):
             if line == "":
                 continue
             logger.debug(f'SH-CONFIG> {line}')
-            (mac, name, keywords) = line.split(",")
+            try:
+                (mac, name, keywords) = line.split(",")
+            except ValueError:
+                msg = f'SH-CONFIG> "{line}" is malformed?!  Skipping it.'
+                logger.warning(msg)
+                continue
             mac = mac.strip()
             name = name.strip()
             keywords = keywords.strip()
@@ -161,6 +166,9 @@ class SmartHomeRegistry(object):
                         else:
                             logger.debug('    ...a TPLinkOutlet')
                             return outlets.TPLinkOutlet(name, mac, kws)
+                    elif 'meross' in kws.lower():
+                        logger.debug('    ...a MerossOutlet')
+                        return outlets.MerossOutlet(name, mac, kws)
                     elif 'goog' in kws.lower():
                         logger.debug('    ...a GoogleOutlet')
                         return outlets.GoogleOutlet(name, mac, kws)
@@ -176,11 +184,10 @@ 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)
         return None
 
     def query(self, query: str) -> List[device.Device]: