Skip to content

Commit

Permalink
Improve JSON state parsing #6
Browse files Browse the repository at this point in the history
Support starting from an empty, existing file.
  • Loading branch information
rubenbe committed May 7, 2024
1 parent a7eff0a commit 1647a27
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions comfospot40/hal.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import asyncio
import json
import time
import logging


class Hal:
Expand Down Expand Up @@ -50,6 +51,10 @@ def storeState(self, storefile, state):
json.dump(state.toJSON(), storefile, indent=2)

def loadState(self, storefile, state):
loadedjson = json.load(storefile)
print(loadedjson)
try:
loadedjson = json.load(storefile)
except json.decoder.JSONDecodeError as e:
logging.info("Failed to decode json {}".format(e))
return
logging.info(loadedjson)
state.fromJSON(loadedjson)

0 comments on commit 1647a27

Please sign in to comment.