diff --git a/aircon.sh b/aircon.sh index c365955..f428bf8 100755 --- a/aircon.sh +++ b/aircon.sh @@ -878,6 +878,8 @@ function processtimeconditions() { local this_human local keepgoing=0 local ok=0 + local nonmatches=0 + local rv if [[ $1 == "-c" ]]; then keepgoing=1 shift 1 @@ -960,6 +962,7 @@ function processtimeconditions() { ok=1 fi fi + [[ $ok -eq 0 ]] && nonmatches=$((nonmatches + 1)) [[ $db -eq 1 && $ok -eq 0 ]] && info " $nowh isn't in range $cond" [[ $db -eq 1 && $ok -eq 1 ]] && info " MATCH: $nowh within range $cond" fi @@ -968,33 +971,77 @@ function processtimeconditions() { break fi done - return $((1 - $ok)) + + if [[ $ok -eq 0 || $nonmatches -gt 0 ]]; then + rv=1 + else + rv=0 + fi + return $rv } function active_cols() { - inactc="$RED" - linec=${PLAIN} - devc="$GREEN" - devbc="$BOLD$devc" - statec="$BOLD$YELLOW" - roomc="$ORANGE" - timec="$PINK" - timebc="$BOLD$timec" - minc="$BOLD$BLUE" - maxc="$BOLD$RED" + if [[ $RULEFORMAT == "html" ]]; then + plainc="" # black + inactc="" # red + linec="" # black + devc="" # green+bold + devbc="" # green + statec="" # yellow+bold + roomc="" # orange + timec="" # pink + timebc="" # pink+bold + minc="" # blue+bold + maxc="" # red+bold + coolc="" # cyan+bold + heatc="" # red+bold + nl="
\n" + else + plainc=${PLAIN} + inactc="$RED" + linec=${PLAIN} + devc="$GREEN" + devbc="$BOLD$devc" + statec="$BOLD$YELLOW" + roomc="$ORANGE" + timec="$PINK" + timebc="$BOLD$timec" + minc="$BOLD$BLUE" + maxc="$BOLD$RED" + coolc="$BOLD$CYAN" + heatc="$RED" + nl="\n" + fi } function inactive_cols() { - inactc="$DARKGREY" - linec="${inactc}" - devc="$inactc" - devbc="$inactc" - statec="$inactc" - roomc="$inactc" - timec="$inactc" - timebc="$inactc" - minc="$inactc" - maxc="$inactc" + if [[ $RULEFORMAT == "html" ]]; then + plainc="
" # black + inactc="" # lightgrey + linec="" + devc="" + devbc="" + statec="" + roomc="" + timec="" + timebc="" + minc="" + maxc="" + nl="
\n" + else + plainc=${PLAIN} + inactc="$DARKGREY" + linec="${inactc}" + devc="$inactc" + devbc="$inactc" + statec="$inactc" + roomc="$inactc" + timec="$inactc" + timebc="$inactc" + minc="$inactc" + maxc="$inactc" + nl="\n" + fi } function parse_config() { @@ -1054,7 +1101,7 @@ function parse_config() { [[ $adj != "open" ]] && adj="${adj}d" line_human="${line_human}Force the vent in ${roomc}${tok[1]}${linec} to be ${statec}${adj}${linec}" else - errstr="${errstr}${linenum}:Invalid zone state '${tok[2]}'. Valid options are: $VALID_ZONE_STATES\n" + errstr="${errstr}${linenum}:Invalid zone state '${tok[2]}'. Valid options are: $VALID_ZONE_STATES$nl" fileok=0 fi elif [[ ${tok[0]} == "owner" ]]; then @@ -1071,24 +1118,24 @@ function parse_config() { if [[ $VALID_MODES == *\ ${tok[1]}\ * ]]; then local col modelock="${tok[1]}" - [[ $modelock == "cool" ]] && col="$BOLD$CYAN" || col="$RED" + [[ $modelock == "cool" ]] && col="$coolc" || col="$heatc" line_human="${line_human}Only operate the aircon in ${col}${tok[1]}${linec} mode" else - errstr="${errstr}${linenum}:Invalid modelock '${tok[1]}'. Valid options are: $VALID_MODES\n" + errstr="${errstr}${linenum}:Invalid modelock '${tok[1]}'. Valid options are: $VALID_MODES$nl" fileok=0 fi elif [[ ${tok[0]} == "test" ]]; then line_human="${line_human}Got test option '${roomc}${tok[1]}${linec}'" elif [[ -n $line ]]; then - errstr="${errstr}${linenum}:Syntax error: ${line}\n" + errstr="${errstr}${linenum}:Syntax error: ${line}$nl" fileok=0 fi fi if [[ -n $line_human ]]; then if [[ $ok -eq 0 ]]; then - line_human="${PLAIN}${inactc} ${linec}${line_human}" + line_human="${plainc}${inactc} ${linec}${line_human}" fi - config_human="${config_human}- ${linec}${line_human}${PLAIN}\n" + config_human="${config_human}- ${linec}${line_human}${plainc}$nl" fi linenum=$((linenum + 1)) done < "$CONFIGFILE" @@ -1102,7 +1149,7 @@ function parse_config() { rv=0 else error "Configuration file is invalid:" - echo -e "${RED}$errstr${PLAIN}" | sed -e 's/^/ /' + echo -e "${RED}$errstr${plainc}" | sed -e 's/^/ /' rv=1 fi return $rv @@ -1505,6 +1552,7 @@ limit=$DEFAULTLIMIT profiler=0 csvfile="$DEFAULT_CSVFILE" sanitycheck=0 +RULEFORMAT=ansi # check for config file option first @@ -1523,13 +1571,16 @@ fi ALLARGS="$ALLARGS $*" -optstring="A:cf:hi:I:k:l:Lo:pmsSt:T:wx:y" +optstring="A:cf:hHi:I:k:l:Lo:pmsSt:T:wx:y" while getopts "$optstring" i $ALLARGS; do case "$i" in h) usage; exit 1; ;; + H) + RULEFORMAT=html + ;; f) CONFIGFILE=${OPTARG} ;;