return to previous state after custom color

This commit is contained in:
root 2017-03-04 15:58:02 +00:00
parent 38863e1714
commit 91212e0468
1 changed files with 9 additions and 2 deletions

View File

@ -1,10 +1,12 @@
#!/bin/bash
TMPFILE_BASE=/tmp/light_state
TMPFILE_CUSTOM_BASE=/tmp/light_state_custom
ROOM_NUMBER="$1"
COLOR="$2"
ROOM_COUNT=3
DFAULT_LIGHT_STATE=0
STATE_0="a\x00\x03\x00\x00\x00|000000000000000000;\
000000000000000000;\
000000000000000000"
@ -67,10 +69,14 @@ fi
touch "${TMPFILE_BASE}_$ROOM_NUMBER"
LIGHT_STATE=$(cat "${TMPFILE_BASE}_$ROOM_NUMBER")
[ -z "$LIGHT_STATE" ] && LIGHT_STATE=0
[ -z "$LIGHT_STATE" ] && LIGHT_STATE=$DFAULT_LIGHT_STATE
if [ -z "$COLOR" ]; then
LIGHT_STATE=$(( $LIGHT_STATE+1 ))
if ! [ -f "${TMPFILE_CUSTOM_BASE}_$ROOM_NUMBER" ]; then # restore previous colour
LIGHT_STATE=$(( $LIGHT_STATE+1 ))
else
rm -f "${TMPFILE_CUSTOM_BASE}_$ROOM_NUMBER"
fi
case $LIGHT_STATE in
0)
STATE=$STATE_0
@ -88,6 +94,7 @@ if [ -z "$COLOR" ]; then
esac
else
STATE="$(get_room_color_string)"
touch "${TMPFILE_CUSTOM_BASE}_$ROOM_NUMBER"
fi
for i in {1..5}; do