Last active
August 29, 2015 14:01
-
-
Save JanneSalokoski/38eb65fde7cf9bf96e87 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
import android | |
import time | |
droid = android.Android() | |
debug = False | |
def getBatteryEvents(): | |
droid.batteryStartMonitoring() | |
droid.eventWaitFor("battery") | |
droid.batteryStopMonitoring() | |
def getBatteryInfo(): | |
battery = {} | |
battery["health"] = str(droid.batteryGetHealth().result) | |
battery["level"] = str(droid.batteryGetLevel().result) | |
battery["plugType"] = str(droid.batteryGetPlugType().result) | |
battery["status"] = str(droid.batteryGetStatus().result) | |
battery["technology"] = str(droid.batteryGetTechnology().result) | |
battery["temperature"] = str(droid.batteryGetTemperature().result) | |
battery["voltage"] = str(droid.batteryGetVoltage().result) | |
health = int(battery["health"]) | |
if health == 1: | |
health = "unknown" | |
elif health == 2: | |
health = "good" | |
elif health == 3: | |
health = "overheat" | |
elif health == 4: | |
health = "dead" | |
elif health == 5: | |
health = "over voltage" | |
elif health == 6: | |
health = "unknown" | |
else: | |
health = "Null" | |
battery["health"] = health | |
plugType = int(battery["plugType"]) | |
if plugType == 1: | |
plugType = "unknown" | |
elif plugType == 0: | |
plugType = "unplugged" | |
elif plugType == 2: | |
plugType = "AC charger" | |
elif plugType == 3: | |
plugType = "USB port" | |
else: | |
plugType = "null" | |
battery["plugType"] = plugType | |
status = int(battery["status"]) | |
if status == 1: | |
status = "unknown" | |
elif status == 2: | |
status = "charging" | |
elif status == 3: | |
status = "discharging" | |
elif status == 4: | |
status = "not charging" | |
elif status == 5: | |
status = "full" | |
else: | |
status = "null" | |
battery["status"] = status | |
temperature = battery["temperature"] | |
temp = temperature[:2] + "." + temperature[2:] | |
battery["temperature"] = temp | |
#voltage = int(battery["voltage"]) | |
#voltage = voltage / 1000 | |
#battery["voltage"] = str(voltage) | |
return battery | |
def printBatteryInfo(battery): | |
print "health: " + battery["health"] | |
print "level: " + battery["level"] + "%" | |
print "plugType: " + battery["plugType"] | |
print "status: " + battery["status"] | |
print "technology: " + battery["technology"] | |
print "temperature: " + battery["temperature"] + "C" | |
print "voltage: " + battery["voltage"] + "V" | |
if debug == False: | |
droid.dialogCreateAlert("batteryState", "health: " + battery["health"] + "\n" + "level: " + battery["level"] + "%\n" + "plugType: " + battery["plugType"]+ "\n" + "status: " + battery["status"]+ "\n" + "technology: " + battery["technology"]+ "\n" + "temperature: " + battery["temperature"] + "C"+ "\n" + "voltage: " + battery["voltage"] + "V") | |
droid.dialogShow() | |
def main(): | |
print "<< Starting >>" | |
getBatteryEvents() | |
batteryInfo = getBatteryInfo() | |
printBatteryInfo(batteryInfo) | |
print "<< Closing >>" | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment