diff --git a/aircon.sh b/aircon.sh index 4116dc7..c3d802e 100755 --- a/aircon.sh +++ b/aircon.sh @@ -68,6 +68,7 @@ function usage() { echo " bottoken" echo " chatid" echo " -f file Specify an alternate config file." + echo " -F zonename:temp Forcibly provide current zone temperature (for testing)" echo " -h Show this text." echo " -i x.x.x.x Specify IP address for aircon (default is $DEFAULT_AIRCON_IP)" echo " -I db Log all zone temperatures to given influxdb database, then exit (see -o)." @@ -225,7 +226,7 @@ function getzoneaction() { # populates zproblem[] and zaction[] fi # if we couldnt turn the system on, there's nothing else to do - if [[ $airconmode == "heat" ]]; then + if [[ $airconmode == "heat" || $thisaction == *set_mode:heat* ]]; then # adjust set temperature, if required if [[ $(echo "${zsettemp[$idx]} > ${zwantmax[$idx]}" | bc) -eq 1 || $(echo "${zsettemp[$idx]} < ${zwantmin[$idx]}" | bc) -eq 1 ]]; then # set temperature to midpoint of acceptable range @@ -264,7 +265,7 @@ function getzoneaction() { # populates zproblem[] and zaction[] fi # if we couldnt turn the system on, there's nothing else to do - if [[ $airconmode == "cool" ]]; then + if [[ $airconmode == "cool" || $thisaction == *set_mode:cool* ]]; then # adjust set temperature, if required if [[ $(echo "${zsettemp[$idx]} > ${zwantmax[$idx]}" | bc) -eq 1 || $(echo "${zsettemp[$idx]} < ${zwantmin[$idx]}" | bc) -eq 1 ]]; then # set temperature to midpoint of acceptable range @@ -2081,8 +2082,9 @@ ALLARGS="$ALLARGS $*" expirenotifyfile="" expirenotifytext="" +FAKESTRING="" -optstring="aA:bcD:e:E:f:g:hHi:I:k:l:Lo:pmRsSt:T:wWy" +optstring="aA:bcD:e:E:f:F:g:hHi:I:k:l:Lo:pmRsSt:T:wWy" while getopts "$optstring" i $ALLARGS; do case "$i" in a) @@ -2109,6 +2111,9 @@ while getopts "$optstring" i $ALLARGS; do f) CONFIGFILE=${OPTARG} ;; + F) + FAKESTRING="${FAKESTRING} ${OPTARG}" + ;; g) USETELEGRAM=1 TELEGRAM_FILE=${OPTARG} @@ -2244,6 +2249,25 @@ else exit 1 fi +# fake input for testing +for x in ${FAKESTRING}; do + fake_name="${x%%:*}" + fake_wanttemp="${x##*:}" + fake_idx=-1 + for zi in ${!zname[@]}; do + if [[ ${zname[zi]^^} == ${fake_name^^} ]]; then + fake_idx=$zi + break + fi + done + if [[ ${fake_idx} -eq -1 ]]; then + error "Unknown zone '${fake_name}' in -f argument '${x}'" + exit 1; + fi + ztemp[$fake_idx]="$fake_wanttemp" + info "Faking zone '${fake_name}' temp to ${fake_wanttemp}" +done + # ping all hosts in background to populate arp table #for x in ${devices}; do # ping -c1 -w1 -n -q $ip >/dev/null 2>&1 &