Skip to content

Commit

Permalink
fix error on uninitialized rfid_reader settings
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvinSchiller committed Nov 20, 2023
1 parent d011faa commit 82a847f
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/jukebox/components/rfid/reader/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,22 @@ def run(self): # noqa: C901

@plugs.finalize
def finalize():
jukebox.cfghandler.load_yaml(cfg_rfid, cfg_main.getn('rfid', 'reader_config'))

# Load all the required modules
# Start a ReaderRunner-Thread for each Reader
for reader_cfg_key in cfg_rfid['rfid']['readers'].keys():
_READERS[reader_cfg_key] = ReaderRunner(reader_cfg_key)
for reader_cfg_key in cfg_rfid['rfid']['readers'].keys():
_READERS[reader_cfg_key].start()
try:
reader_config_file = cfg_main.getn('rfid', 'reader_config')
jukebox.cfghandler.load_yaml(cfg_rfid, reader_config_file)
except FileNotFoundError:
cfg_rfid.config_dict({'rfid': {'readers': {}}})
log.warning(f"rfid reader database file not found. Creating empty database: '{reader_config_file}'")
# Save the empty rfid reader database, to make sure we can create the file and have access to it
cfg_rfid.save(only_if_changed=False)

if 'rfid' in cfg_rfid and 'readers' in cfg_rfid['rfid']:
# Load all the required modules
# Start a ReaderRunner-Thread for each Reader
for reader_cfg_key in cfg_rfid['rfid']['readers'].keys():
_READERS[reader_cfg_key] = ReaderRunner(reader_cfg_key)
for reader_cfg_key in cfg_rfid['rfid']['readers'].keys():
_READERS[reader_cfg_key].start()


@plugs.atexit
Expand Down

0 comments on commit 82a847f

Please sign in to comment.