You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
852 B

import json
import os
STATE_FILE = "plant_state.json"
def save_state(ps_id=None, ps_key=None, device_name=None):
state = load_state() or {}
if device_name is not None:
state["device_name"] = device_name
if ps_id is not None:
state["ps_id"] = ps_id
if ps_key is not None:
state["ps_key"] = ps_key
with open(STATE_FILE, "w") as f:
json.dump(state, f, indent=4)
def load_state():
if not os.path.exists(STATE_FILE):
return None
with open(STATE_FILE) as f:
return json.load(f)
def load_ps_id():
state = load_state()
return state.get("ps_id") if state else None
def load_ps_key():
state = load_state()
return state.get("ps_key") if state else None
def load_device_name():
state = load_state()
return state.get("device_name") if state else None