Support the changes in specific files without restarting home assistant (#475)

* Support the changes in specific files without restarting home assistant

Support the changes in specific files without restarting home assistant.  Files such as the lovelace config can be picked up without a restart of the service, decreasing impact of changes.

* Syntax Changes

* Shellcheck Fixes

* Remove extra quote

* Update config.json

* Update CHANGELOG.md
This commit is contained in:
Adam Goodbar
2018-12-06 02:44:34 -08:00
committed by Pascal Vizeli
parent d0424b83d5
commit 65082b5361
3 changed files with 30 additions and 3 deletions

View File

@@ -1,5 +1,8 @@
# Changelog
## 6
- Allow to disable Home Assistant restart for specific file changes
## 5
- Update Hass.io CLI to 1.4.0
- Add new API role profile

View File

@@ -1,6 +1,6 @@
{
"name": "Git pull",
"version": "5",
"version": "6",
"slug": "git_pull",
"description": "Simple git pull to update the local configuration",
"url": "https://home-assistant.io/addons/git_pull/",
@@ -20,6 +20,10 @@
"git_prune": false,
"repository": null,
"auto_restart": false,
"restart_ignore": [
"ui-lovelace.yaml",
".gitignore"
],
"repeat": {
"active": false,
"interval": 300
@@ -36,6 +40,7 @@
"git_prune": "bool",
"repository": "match((?:.+):(\/\/)?(.*?)(\\.git)(\/?|\\#[-\\d\\w._]+?))",
"auto_restart": "bool",
"restart_ignore": ["str"],
"repeat": {
"active": "bool",
"interval": "int"

View File

@@ -14,6 +14,7 @@ GIT_REMOTE=$(jq --raw-output '.git_remote' $CONFIG_PATH)
GIT_PRUNE=$(jq --raw-output '.git_prune' $CONFIG_PATH)
REPOSITORY=$(jq --raw-output '.repository' $CONFIG_PATH)
AUTO_RESTART=$(jq --raw-output '.auto_restart' $CONFIG_PATH)
RESTART_IGNORED_FILES=$(jq --raw-output '.restart_ignore | join(" ")' $CONFIG_PATH)
REPEAT_ACTIVE=$(jq --raw-output '.repeat.active' $CONFIG_PATH)
REPEAT_INTERVAL=$(jq --raw-output '.repeat.interval' $CONFIG_PATH)
################
@@ -177,8 +178,26 @@ function validate-config {
echo "[Info] Something has changed, check Home-Assistant config"
if hassio homeassistant check; then
if [ "$AUTO_RESTART" == "true" ]; then
echo "[Info] Restart Home-Assistant"
hassio homeassistant restart 2&> /dev/null
DO_RESTART="false"
CHANGED_FILES=$(git diff "$OLD_COMMIT" .. "$NEW_COMMIT" --name-only)
echo "Changed Files: $CHANGED_FILES"
if [ -n "$RESTART_IGNORED_FILES" ]; then
for file in $CHANGED_FILES; do
echo "$RESTART_IGNORED_FILES" | grep -qw "${file}"
if [ $? -eq 1 ] ; then
DO_RESTART="true"
echo "[Info] Detected Restart Required File $file"
fi
done
else
DO_RESTART="true"
fi
if [ "$DO_RESTART" == "true" ]; then
echo "[Info] Restart Home-Assistant"
hassio homeassistant restart 2&> /dev/null
else
echo "[Info] No Restart Required, only ignored changes detected"
fi
else
echo "[Info] Local configuration has changed. Restart required."
fi