Skip to content

Commit

Permalink
Moved settings save/restore directory to config (#1170)
Browse files Browse the repository at this point in the history
* Moved settings save/restore directory to config

* Fix crash

* [pre-commit.ci lite] apply automatic fixes

---------

Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
  • Loading branch information
springfall2008 and pre-commit-ci-lite[bot] committed Jun 2, 2024
1 parent 78b9f7b commit 9ba854d
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions apps/predbat/predbat.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
if not "PRED_GLOBAL" in globals():
PRED_GLOBAL = {}

THIS_VERSION = "v7.21.5"
THIS_VERSION = "v7.22.0"
PREDBAT_FILES = ["predbat.py"]
TIME_FORMAT = "%Y-%m-%dT%H:%M:%S%z"
TIME_FORMAT_SECONDS = "%Y-%m-%dT%H:%M:%S.%f%z"
Expand All @@ -46,7 +46,6 @@
PREDICT_STEP = 5
RUN_EVERY = 5
CONFIG_ROOTS = ["/config", "/conf", "/homeassistant", "./"]
CONFIG_ROOTS_HA = ["/homeassistant", "/conf", "/config", "./"]
TIME_FORMAT_HA = "%Y-%m-%dT%H:%M:%S%z"
TIMEOUT = 60 * 5
CONFIG_REFRESH_PERIOD = 60 * 8
Expand Down Expand Up @@ -4444,12 +4443,18 @@ def call_notify(self, message):
self.call_service_wrapper("notify/" + device, message=message)
return True

def call_service_wrapper_stub2(self, service, message):
"""
Stub for 2 arg service wrapper
"""
return self.call_service_wrapper(service, message=message)

async def async_call_notify(self, message):
"""
Send HA notifications
"""
for device in self.notify_devices:
await self.call_service_wrapper("notify/" + device, message=message)
await self.run_in_executor(self.call_service_wrapper_stub2, "notify/" + device, message)
return True

def resolve_arg(self, arg, value, default=None, indirect=True, combine=False, attribute=None, index=None, extra_args=None):
Expand Down Expand Up @@ -14818,13 +14823,7 @@ def update_save_restore_list(self):
Update list of current Predbat settings
"""
global PREDBAT_SAVE_RESTORE
self.save_restore_dir = None
for root in CONFIG_ROOTS_HA:
if os.path.exists(root):
self.save_restore_dir = root + "/predbat_save"
break
if not self.save_restore_dir:
return
self.save_restore_dir = self.config_root + "/predbat_save"

if not os.path.exists(self.save_restore_dir):
os.mkdir(self.save_restore_dir)
Expand All @@ -14843,13 +14842,7 @@ async def async_restore_settings_yaml(self, filename):
"""
Restore settings from YAML file
"""
self.save_restore_dir = None
for root in CONFIG_ROOTS_HA:
if os.path.exists(root):
self.save_restore_dir = root + "/predbat_save"
break
if not self.save_restore_dir:
return
self.save_restore_dir = self.config_root + "/predbat_save"

if filename != "previous.yaml":
await self.async_save_settings_yaml("previous.yaml")
Expand Down Expand Up @@ -14879,8 +14872,7 @@ async def async_save_settings_yaml(self, filename=None):
"""
Save current Predbat settings
"""
if not self.save_restore_dir:
return
self.save_restore_dir = self.config_root + "/predbat_save"

if not filename:
filename = self.now_utc.strftime("%y_%m_%d_%H_%M_%S")
Expand Down Expand Up @@ -15588,7 +15580,8 @@ async def socketLoop(self):
else:
self.log("Info: Web Socket unknown message {}".format(data))
except Exception as e:
self.log("Warn Web Socket exception in update loop: {}".format(e))
self.log("Error: Web Socket exception in update loop: {}".format(e))
self.log("Error: " + traceback.format_exc())
break

elif message.type == WSMsgType.CLOSED:
Expand All @@ -15597,7 +15590,8 @@ async def socketLoop(self):
break

except Exception as e:
self.log("Warn: Web Socket exception in startup: {}".format(e))
self.log("Error: Web Socket exception in startup: {}".format(e))
self.log("Error: " + traceback.format_exc())
continue

if not self.base.stop_thread:
Expand Down

0 comments on commit 9ba854d

Please sign in to comment.