Last active
February 4, 2020 22:12
-
-
Save maccyber/d3d69337e3d074d5be710ef14240d657 to your computer and use it in GitHub Desktop.
Revisions
-
maccyber revised this gist
Feb 4, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -46,7 +46,7 @@ display_status() { status_text="retrieving info" fi if [ $charging != "NOT_CHARGING" ]; then color=#88b090 icon+= fi -
maccyber revised this gist
Feb 3, 2020 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,11 @@ #!/bin/bash FILE="/tmp/leaf.cache" USERNAME=myleaf@leaf.com 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 -
maccyber created this gist
Feb 3, 2020 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,57 @@ #!/bin/bash FILE="/tmp/leaf.log" update_status() { result=`leaf-connect-cli cachedStatus -u myleaf@leaf.com -p mypassword -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 == "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