Skip to content

Commit

Permalink
LoadData and SaveDate was reversed
Browse files Browse the repository at this point in the history
  • Loading branch information
Sdahl1234 authored Feb 28, 2024
1 parent d6c34f6 commit 26e948a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
38 changes: 22 additions & 16 deletions custom_components/seven_segments_alt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class SSDataCoordinator(DataUpdateCoordinator): # noqa: D101
image_entity_2: ImageEntity
image_entity_3: ImageEntity
ocr_image: Image
ocr_entity: ImageProcessingEntity # ImageProcessingSsocr
ocr_entity: ImageProcessingEntity
ocr_state: str = None
camera_entity_id: str
jdata: None
Expand Down Expand Up @@ -189,24 +189,30 @@ async def file_exits(self):

async def save_data(self, append: bool):
"""Save data."""
if append:
cfile = open(self.filepath, "w", encoding="utf-8")
else:
cfile = open(self.filepath, "a", encoding="utf-8")
ocrdata = json.dumps(self.jdata)
cfile.write(ocrdata)
cfile.close()
try:
if append:
cfile = open(self.filepath, "w", encoding="utf-8")
else:
cfile = open(self.filepath, "a", encoding="utf-8")
ocrdata = json.dumps(self.jdata)
cfile.write(ocrdata)
cfile.close()
except Exception as ex: # pylint: disable=broad-except
_LOGGER.debug(f"Save data failed: {ex}") # noqa: G004

async def load_data(self):
"""Load data."""
cfile = open(self.filepath, encoding="utf-8")
ocrdata = cfile.read()
cfile.close()
_LOGGER.debug(f"ocrdata: {ocrdata}") # noqa: G004
_LOGGER.debug(f"jsonload: {json.loads(ocrdata)}") # noqa: G004

self.jdata = json.loads(ocrdata)
self.data_loaded = True
try:
cfile = open(self.filepath, encoding="utf-8")
ocrdata = cfile.read()
cfile.close()
_LOGGER.debug(f"ocrdata: {ocrdata}") # noqa: G004
_LOGGER.debug(f"jsonload: {json.loads(ocrdata)}") # noqa: G004

self.jdata = json.loads(ocrdata)
self.data_loaded = True
except Exception as ex: # pylint: disable=broad-except
_LOGGER.debug(f"load data failed: {ex}") # noqa: G004

async def _async_update_data(self):
try:
Expand Down
4 changes: 2 additions & 2 deletions custom_components/seven_segments_alt/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
},
"button": {
"ss_save_data": {
"name": "Load data"
"name": "Save data"
},
"ss_load_data": {
"name": "Save data"
"name": "Load data"
}
},
"number": {
Expand Down

0 comments on commit 26e948a

Please sign in to comment.