Skip to content

Commit 037a9fb

Browse files
committed
Fix a startup ordering bug that prevented --create_device_cache from working
1 parent d2055be commit 037a9fb

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

main.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ def is_connected(self) -> bool:
5454
return self.libdyson.is_connected
5555

5656
def connect(self, host: str):
57-
"""Connect to the device and start the environmental monitoring timer."""
57+
"""Connect to the device and start the environmental monitoring
58+
timer."""
5859
self.libdyson.connect(host)
5960
self._refresh_timer()
6061

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

211-
devices = cfg.devices
212-
if len(devices) == 0:
213-
logging.fatal(
214-
'No devices configured; please re-run this program with --create_device_cache.')
215-
sys.exit(-2)
216-
217212
if args.create_device_cache:
213+
if not cfg.dyson_credentials:
214+
logging.error('DysonLink credentials not found in %s, cannot generate device cache',
215+
args.config)
216+
sys.exit(-1)
217+
218218
logging.info(
219219
'--create_device_cache supplied; breaking out to perform this.')
220220
account.generate_device_cache(cfg.dyson_credentials, args.config)
221221
sys.exit(0)
222222

223+
devices = cfg.devices
224+
if len(devices) == 0:
225+
logging.fatal(
226+
'No devices configured; please re-run this program with --create_device_cache.')
227+
sys.exit(-2)
228+
223229
prometheus_client.start_http_server(args.port)
224230

225231
ConnectionManager(metrics.Metrics().update, devices, cfg.hosts)

0 commit comments

Comments
 (0)