diff --git a/rpc_shutdown/CHANGELOG.md b/rpc_shutdown/CHANGELOG.md index e8ed207..1fe966d 100644 --- a/rpc_shutdown/CHANGELOG.md +++ b/rpc_shutdown/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 2.1 + +- Set delay to zero when it is empty (to not break existing configurations) +- Update from bash to bashio + ## 2.0 - New option to delay shutting down the Windows PC diff --git a/rpc_shutdown/config.json b/rpc_shutdown/config.json index b4cc95a..fcec27c 100644 --- a/rpc_shutdown/config.json +++ b/rpc_shutdown/config.json @@ -1,6 +1,6 @@ { "name": "RPC Shutdown", - "version": "2.0", + "version": "2.1", "slug": "rpc_shutdown", "description": "Simple way for remote windows shutdowns", "url": "https://home-assistant.io/addons/rpc_shutdown/", diff --git a/rpc_shutdown/run.sh b/rpc_shutdown/run.sh index 7102bc5..7519789 100755 --- a/rpc_shutdown/run.sh +++ b/rpc_shutdown/run.sh @@ -1,32 +1,33 @@ -#!/bin/bash +#!/usr/bin/env bashio set -e -CONFIG_PATH=/data/options.json - -COMPUTERS=$(jq --raw-output '.computers | length' $CONFIG_PATH) - # Read from STDIN aliases to send shutdown while read -r input; do - # remove json stuff - input="$(echo "$input" | jq --raw-output '.')" - echo "[Info] Read alias: $input" + # parse JSON value + input=$(bashio::jq "${input}" '.') + bashio::log.info "Read alias: $input" # Find aliases -> computer - for (( i=0; i < "$COMPUTERS"; i++ )); do - ALIAS=$(jq --raw-output ".computers[$i].alias" $CONFIG_PATH) - ADDRESS=$(jq --raw-output ".computers[$i].address" $CONFIG_PATH) - CREDENTIALS=$(jq --raw-output ".computers[$i].credentials" $CONFIG_PATH) - DELAY=$(jq --raw-output ".computers[$i].delay" $CONFIG_PATH) - MESSAGE=$(jq --raw-output ".computers[$i].message" $CONFIG_PATH) - + for computer in $(bashio::config 'computers|keys'); do + ALIAS=$(bashio::config "computers[${computer}].alias") + ADDRESS=$(bashio::config "computers[${computer}].address") + CREDENTIALS=$(bashio::config "computers[${computer}].credentials") + DELAY=$(bashio::config "computers[${computer}].delay") + MESSAGE=$(bashio::config "computers[${computer}].message") + # Not the correct alias - if [ "$ALIAS" != "$input" ]; then + if ! bashio::var.equals "$ALIAS" "$input"; then continue fi - - echo "[Info] Shutdown $input -> $ADDRESS" + + # Check if delay is not empty + if bashio::var.is_empty "${DELAY}"; then + DELAY="0" + fi + + bashio::log.info "Shutdown $input -> $ADDRESS" if ! msg="$(net rpc shutdown -I "$ADDRESS" -U "$CREDENTIALS" -t "$DELAY" -C "$MESSAGE")"; then - echo "[Error] Shutdown fails -> $msg" + bashio::log.error "Shutdown fails -> $msg" fi done done \ No newline at end of file