Skip to content

Commit

Permalink
Fix a startup ordering bug that prevented --create_device_cache from …
Browse files Browse the repository at this point in the history
…working
  • Loading branch information
seanrees committed Mar 30, 2021
1 parent d2055be commit 037a9fb
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def is_connected(self) -> bool:
return self.libdyson.is_connected

def connect(self, host: str):
"""Connect to the device and start the environmental monitoring timer."""
"""Connect to the device and start the environmental monitoring
timer."""
self.libdyson.connect(host)
self._refresh_timer()

Expand Down Expand Up @@ -208,18 +209,23 @@ def main(argv):
logging.exception('Could not load configuration: %s', args.config)
sys.exit(-1)

devices = cfg.devices
if len(devices) == 0:
logging.fatal(
'No devices configured; please re-run this program with --create_device_cache.')
sys.exit(-2)

if args.create_device_cache:
if not cfg.dyson_credentials:
logging.error('DysonLink credentials not found in %s, cannot generate device cache',
args.config)
sys.exit(-1)

logging.info(
'--create_device_cache supplied; breaking out to perform this.')
account.generate_device_cache(cfg.dyson_credentials, args.config)
sys.exit(0)

devices = cfg.devices
if len(devices) == 0:
logging.fatal(
'No devices configured; please re-run this program with --create_device_cache.')
sys.exit(-2)

prometheus_client.start_http_server(args.port)

ConnectionManager(metrics.Metrics().update, devices, cfg.hosts)
Expand Down

0 comments on commit 037a9fb

Please sign in to comment.