From 091aa8aa17f65cc9a23037d68124302ee301d616 Mon Sep 17 00:00:00 2001 From: Rob Pearce Date: Sat, 25 Nov 2023 13:12:56 +1100 Subject: [PATCH] Killfile can now contain a unixtime, after which it expires. --- aircon.sh | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/aircon.sh b/aircon.sh index e88fa0d..81b9b8e 100755 --- a/aircon.sh +++ b/aircon.sh @@ -66,7 +66,9 @@ function usage() { 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)." - echo " -k file If file exists, never change aircon settings (default: $DEFAULT_KILLFILE)." + echo " -k file If file exists and is empty, never change aircon settings (default: $DEFAULT_KILLFILE)." + echo " If file is non-empty, never change aircon settings if current unixtime < file contents." + echo " File will be removed if current unixtime >= file contents." echo " -l num Set number of too hot/cold zones at which to taking action." echo " -L Log all zone temperatures to CSV file, then exit (see -o)." echo " -m Generate a config file based on current aircon setup." @@ -1698,13 +1700,29 @@ function show_analysis() { [[ $count -eq 0 ]] && echo -e "${GREEN}All is good!${PLAIN}" } +function killfile_active() { # returns true if killfile swill stop us + local val now + if [[ ! -f ${KILLFILE} ]]; then + return 1 + fi + val=$(cat "${KILLFILE}") + [[ -z $val ]] && return 1 + now=$(date +%s) + if [[ $val -le $now ]]; then + # killfile expired + rm -f "${KILLFILE}" + return 1 + fi + return 0 +} + function show_proposed_commands() { local str x maxlen count cmdformat fullcmd str="Proposed commands" echo -e "${UNDERLINE}${str}:${PLAIN}" if [[ $nairconcommands -gt 0 ]]; then - if [[ -f ${KILLFILE} ]]; then + if killfile_active; then echo -e "${RED}Not running commands because killfile exists ($KILLFILE)${PLAIN}" elif [[ $DOIT -ne 1 ]]; then echo -e "${RED}Not running commands because -y not specified${PLAIN}" @@ -2197,7 +2215,7 @@ fi # Actually run the commands if [[ $DOIT -eq 1 ]]; then - if [[ ! -f ${KILLFILE} ]]; then + if ! killfile_active; then run_commands [[ $cronmode -ne 1 ]] && echo fi