mirror of
https://github.com/acatoire/bipbipzizik.git
synced 2026-03-10 08:01:18 +00:00
Implement clearqueu mode in box
Implement modes as list in CardList
This commit is contained in:
46
CardList.py
46
CardList.py
@@ -9,6 +9,7 @@ import os.path
|
||||
|
||||
class Card:
|
||||
def __init__(self, csv_line):
|
||||
|
||||
try:
|
||||
self.id = csv_line.split(",")[0].strip()
|
||||
if "" == self.id:
|
||||
@@ -24,11 +25,16 @@ class Card:
|
||||
self.cmd = "error"
|
||||
|
||||
try:
|
||||
self.mode = csv_line.split(",")[2].strip()
|
||||
if "" == self.mode:
|
||||
self.modes = []
|
||||
|
||||
raw_mode = csv_line.split(",")[2].strip()
|
||||
if "" == raw_mode:
|
||||
raise ValueError("Incorrect Value for mode")
|
||||
else:
|
||||
for element in raw_mode.split(";"):
|
||||
self.modes.append(element)
|
||||
except (IndexError, ValueError):
|
||||
self.mode = "Normal"
|
||||
self.modes.append("Normal")
|
||||
|
||||
try:
|
||||
self.comment = csv_line.split(",")[3].strip()
|
||||
@@ -38,20 +44,39 @@ class Card:
|
||||
self.comment = "no"
|
||||
|
||||
def __str__(self):
|
||||
return "[" + self.id + "," + self.cmd + "," + self.mode + "," + self.comment + "]"
|
||||
|
||||
return "[" + self.id + ", " + self.cmd + ", " + self.str_modes() + ", " + self.comment + "]"
|
||||
|
||||
def str_modes(self):
|
||||
modes_string = "("
|
||||
modes_string += ", ".join(self.modes)
|
||||
modes_string += ")"
|
||||
return modes_string
|
||||
|
||||
def has_mode(self, mode):
|
||||
|
||||
if 0 != self.modes.count(mode):
|
||||
mode_exist = True
|
||||
|
||||
else:
|
||||
mode_exist = False
|
||||
|
||||
return mode_exist
|
||||
|
||||
|
||||
class CardList:
|
||||
|
||||
def __init__(self):
|
||||
|
||||
self.file_path = os.path.dirname(os.path.realpath(__file__)) + '/cardList.csv' # TODO use relative path?
|
||||
self.card_list = self.update_list()
|
||||
|
||||
def __str__(self):
|
||||
# return [print("[" + element.id + " " + element.cmd + " " + element.mode + "]") for element in self.cardList]
|
||||
|
||||
printed_list = self.card_list.__len__().__str__() + " Recorded cards:\n"
|
||||
|
||||
for element in self.card_list:
|
||||
printed_list = printed_list + element.__str__() + "\n"
|
||||
printed_list += element.__str__() + "\n"
|
||||
|
||||
return printed_list
|
||||
|
||||
@@ -82,8 +107,11 @@ class CardList:
|
||||
def main():
|
||||
|
||||
# Test the card creation
|
||||
card_test = Card("1,2,3,4")
|
||||
print(card_test)
|
||||
card_test = Card("1,2,mode1;mode2;mode3,4")
|
||||
print("Card: " + card_test.__str__())
|
||||
print(card_test.has_mode("mode2"))
|
||||
print(card_test.has_mode("mode4"))
|
||||
|
||||
card_test = Card(",,,")
|
||||
print(card_test)
|
||||
card_test = Card("")
|
||||
@@ -98,7 +126,7 @@ def main():
|
||||
if card is not None:
|
||||
print(card)
|
||||
|
||||
card = card_list.get_card("0") # Not Existing
|
||||
card = card_list.get_card("0-0") # Not Existing
|
||||
if card is not None:
|
||||
print(card)
|
||||
|
||||
|
||||
12
Reader.py
12
Reader.py
@@ -19,26 +19,26 @@ class Reader:
|
||||
sys.exit('Please run config.py first')
|
||||
else:
|
||||
with open(path + '/deviceName.txt','r') as f:
|
||||
deviceName = f.read()
|
||||
device_name = f.read()
|
||||
devices = [InputDevice(fn) for fn in list_devices()]
|
||||
for device in devices:
|
||||
if device.name == deviceName:
|
||||
if device.name == device_name:
|
||||
self.dev = device
|
||||
break
|
||||
try:
|
||||
self.dev
|
||||
except:
|
||||
sys.exit('Could not find the device %s\n. Make sure is connected' % deviceName)
|
||||
sys.exit('Could not find the device %s\n. Make sure is connected' % device_name)
|
||||
|
||||
def read_card(self):
|
||||
stri = ''
|
||||
keys_input = ''
|
||||
key = ''
|
||||
while key != 'KEY_ENTER':
|
||||
r,w,x = select([self.dev], [], [])
|
||||
for event in self.dev.read():
|
||||
if event.type == 1 and event.value == 1:
|
||||
stri += self.keys[event.code]
|
||||
keys_input += self.keys[event.code]
|
||||
# print( keys[ event.code ] )
|
||||
key = ecodes.KEY[event.code]
|
||||
return stri[:-1]
|
||||
return keys_input[:-1]
|
||||
|
||||
|
||||
9
box.py
9
box.py
@@ -56,12 +56,15 @@ while True:
|
||||
else:
|
||||
previousCard = read_id
|
||||
|
||||
if card.has_mode("ClearQueue"):
|
||||
subprocess.check_call(["./sonosplay.sh " + commandLine + "clearqueue"], shell=True)
|
||||
|
||||
if card.cmd != 'error':
|
||||
# TODO, direct python implementation without using sh script
|
||||
subprocess.check_call(["./sonosplay.sh %s" % commandLine + card.cmd], shell=True)
|
||||
subprocess.check_call(["./sonosplay.sh " + commandLine + card.cmd], shell=True)
|
||||
|
||||
list(range(10000)) # some payload code
|
||||
time.sleep(0.2) # sane sleep time
|
||||
list(range(10000)) # some payload code
|
||||
time.sleep(0.2) # sane sleep time
|
||||
|
||||
except OSError as e:
|
||||
print("Execution failed:")
|
||||
|
||||
19
sonosplay.sh
19
sonosplay.sh
@@ -3,22 +3,17 @@
|
||||
# Get arguments
|
||||
addr=$1 # Mendatory - exemple : http://192.168.0.140:5005
|
||||
cmd=$2 # Mendatory - exemple : volume/50
|
||||
where=$3 # Optional - exemple : salon TODO
|
||||
|
||||
|
||||
echo "Execute the command '$cmd' on the server at '$addr'"
|
||||
|
||||
|
||||
# Execute the sonos api request using curl
|
||||
if [ -z $where ]
|
||||
then
|
||||
# Clear the queu and load the new album/playlist
|
||||
# Todo, check if needed for all (maybe not for tracks
|
||||
# curl -X GET $addr/clearqueue
|
||||
curl -X GET $addr/$cmd
|
||||
else
|
||||
echo "only for the room $where"
|
||||
# curl -X GET $addr/$where/clearqueue
|
||||
curl -X GET $addr/$where/$cmd
|
||||
fi
|
||||
|
||||
# Clear the queu and load the new album/playlist
|
||||
# Todo, check if needed for all (maybe not for tracks
|
||||
# curl -X GET $addr/clearqueue
|
||||
curl -X GET $addr/$cmd
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user