Fix PlanObject import issue

This commit is contained in:
Matthew Stratford 2020-11-05 18:58:18 +00:00
parent f5fd6ca236
commit cb42eec757
No known key found for this signature in database
GPG key ID: 9E53C8B3F0B57395
3 changed files with 18 additions and 19 deletions

View file

@ -1,10 +1,12 @@
from helpers.logging_manager import LoggingManager
import json
import os
import logging
import time
from datetime import datetime
from copy import copy
from plan import PlanObject
from helpers.logging_manager import LoggingManager
from helpers.os_environment import resolve_external_file_path
@ -38,25 +40,22 @@ class StateManager:
if file_state == "":
self._log("State file is empty. Setting default state.")
self.state = copy(default_state)
self.state = default_state
self.__state_in_file = copy(self.state)
else:
try:
self.state = json.loads(file_state)
file_state = json.loads(file_state)
# Turn from JSON -> PlanObject
self.update(
"loaded_item",
PlanObject(self.__state["loaded_item"]) if self.state["loaded_item"] else None
)
self.update(
"show_plan",
[PlanObject(obj) for obj in self.state["show_plan"]]
)
file_state["loaded_item"] = PlanObject(file_state["loaded_item"]) if file_state["loaded_item"] else None
file_state["show_plan"] = [PlanObject(obj) for obj in file_state["show_plan"]]
# Now feed the loaded state into the initialised state manager.
self.state = file_state
except:
self._logException("Failed to parse state JSON. Resetting to default state.")
self.state = copy(default_state)
self.state = default_state
self.__state_in_file = copy(self.state)
# Now setup the rate limiting

View file

@ -244,7 +244,7 @@ class Player():
self.unload()
updated: bool = False
for i in range(len(self.state.state["show_plan"])):
if self.state.state["show_plan"][i].timeslotitemid == timeslotitemid:
self.state.update("loaded_item", self.state.state["show_plan"][i])
@ -335,7 +335,7 @@ class Player():
if self.state.state["remaining"] == 0 and self.state.state["loaded_item"]:
# Track has ended
print("Finished", self.state.state["loaded_item"].name)
# Repeat 1
if self.state.state["repeat"] == "ONE":
self.play()
@ -351,11 +351,11 @@ class Player():
# Repeat All
elif self.state.state["repeat"] == "ALL":
self.load(self.state.state["show_plan"][0].timeslotitemid)
# Play on Load
if self.state.state["play_on_load"]:
self.play()
def _retMsg(self, msg, okay_str=False):
response = self.last_msg + ":"
@ -431,7 +431,7 @@ class Player():
message_types: Dict[str, Callable[any, bool]] = { # TODO Check Types
"STATUS": lambda: self._retMsg(self.status, True),
# Audio Playout
"PLAY": lambda: self._retMsg(self.play()),
"PAUSE": lambda: self._retMsg(self.pause()),

View file

@ -201,7 +201,7 @@ def add_to_plan(channel: int):
@app.route("/player/<int:channel>/move/<int:timeslotitemid>/<int:position>")
def move_plan(channel: int, timeslotitemid: int, position: int):
channel_to_q[channel].put("MOVE:" + json.dumps({"timeslotitemid": timeslotitemid, "position": position}))
#TODO Return
return True
@ -254,7 +254,7 @@ def all_stop():
@app.route("/player/all/clear")
def clear_all_channels():
for channel in channel_to_q:
channel.put("CLEAR")
channel.put("CLEAR")
return ui_status()