diff --git a/aircon.sh b/aircon.sh index 2ee0500..8f7843b 100755 --- a/aircon.sh +++ b/aircon.sh @@ -134,6 +134,10 @@ function getzoneaction() { # populates zproblem[] and zaction[] fi fv=$(getforcevent ${zname[$idx]}) +if [[ $robtest -eq 1 ]]; then + echo "canping zone ${zname[$idx]} is: $pingok" +fi + donearby=0 if [[ -n $fv && ${zstate[$idx]} == $(getoppositestate ${fv}) ]]; then @@ -162,7 +166,7 @@ function getzoneaction() { # populates zproblem[] and zaction[] if [[ ${zwanttemp[$idx]} != *-* ]]; then thisperfect=1 else - local mid midtol + local mid midtol mid=$(get_midrange $idx) midtol=$(get_perfect_tolerance $idx) #echo "zone ${zname[$idx]} temp ${ztemp[$idx]} mid is $mid midtol is $midtol perfect is >= $(echo "$mid - $midtol" | bc)" @@ -274,11 +278,16 @@ function getzoneaction() { # populates zproblem[] and zaction[] function getidxfromname() { # name local x +#echo "==== getidxfromname($1)" >/dev/stderr for x in ${!zname[@]}; do - if [[ ${zname[$x]} == $1 ]]; then +#echo "==== idx $x comparing zname ('${zname[$x]}') to \$1 ('$1')" >/dev/stderr + if [[ ${zname[$x]} == "$1" ]]; then +#echo " ==== matched. returning ${x}" >/dev/stderr echo "${x}" + return fi done + echo "-1" } function getnamefromid() { # id @@ -802,6 +811,7 @@ function addperson() { function addowner() { # zone "host1 host2 ..." local z h local x idx db doset=0 + local zidx db=0 if [[ $1 == "-s" ]]; then doset=1 @@ -812,6 +822,13 @@ function addowner() { # zone "host1 host2 ..." shift h="$*" + + zidx=$(getidxfromname "$z") # get the index into the zname[] etc arrays + if [[ $zidx -eq -1 ]]; then + error "Failed to set owner of zone '$z' to '$h' - zone doesn't exist. " + exit 1; + fi + [[ $db -eq 1 ]] && info "addowner() zone $z host(s) [$h]" idx=$nowners @@ -830,9 +847,9 @@ function addowner() { # zone "host1 host2 ..." [[ $idx == $nowners ]] && nowners=$((nowners + 1)) if [[ $doset -eq 1 ]]; then - local zidx - zidx=$(getidxfromname "$z") zowner[$zidx]="${ownerhost[$idx]}"; + + [[ $db -eq 1 ]] && info " doing set of zowner[$zidx] (${zname[$zidx]}} to [${ownerhost[$idx]}]" #zownerperson[$zidx]=$(getownerperson "$z"); # may be overwritten later fi } @@ -852,7 +869,7 @@ function addowner() { # zone "host1 host2 ..." #} # getowner zone_name -# returns devices associated woth zone +# returns devices associated with zone function getowner() { local x retval retval="" @@ -899,7 +916,7 @@ function weekdaytonum() { "mon") num=1;; "tue") num=2;; "wed") num=3;; - "thu") num=4;; + "thu") num=4;; "fri") num=5;; "sat") num=6;; "sun") num=7;; @@ -1706,6 +1723,7 @@ profiler=0 csvfile="$DEFAULT_CSVFILE" sanitycheck=0 RULEFORMAT=ansi +robtest=0 # check for config file option first if [[ $* == *-f\ * ]]; then @@ -1723,7 +1741,7 @@ fi ALLARGS="$ALLARGS $*" -optstring="A:cD:f:hHi:I:k:l:Lo:pmsSt:T:wWx:y" +optstring="A:cD:f:hHi:I:k:l:Lo:pmRsSt:T:wWx:y" while getopts "$optstring" i $ALLARGS; do case "$i" in h) @@ -1767,6 +1785,9 @@ while getopts "$optstring" i $ALLARGS; do T) tolerance_h=${OPTARG} ;; + R) + robtest=1 + ;; c) enable_cronmode ;; @@ -1862,6 +1883,13 @@ for x in ${devices}; do done wait +if [[ $robtest -eq 1 ]]; then + for x in ${!zname[@]}; do + echo "zone ${zname[$x]} owner is [${zowner[$x]}]" + done + exit 1 +fi + if [[ $showwho -eq 1 ]]; then # get max phone name length maxlen=1