minor fixes to logging; qos; config sample

pull/106/head
Jeff Culverhouse 11 months ago
parent d1c9120ab1
commit 34444997e1

@ -138,7 +138,7 @@ class AmcrestAPI(object):
try: try:
config = self.devices[device_id]['config'] config = self.devices[device_id]['config']
self.logger.info(f'Event on {config["host"]} - {code}: {payload}') self.logger.debug(f'Event on {config["host"]} - {code}: {payload}')
if ((code == "ProfileAlarmTransmit" and config["is_ad110"]) if ((code == "ProfileAlarmTransmit" and config["is_ad110"])
or (code == "VideoMotion" and not config["is_ad110"])): or (code == "VideoMotion" and not config["is_ad110"])):

@ -22,15 +22,7 @@ def read_version():
return read_file('../VERSION') return read_file('../VERSION')
# Let's go! # Let's go!
logging.basicConfig(
format = '%(asctime)s.%(msecs)03d [%(levelname)s] %(name)s: %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
level=logging.INFO
)
logger = logging.getLogger(__name__)
version = read_version() version = read_version()
logger.info(f'Starting: amcrest2mqtt v{version}')
# cmd-line args # cmd-line args
argparser = argparse.ArgumentParser() argparser = argparse.ArgumentParser()
@ -51,11 +43,9 @@ try:
configfile = configpath + 'config.yaml' configfile = configpath + 'config.yaml'
with open(configfile) as file: with open(configfile) as file:
config = yaml.safe_load(file) config = yaml.safe_load(file)
logger.info(f'Reading config file {configpath}')
config['config_from'] = 'file' config['config_from'] = 'file'
config['config_path'] = configpath config['config_path'] = configpath
except: except:
logger.info(f'config.yaml not found, checking ENV')
config = { config = {
'mqtt': { 'mqtt': {
'host': os.getenv('MQTT_HOST') or 'localhost', 'host': os.getenv('MQTT_HOST') or 'localhost',
@ -80,10 +70,20 @@ except:
'device_update_interval': int(os.getenv("DEVICE_UPDATE_INTERVAL") or 600), 'device_update_interval': int(os.getenv("DEVICE_UPDATE_INTERVAL") or 600),
}, },
'debug': True if os.getenv('DEBUG') else False, 'debug': True if os.getenv('DEBUG') else False,
'hide_ts': True if os.getenv('HIDE_TS') else False,
'config_from': 'env', 'config_from': 'env',
'timezone': os.getenv('TZ'), 'timezone': os.getenv('TZ'),
} }
logging.basicConfig(
format = '%(asctime)s.%(msecs)03d [%(levelname)s] %(name)s: %(message)s' if config['hide_ts'] == False else '[%(levelname)s] %(name)s: %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
level=logging.INFO
)
logger = logging.getLogger(__name__)
logger.info(f'Starting: amcrest2mqtt v{version}')
logger.info(f'Config loaded from {config["config_from"]}')
config['version'] = version config['version'] = version
config['configpath'] = os.path.dirname(configpath) config['configpath'] = os.path.dirname(configpath)
@ -116,10 +116,5 @@ else:
if config['debug']: if config['debug']:
logger.setLevel(logging.DEBUG) logger.setLevel(logging.DEBUG)
try:
with AmcrestMqtt(config) as mqtt: with AmcrestMqtt(config) as mqtt:
asyncio.run(mqtt.main_loop()) asyncio.run(mqtt.main_loop())
except KeyboardInterrupt:
pass
except Exception as err:
logging.exception("Exception caught", exc_info=True)

@ -5,7 +5,8 @@ mqtt:
password: password password: password
qos: 0 qos: 0
prefix: amcrest2mqtt prefix: amcrest2mqtt
homeassistant: homeassistant home_assistant: True
discovery_prefix: homeassistant
tls_enabled: False tls_enabled: False
tls_ca_cert: filename tls_ca_cert: filename
tls_cert: filename tls_cert: filename
@ -23,6 +24,6 @@ amcrest:
password: password password: password
storage_poll_interval: 60 storage_poll_interval: 60
home_assistant: True timezone: America/New_York
home_assistant_prefix: homeassistant hide_ts: False
debug: False debug: False
Loading…
Cancel
Save