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 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="<font color=#000000></strong></s>" # black
inactc="<font color=#ff0000>" # red
linec="<font color=#000000></strong></s>" # black
devc="<font color=#00aa00>" # green+bold
devbc="<strong><font color=#00aa00>" # green
statec="<strong><font color=#bbbb00>" # yellow+bold
roomc="<font color=#ffa500>" # orange
timec="<font color=#ff97c6>" # pink
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() {
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="<font color=#000000></strong></s>" # black
inactc="<s><font color=#aaaaaa>" # lightgrey
linec=""
devc=""
devbc=""
statec=""
roomc=""
timec=""
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() {
@ -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}<INACTIVE> ${linec}${line_human}"
line_human="${plainc}${inactc}<INACTIVE> ${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}
;;