Skip to content

Commit

Permalink
print unifi mode (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
psmsmets committed Jan 7, 2022
1 parent 23b4600 commit 9b9dc89
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions thermmode-unifi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function usage {
"Options:"
" -C, --config Print a demo configuration file with all variables"
" -h, --help Print help"
" -m, --mode Print previous unifi mode"
" -v, --verbose Make the operation more talkative"
" -V, --version Show version number and quit"
)
Expand Down Expand Up @@ -419,6 +420,17 @@ function verbose {
}


#-------------------------------------------------------------------------------
#
# Previous run thermmode status
#
#-------------------------------------------------------------------------------

touch $HOME/.thermmode-unifi.mode

previous_mode=$(cat $HOME/.thermmode-unifi.mode)


#-------------------------------------------------------------------------------
#
# Parse arguments and configuration file
Expand All @@ -436,6 +448,8 @@ do
;;
-h|--help) usage
;;
-m|--mode) echo "unifi_mode=$previous_mode" && exit 0
;;
-v|--verbose) DO_VERB=1
;;
-V|--version) version
Expand Down Expand Up @@ -506,11 +520,14 @@ fi

now=$(date +%s)

# init states
ignore=1
offline=1

# login to unifi controller
unifi_login

# verify client activity
for CLIENT in $UNIFI_CLIENTS;
do
# Get client data
Expand Down Expand Up @@ -546,8 +563,10 @@ do
fi
done

# logout from unifi controller
unifi_logout

# set mode from states
if [ $offline -eq 0 ] && [ $ignore -eq 0 ];
then
unifi_mode='active'
Expand All @@ -558,11 +577,7 @@ else
unifi_mode='ignore'
fi


touch $HOME/.thermmode-unifi.mode

previous_mode=$(cat $HOME/.thermmode-unifi.mode)

# compare current with previous mode
if [ "$previous_mode" == "$unifi_mode" ];
then
verbose "** No change in thermostat mode **"
Expand Down

0 comments on commit 9b9dc89

Please sign in to comment.