aboutsummaryrefslogtreecommitdiff
path: root/dial.py
diff options
context:
space:
mode:
authorMark Powers <mark@marks.kitchen>2021-07-12 03:45:22 +0100
committerMark Powers <mark@marks.kitchen>2021-07-12 03:45:22 +0100
commitc985f5cb690189cfa94078b5990da4776dbd0cf4 (patch)
treef8c07dfd7feaaf036e3ec4be0cde803b7132bb2f /dial.py
parentc72abd79e4dbfd9b533d75bb00fea1ded9975d95 (diff)
Parse dial sequences from config
Diffstat (limited to 'dial.py')
-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):