Last active
February 4, 2020 22:12
-
-
Save maccyber/d3d69337e3d074d5be710ef14240d657 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
FILE="/tmp/leaf.cache" | |
[email protected] | |
PASSWORD=mypassword | |
update_status() { | |
result=`leaf-connect-cli cachedStatus -u $USERNAME -p $PASSWORD -r NE` | |
BATTERY_STATUS=`echo ${result} | jq '.BatteryStatusRecords.BatteryStatus.SOC.Value' | sed 's/"//g'` | |
CHARGING_STATUS=`echo ${result} | jq '.BatteryStatusRecords.BatteryStatus.BatteryChargingStatus' | sed 's/"//g'` | |
echo "$BATTERY_STATUS" > $FILE | |
echo "$CHARGING_STATUS" >> $FILE | |
} | |
display_status() { | |
if [ ! -f "$FILE" ]; then | |
update_status | |
fi | |
FILE_TIMESTAMP=$(stat -c %Y $FILE) | |
NOW_TIMESTAMP=$(date +"%s") | |
DIFF="$(($NOW_TIMESTAMP-$FILE_TIMESTAMP))" | |
if [ $DIFF -ge "600" ]; then | |
update_status | |
fi | |
status_text=$(head -n 1 $FILE) | |
charging=$(tail -n 1 $FILE) | |
icon= | |
if [ -z "$status_text" ]; then | |
color=#36a8d5 | |
status_text="retrieving info" | |
elif [ $status_text -ge "70" ]; then | |
color=#88b090 | |
status_text="${status_text}%" | |
elif [ $status_text -ge "30" ]; then | |
color=#ccdc90 | |
status_text="${status_text}%" | |
elif [ $status_text -lt "30" ]; then | |
color=#e89393 | |
status_text="${status_text}%" | |
else | |
color=#36a8d5 | |
status_text="retrieving info" | |
fi | |
if [ $charging != "NOT_CHARGING" ]; then | |
color=#88b090 | |
icon+= | |
fi | |
echo '[{"name": "leaf", "instance": "battery", "full_text": " '${icon}' ' ${status_text} '", "color": "'${color}'"}]' | |
} | |
while sleep 10; do | |
display_status | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Display battery and charging status on Nissan Leaf with i3bar and i3cat
