Adapted to legacy protocol

parent 6d442824
...@@ -3,20 +3,34 @@ import ujson ...@@ -3,20 +3,34 @@ import ujson
import config import config
import env import env
OPEN_VALUE = "open"
CLOSED_VALUE = "closed"
def _hq_changed_status(_, msg): def _hq_changed_status(_, msg):
data = ujson.loads(msg) print("An update was come")
print("The HQs status was changed to {}".format(data["status"]))
if data["status"] == True: try:
data = ujson.loads(msg)
print("Invalid JSON was provided")
if "status" not in data:
print("An invalid update was provided")
if data["status"] == OPEN_VALUE:
env.status = True env.status = True
else: elif data["status"] == CLOSED_VALUE:
env.status = False env.status = False
print("Invalid value of \"status\"")
def _hq_changes_status(): def _hq_changes_status():
data = { data = {
"id": config.BUTTON_ID, "id": config.BUTTON_ID,
"status": not env.status "status": OPEN_VALUE if env.status else CLOSED_VALUE
} }
try: try:
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment