Commit fad601f5 authored by Benjamin Mummery's avatar Benjamin Mummery 💻

handler.set_db now returns 1 for an unrecognised payload type.…

handler.set_db now returns 1 for an unrecognised payload type. NativeUI.get_updates uses this to determine if the payload has been recognised, and raises an error if not.
parent b08b96e2
......@@ -464,30 +464,31 @@ class NativeUI(HEVClient, QMainWindow):
super().start_client()
def get_updates(self, payload: dict) -> int:
"""callback from the polling function, payload is data from socket """
"""
Callback from the polling function, payload is data from socket.
TODO: remove all if-elif logic on favor of looping over handlers.
"""
self.statusBar().showMessage(f"{payload}")
logging.debug("recieved payload of type %s", payload["type"])
payload_registered = False
for handler in self.__payload_handlers:
if handler.set_db(payload) == 0:
payload_registered = True
if not payload_registered:
logging.warning("Handlers: Invalid payload type: %s", payload["type"])
logging.debug("Content of invalid payload:\n%s", payload)
if payload["type"] == "DATA":
self.data_handler.set_db(payload)
old = self.ongoingAlarms
self.ongoingAlarms = payload["alarms"]
elif payload["type"] == "BATTERY":
self.battery_handler.set_db(payload)
elif payload["type"] == "ALARM":
self.__set_db("alarms", payload["ALARM"])
elif payload["type"] == "TARGET":
self.__set_db("targets", payload["TARGET"])
elif payload["type"] == "READBACK":
self.measurement_handler.set_db(payload)
elif payload["type"] == "PERSONAL":
self.personal_handler.set_db(payload)
elif payload["type"] == "CYCLE":
self.measurement_handler.set_db(payload)
elif payload["type"] == "DEBUG":
pass
else:
logging.warning("Invalid payload type: %s", payload["type"])
logging.debug("Content of invalid payload:\n%s", payload)
return 0
@Slot(str, str, float)
......
......@@ -25,7 +25,7 @@ class Handler:
If the provided database is of the correct type, copy its contents to the database
"""
if payload["type"] not in self.__payload_types:
return 0
return 1
with self.__lock:
for key in payload[payload["type"]]:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment