Skip to content

Commit

Permalink
Auto restart - add a way to delete .pkl files (#745)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
springfall2008 and pre-commit-ci-lite[bot] authored Feb 10, 2024
1 parent 916a3bc commit c7ab6a7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions apps/predbat/config/apps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 11 additions & 1 deletion apps/predbat/predbat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -1018,13 +1018,17 @@ 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:
addon = self.base.resolve_arg(service, addon, indirect=False)
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))
Expand Down Expand Up @@ -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 = {}

Expand Down
6 changes: 6 additions & 0 deletions docs/apps-yaml.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down

0 comments on commit c7ab6a7

Please sign in to comment.