aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dial.py21
1 files changed, 13 insertions, 8 deletions
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):