From c985f5cb690189cfa94078b5990da4776dbd0cf4 Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Mon, 12 Jul 2021 03:45:22 +0100 Subject: Parse dial sequences from config --- dial.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'dial.py') diff --git a/dial.py b/dial.py index 0d14a32..b6f3dd9 100644 --- a/dial.py +++ b/dial.py @@ -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): -- cgit v1.2.3