profile selection
This commit is contained in:
parent
f6d3039d46
commit
7e64d78d11
@ -112,7 +112,7 @@ def find_profile(wanted):
|
||||
json profile object or None.
|
||||
'''
|
||||
#load all profiles from disk
|
||||
profiles = get_profiles()
|
||||
profiles = get_profiles_json()
|
||||
json_profiles = json.loads(profiles)
|
||||
|
||||
# find the wanted profile
|
||||
@ -191,14 +191,14 @@ def handle_storage():
|
||||
|
||||
if message == "GET":
|
||||
log.info("GET command received")
|
||||
wsock.send(get_profiles())
|
||||
wsock.send(get_profiles_json())
|
||||
elif msgdict.get("cmd") == "DELETE":
|
||||
log.info("DELETE command received")
|
||||
profile_obj = msgdict.get('profile')
|
||||
if delete_profile(profile_obj):
|
||||
msgdict["resp"] = "OK"
|
||||
wsock.send(json.dumps(msgdict))
|
||||
#wsock.send(get_profiles())
|
||||
#wsock.send(get_profiles_json())
|
||||
elif msgdict.get("cmd") == "PUT":
|
||||
log.info("PUT command received")
|
||||
profile_obj = msgdict.get('profile')
|
||||
@ -213,7 +213,7 @@ def handle_storage():
|
||||
log.debug("websocket (storage) sent: %s" % message)
|
||||
|
||||
wsock.send(json.dumps(msgdict))
|
||||
wsock.send(get_profiles())
|
||||
wsock.send(get_profiles_json())
|
||||
except WebSocketError:
|
||||
break
|
||||
log.info("websocket (storage) closed")
|
||||
@ -245,7 +245,6 @@ def handle_status():
|
||||
break
|
||||
log.info("websocket (status) closed")
|
||||
|
||||
|
||||
def get_profiles():
|
||||
try:
|
||||
profile_files = os.listdir(profile_path)
|
||||
@ -255,8 +254,13 @@ def get_profiles():
|
||||
for filename in profile_files:
|
||||
with open(os.path.join(profile_path, filename), 'r') as f:
|
||||
profiles.append(json.load(f))
|
||||
return json.dumps(profiles)
|
||||
return profiles
|
||||
|
||||
def get_profiles_json():
|
||||
return json.dumps(get_profiles())
|
||||
|
||||
def update_profiles():
|
||||
ovenDisplay.update_profiles(get_profiles())
|
||||
|
||||
def save_profile(profile, force=False):
|
||||
profile_json = json.dumps(profile)
|
||||
@ -269,6 +273,7 @@ def save_profile(profile, force=False):
|
||||
f.write(profile_json)
|
||||
f.close()
|
||||
log.info("Wrote %s" % filepath)
|
||||
update_profiles()
|
||||
return True
|
||||
|
||||
def delete_profile(profile):
|
||||
@ -277,6 +282,7 @@ def delete_profile(profile):
|
||||
filepath = os.path.join(profile_path, filename)
|
||||
os.remove(filepath)
|
||||
log.info("Deleted %s" % filepath)
|
||||
update_profiles()
|
||||
return True
|
||||
|
||||
|
||||
@ -292,6 +298,7 @@ def main():
|
||||
ip = "0.0.0.0"
|
||||
port = config.listening_port
|
||||
log.info("listening on %s:%d" % (ip, port))
|
||||
update_profiles()
|
||||
|
||||
server = WSGIServer((ip, port), app,
|
||||
handler_class=WebSocketHandler)
|
||||
|
||||
@ -24,6 +24,8 @@ class OvenDisplay(threading.Thread):
|
||||
self.started = None
|
||||
self.recording = False
|
||||
self.observers = []
|
||||
self.profiles = None
|
||||
self.profile = None
|
||||
threading.Thread.__init__(self)
|
||||
self.daemon = True
|
||||
# oven setup
|
||||
@ -54,10 +56,12 @@ class OvenDisplay(threading.Thread):
|
||||
self.prev_profile()
|
||||
if (b_pressed):
|
||||
self.next_profile()
|
||||
|
||||
|
||||
time.sleep(self.sleep_time)
|
||||
|
||||
def update_profiles(self, new_profiles):
|
||||
log.info("New profiles ", new_profiles)
|
||||
self.profiles = new_profiles
|
||||
|
||||
# {'cost': 0, 'runtime': 0, 'temperature': 23.176953125, 'target': 0, 'state': 'IDLE', 'heat': 0, 'totaltime': 0, 'kwh_rate': 0.33631, 'currency_type': '£', 'profile': None, 'pidstats': {}}
|
||||
# {'cost': 0.003923616666666667, 'runtime': 0.003829, 'temperature': 23.24140625, 'target': 100.00079770833334, 'state': 'RUNNING', 'heat': 1.0, 'totaltime': 3600, 'kwh_rate': 0.33631, 'currency_type': '£', 'profile': 'test-200-250', 'pidstats': {'time': 1686902305.0, 'timeDelta': 5.027144, 'setpoint': 100.00079770833334, 'ispoint': 23.253125, 'err': 76.74767270833334, 'errDelta': 0, 'p': 1918.6918177083335, 'i': 0, 'd': 0, 'kp': 25, 'ki': 10, 'kd': 200, 'pid': 0, 'out': 1}}
|
||||
def update_display(self, oven_state):
|
||||
@ -73,10 +77,16 @@ class OvenDisplay(threading.Thread):
|
||||
else:
|
||||
self.text("Target: ---°C", (25, 100), fnt25, (255, 255, 255))
|
||||
|
||||
|
||||
if (oven_state['profile'] is not None):
|
||||
self.text(oven_state['profile'], (25, 150), fnt25, (255, 255, 255))
|
||||
active_profile = oven_state['profile']
|
||||
else:
|
||||
self.text("No Programme", (25, 150), fnt25, (255, 255, 255))
|
||||
active_profile = self.profile
|
||||
|
||||
if (active_profile is not None):
|
||||
self.text(active_profile.name, (25, 150), fnt25, (255, 255, 255))
|
||||
else:
|
||||
self.text('No Programme', (25, 150), fnt25, (255, 255, 255))
|
||||
|
||||
if (oven_state['state'] is None):
|
||||
self.text("Initialising", (25, 175), fnt25, (255, 255, 255))
|
||||
@ -110,10 +120,26 @@ class OvenDisplay(threading.Thread):
|
||||
self.update_display(self.oven.get_state())
|
||||
|
||||
def start_oven(self):
|
||||
log.info("Starting run")
|
||||
if (self.profile is None):
|
||||
log.error("No programme to start")
|
||||
else:
|
||||
log.info("Starting run " + self.profile)
|
||||
self.oven.run_profile(self.profile)
|
||||
|
||||
def prev_profile(self):
|
||||
log.info("Prev profile")
|
||||
idx = self.find_profile_idx()
|
||||
new_idx = (idx - 1) % len(self.profiles)
|
||||
self.profile = self.profiles[new_idx]
|
||||
|
||||
def next_profile(self):
|
||||
log.info("Next profile")
|
||||
idx = self.find_profile_idx()
|
||||
new_idx = (idx + 1) % len(self.profiles)
|
||||
self.profile = self.profiles[new_idx]
|
||||
|
||||
def find_profile_idx(self):
|
||||
for idx, p in enumerate(self.profiles):
|
||||
if (p == self.profile):
|
||||
return idx
|
||||
return 0
|
||||
|
||||
Loading…
Reference in New Issue
Block a user