From c7ab6a78fbf2f44757193be712e38516679f58ed Mon Sep 17 00:00:00 2001 From: Trefor Southwell <48591903+springfall2008@users.noreply.github.com> Date: Sat, 10 Feb 2024 10:13:02 +0000 Subject: [PATCH] Auto restart - add a way to delete .pkl files (#745) * Auto restart - add a way to delete .pkl files * Update apps.yaml - add rm of pkl files --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> --- apps/predbat/config/apps.yaml | 1 + apps/predbat/predbat.py | 12 +++++++++++- docs/apps-yaml.md | 6 ++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/apps/predbat/config/apps.yaml b/apps/predbat/config/apps.yaml index 5473409f..7c55ec3f 100644 --- a/apps/predbat/config/apps.yaml +++ b/apps/predbat/config/apps.yaml @@ -73,6 +73,7 @@ pred_bat: # When enabled automatic restart will restart the add-on if communication fails # Example below is auto-restart for GivTCP add-on itself #auto_restart: + # - shell: 'rm -rf /homeassistant/GivTCP/*.pkl' # - service: hassio/addon_restart # addon: a6a2857d_givtcp diff --git a/apps/predbat/predbat.py b/apps/predbat/predbat.py index 095566d1..458d2d6c 100644 --- a/apps/predbat/predbat.py +++ b/apps/predbat/predbat.py @@ -21,7 +21,7 @@ import requests import yaml -THIS_VERSION = "v7.15.19" +THIS_VERSION = "v7.15.20" PREDBAT_FILES = ["predbat.py"] TIME_FORMAT = "%Y-%m-%dT%H:%M:%S%z" TIME_FORMAT_SECONDS = "%Y-%m-%dT%H:%M:%S.%f%z" @@ -1018,6 +1018,7 @@ def auto_restart(self, reason): if isinstance(restart_command, dict): restart_command = [restart_command] for command in restart_command: + shell = command.get("shell", None) service = command.get("service", None) addon = command.get("addon", None) if addon: @@ -1025,6 +1026,9 @@ def auto_restart(self, reason): entity_id = command.get("entity_id", None) if entity_id: entity_id = self.base.resolve_arg(service, entity_id, indirect=False) + if shell: + self.log("Calling restart shell command: {}".format(shell)) + os.system(shell) if service: if addon: self.log("Calling restart service {} with addon {}".format(service, addon)) @@ -10160,6 +10164,12 @@ def execute_plan(self): return status, status_extra def fetch_octopus_rates(self, entity_id, adjust_key=None): + """ + Fetch the Octopus rates from the sensor + + :param entity_id: The entity_id of the sensor + :param adjust_key: The key use to find Octopus Intelligent adjusted rates + """ data_all = [] rate_data = {} diff --git a/docs/apps-yaml.md b/docs/apps-yaml.md index 9661938e..5e64d6fa 100644 --- a/docs/apps-yaml.md +++ b/docs/apps-yaml.md @@ -455,8 +455,14 @@ Right now only communication loss with GE inverters is detectable but in future When enabled if communication is lost then the service configured will be triggered and can cause a restart which may restart the connection. This maybe useful with GivTCP if you have time sync errors or lost of REST service every now and again. +The auto_restart itself is a list of commands to run to trigger a restart. + +- The **shell** command will call a 'sh' shell and can be used to delete files and suchlike. +- The **service** command is used to call a service, and can contain arguments of **addon** and/or **entity_id** + ```yaml auto_restart: + - shell: 'rm -rf /homeassistant/GivTCP/*.pkl' - service: hassio/addon_restart addon: a6a2857d_givtcp ```