X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=smart_home%2Fregistry.py;h=16e18ba11bcc5fa19443245f02df546c68d54787;hb=5c212d7639f62fcb936f9d7a0bbe704a9f7b213d;hp=20fb3f43807bf0dbbd45fa7f5c36ed8f4d1bc917;hpb=b454ad295eb3024a238d32bf2aef1ebc3c496b44;p=python_utils.git diff --git a/smart_home/registry.py b/smart_home/registry.py index 20fb3f4..16e18ba 100644 --- a/smart_home/registry.py +++ b/smart_home/registry.py @@ -3,21 +3,20 @@ import logging import re from typing import List, Optional, Set -import warnings import argparse_utils import config import file_utils import logical_search -import smart_home.device as device import smart_home.cameras as cameras import smart_home.chromecasts as chromecasts +import smart_home.device as device import smart_home.lights as lights import smart_home.outlets as outlets args = config.add_commandline_args( f"Smart Home Registry ({__file__})", - "Args related to the smart home configuration registry." + "Args related to the smart home configuration registry.", ) args.add_argument( '--smart_home_registry_file_location', @@ -33,9 +32,9 @@ logger = logging.getLogger(__file__) class SmartHomeRegistry(object): def __init__( - self, - registry_file: Optional[str] = None, - filters: List[str] = ['smart'], + self, + registry_file: Optional[str] = None, + filters: List[str] = ['smart'], ) -> None: self._macs_by_name = {} self._keywords_by_name = {} @@ -45,13 +44,11 @@ class SmartHomeRegistry(object): # Read the disk config file... if registry_file is None: - registry_file = config.config[ - 'smart_home_registry_file_location' - ] + registry_file = config.config['smart_home_registry_file_location'] assert file_utils.does_file_exist(registry_file) logger.debug(f'Reading {registry_file}') - with open(registry_file, "r") as f: - contents = f.readlines() + with open(registry_file, "r") as rf: + contents = rf.readlines() # Parse the contents... for line in contents: @@ -64,9 +61,8 @@ class SmartHomeRegistry(object): try: (mac, name, keywords) = line.split(",") except ValueError: - msg = f'SH-CONFIG> {line} is malformed?!' + msg = f'SH-CONFIG> "{line}" is malformed?! Skipping it.' logger.warning(msg) - warnings.warn(msg) continue mac = mac.strip() name = name.strip() @@ -187,10 +183,12 @@ class SmartHomeRegistry(object): return device.Device(name, mac, kws) except Exception as e: logger.exception(e) + logger.debug( + f'Device {name} at {mac} with {kws} confused me, returning a generic Device' + ) return device.Device(name, mac, kws) 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]: