From 2ff988037b3fa9a27e89d4ca2dc1c0b2a1157b9d Mon Sep 17 00:00:00 2001 From: AxelC Date: Wed, 6 Nov 2019 22:38:16 +0100 Subject: [PATCH] Start using bdd, to be tested on target --- box.py | 23 ++++++++++++----------- modules/cards_bdd/BddCreator.py | 8 ++++---- modules/cards_bdd/CardReader.py | 9 +++++++++ 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/box.py b/box.py index 6a51a22..8403d23 100755 --- a/box.py +++ b/box.py @@ -10,15 +10,20 @@ import subprocess import time # Bipbip Music import -from modules.card_memory.CardMemory import CardMemory -from modules.cards_csv.CardList import CardList from modules.rfid_reader.Reader import Reader +from modules.card_memory.CardMemory import CardMemory +from modules.cards_bdd.CardReader import CardBdd import config as cfg # Get config from file +# TODO check if bdd is automatically updated + def main(): + reader = Reader() + bdd = CardBdd('https://bipbipzizik.firebaseio.com/', 'cards_test') + # Previous card id memory try: # Get it from config @@ -27,9 +32,6 @@ def main(): # Default value previous_card = CardMemory(30) - reader = Reader() - card_list = CardList() - # Create address path address = cfg.ip + ':' + cfg.port @@ -50,16 +52,15 @@ def main(): try: print('Read card : ', read_id) - # Update Card bdd TODO do it every X minutes - card_list.update_list() - # Find the card in bdd - card = card_list.get_card(read_id) + card = bdd.get_card(read_id) + mode = card.get_mode() + command = card.get_command() if card is not None: # Card execution - print('Command : ', card.cmd) - print('Modes : ', card.str_modes()) + print('Command : ', command) + print('Modes : ', mode) if (previous_card.get() == read_id) and ("cancel" == cfg.multiReadMode) and (not card.has_mode("Command")): # Cancel the read diff --git a/modules/cards_bdd/BddCreator.py b/modules/cards_bdd/BddCreator.py index 2c777c5..cbca7b7 100644 --- a/modules/cards_bdd/BddCreator.py +++ b/modules/cards_bdd/BddCreator.py @@ -12,7 +12,7 @@ bdd.write_card(user="axel", comment="", ids="0013397903", mode="none", - action="command", + action="Command", data="playpause") bdd.write_card(user="axel", @@ -20,7 +20,7 @@ bdd.write_card(user="axel", comment="", ids="0013403195", mode="none", - action="command", + action="Command", data="next") bdd.write_card(user="axel", @@ -28,7 +28,7 @@ bdd.write_card(user="axel", comment="", ids="0005690629", mode="none", - action="command", + action="Command", data="volume/+5") bdd.write_card(user="axel", @@ -36,7 +36,7 @@ bdd.write_card(user="axel", comment="", ids="0005690629", mode="none", - action="command", + action="Command", data="volume/-5") # For Parents diff --git a/modules/cards_bdd/CardReader.py b/modules/cards_bdd/CardReader.py index 49fbfab..20d2921 100644 --- a/modules/cards_bdd/CardReader.py +++ b/modules/cards_bdd/CardReader.py @@ -68,6 +68,15 @@ class Card: return mode + def has_mode(self, mode): + + if self.parameters.get("mode") == mode: + mode_exist = True + else: + mode_exist = False + + return mode_exist + class CardBdd: