|
|
|
@ -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)
|
|
|
|
|