Add html output mode when showing rules (-H)

This commit is contained in:
Rob Pearce 2021-12-05 16:51:14 +11:00
parent 8ccbdc902c
commit f0dce13580
1 changed files with 80 additions and 29 deletions

109
aircon.sh
View File

@ -878,6 +878,8 @@ function processtimeconditions() {
local this_human local this_human
local keepgoing=0 local keepgoing=0
local ok=0 local ok=0
local nonmatches=0
local rv
if [[ $1 == "-c" ]]; then if [[ $1 == "-c" ]]; then
keepgoing=1 keepgoing=1
shift 1 shift 1
@ -960,6 +962,7 @@ function processtimeconditions() {
ok=1 ok=1
fi fi
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 0 ]] && info " $nowh isn't in range $cond"
[[ $db -eq 1 && $ok -eq 1 ]] && info " MATCH: $nowh within range $cond" [[ $db -eq 1 && $ok -eq 1 ]] && info " MATCH: $nowh within range $cond"
fi fi
@ -968,33 +971,77 @@ function processtimeconditions() {
break break
fi fi
done done
return $((1 - $ok))
if [[ $ok -eq 0 || $nonmatches -gt 0 ]]; then
rv=1
else
rv=0
fi
return $rv
} }
function active_cols() { function active_cols() {
inactc="$RED" if [[ $RULEFORMAT == "html" ]]; then
linec=${PLAIN} plainc="<font color=#000000></strong></s>" # black
devc="$GREEN" inactc="<font color=#ff0000>" # red
devbc="$BOLD$devc" linec="<font color=#000000></strong></s>" # black
statec="$BOLD$YELLOW" devc="<font color=#00aa00>" # green+bold
roomc="$ORANGE" devbc="<strong><font color=#00aa00>" # green
timec="$PINK" statec="<strong><font color=#bbbb00>" # yellow+bold
timebc="$BOLD$timec" roomc="<font color=#ffa500>" # orange
minc="$BOLD$BLUE" timec="<font color=#ff97c6>" # pink
maxc="$BOLD$RED" timebc="<strong><font color=#ff97c6>" # pink+bold
minc="<strong><font color=#0000dd>" # blue+bold
maxc="<strong><font color=#dd0000>" # red+bold
coolc="<strong><font color=#00dddd>" # cyan+bold
heatc="<strong><font color=#dd0000>" # red+bold
nl="<br></s></strong><font color=#000000>\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() { function inactive_cols() {
inactc="$DARKGREY" if [[ $RULEFORMAT == "html" ]]; then
linec="${inactc}" plainc="<font color=#000000></strong></s>" # black
devc="$inactc" inactc="<s><font color=#aaaaaa>" # lightgrey
devbc="$inactc" linec=""
statec="$inactc" devc=""
roomc="$inactc" devbc=""
timec="$inactc" statec=""
timebc="$inactc" roomc=""
minc="$inactc" timec=""
maxc="$inactc" timebc=""
minc=""
maxc=""
nl="</s><br>\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() { function parse_config() {
@ -1054,7 +1101,7 @@ function parse_config() {
[[ $adj != "open" ]] && adj="${adj}d" [[ $adj != "open" ]] && adj="${adj}d"
line_human="${line_human}Force the vent in ${roomc}${tok[1]}${linec} to be ${statec}${adj}${linec}" line_human="${line_human}Force the vent in ${roomc}${tok[1]}${linec} to be ${statec}${adj}${linec}"
else 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 fileok=0
fi fi
elif [[ ${tok[0]} == "owner" ]]; then elif [[ ${tok[0]} == "owner" ]]; then
@ -1071,24 +1118,24 @@ function parse_config() {
if [[ $VALID_MODES == *\ ${tok[1]}\ * ]]; then if [[ $VALID_MODES == *\ ${tok[1]}\ * ]]; then
local col local col
modelock="${tok[1]}" 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" line_human="${line_human}Only operate the aircon in ${col}${tok[1]}${linec} mode"
else 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 fileok=0
fi fi
elif [[ ${tok[0]} == "test" ]]; then elif [[ ${tok[0]} == "test" ]]; then
line_human="${line_human}Got test option '${roomc}${tok[1]}${linec}'" line_human="${line_human}Got test option '${roomc}${tok[1]}${linec}'"
elif [[ -n $line ]]; then elif [[ -n $line ]]; then
errstr="${errstr}${linenum}:Syntax error: ${line}\n" errstr="${errstr}${linenum}:Syntax error: ${line}$nl"
fileok=0 fileok=0
fi fi
fi fi
if [[ -n $line_human ]]; then if [[ -n $line_human ]]; then
if [[ $ok -eq 0 ]]; then if [[ $ok -eq 0 ]]; then
line_human="${PLAIN}${inactc}<INACTIVE> ${linec}${line_human}" line_human="${plainc}${inactc}<INACTIVE> ${linec}${line_human}"
fi fi
config_human="${config_human}- ${linec}${line_human}${PLAIN}\n" config_human="${config_human}- ${linec}${line_human}${plainc}$nl"
fi fi
linenum=$((linenum + 1)) linenum=$((linenum + 1))
done < "$CONFIGFILE" done < "$CONFIGFILE"
@ -1102,7 +1149,7 @@ function parse_config() {
rv=0 rv=0
else else
error "Configuration file is invalid:" error "Configuration file is invalid:"
echo -e "${RED}$errstr${PLAIN}" | sed -e 's/^/ /' echo -e "${RED}$errstr${plainc}" | sed -e 's/^/ /'
rv=1 rv=1
fi fi
return $rv return $rv
@ -1505,6 +1552,7 @@ limit=$DEFAULTLIMIT
profiler=0 profiler=0
csvfile="$DEFAULT_CSVFILE" csvfile="$DEFAULT_CSVFILE"
sanitycheck=0 sanitycheck=0
RULEFORMAT=ansi
# check for config file option first # check for config file option first
@ -1523,13 +1571,16 @@ fi
ALLARGS="$ALLARGS $*" 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 while getopts "$optstring" i $ALLARGS; do
case "$i" in case "$i" in
h) h)
usage; usage;
exit 1; exit 1;
;; ;;
H)
RULEFORMAT=html
;;
f) f)
CONFIGFILE=${OPTARG} CONFIGFILE=${OPTARG}
;; ;;