And here’s a bash script to query the status of each of my three danalocks, updating openHAB items accordingly:
#!/bin/bash
#quit app if running
adb shell am force-stop dk.polycontrol.ekey
#restart app
adb shell monkey -p dk.polycontrol.ekey -c android.intent.category.LAUNCHER 1
sleep 1
#Goes through the three locks
for i in `seq 1 3`; do
echo Trying $i
# Find the colour
# Keep pulling screen until not grey
while true; do
sleep 0.7
adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > /tmp/screen.png
output=$(convert /tmp/screen.png -crop '1x1+366+300' txt:-)
echo "Reading is $output"
if [[ $output == *"59624"* ]]; then
status="ON"
break
elif [[ $output == *"42405"* ]]; then
status="OFF"
break
elif [[ $output == *"64507"* ]]; then
echo "App not yet ready - retrying"
else
echo "Some kind of error - will return with UNDEF"
status="UNDEF"
# SET OPENHAB ERROR CODE HERE!
break
fi
done
#Which lock am I looking at?
adb pull $(adb shell uiautomator dump | grep -oP '[^ ]+.xml') /tmp/view.xml
if grep -q "door bottom" /tmp/view.xml; then
lock=DanaDoorStatus
elif grep -q "door top" /tmp/view.xml; then
lock=DanaDoorStatus
elif grep -q "storage" /tmp/view.xml; then
lock=DanaStorageStatus
fi
echo "Lock $lock set to $status"
# now update openHAB
wget -O /dev/null http://192.168.1.53:8080/classicui/CMD?$lock=$status
# swipe to next lock
adb shell input swipe 750 600 300 600 500
done
# and quit app
adb shell am force-stop dk.polycontrol.ekey