diff options
author | Mark Powers <mark@marks.kitchen> | 2021-07-12 03:45:22 +0100 |
---|---|---|
committer | Mark Powers <mark@marks.kitchen> | 2021-07-12 03:45:22 +0100 |
commit | c985f5cb690189cfa94078b5990da4776dbd0cf4 (patch) | |
tree | f8c07dfd7feaaf036e3ec4be0cde803b7132bb2f /dial.py | |
parent | c72abd79e4dbfd9b533d75bb00fea1ded9975d95 (diff) |
Parse dial sequences from config
Diffstat (limited to 'dial.py')
-rw-r--r-- | dial.py | 21 |
1 files changed, 13 insertions, 8 deletions
@@ -3,6 +3,7 @@ import time import RPi.GPIO as GPIO import threading import events +from config import config BUTTON_GPIO = 25 REST_TIME = 0.3 # seconds @@ -53,14 +54,18 @@ class DialManager: self._load_sequences(phone_held, phone_hung_up) def _load_sequences(self, phone_held, phone_hung_up): - self.sequences = { - 0: events.OperatorEvent(self, phone_held, phone_hung_up), - 1: events.WeatherEvent(self, phone_held, phone_hung_up), - 2: events.TimerEvent(self, phone_held, phone_hung_up), - 4: {1: {1: events.DirectoryEvent(self, phone_held, phone_hung_up)}}, - 7: events.FortuneEvent(self, phone_held, phone_hung_up), - } - print(self.sequences) + def recursive_add(classname, sequence_list, sequences): + key = int(sequence_list[0]) + if not sequence_list[1:]: + sequences[key] = eval(classname)(self, phone_held, phone_hung_up) + else: + sequences[key] = {} + recursive_add(classname, sequence_list[1:], sequences[key]) + + self.sequences = {} + for sequence in config["sequences"]: + print(sequence, config["sequences"][sequence], sep="\t") + recursive_add(config["sequences"][sequence], list(sequence), self.sequences) def dial(self, number): if datetime.now() - self.update > timedelta(seconds=DIAL_RESET_TIME): |