Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change connected to isCharging #85

Merged
merged 1 commit into from
Aug 3, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plyer/facades.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ class Battery(object):
@property
def status(self):
'''Property that contains a dict with the following fields:
* **connected** *(bool)*: Whether to power supply
* **isCharging** *(bool)*: Battery is charging
* **percentage** *(float)*: Battery charge remaining

.. warning::
Expand Down
4 changes: 2 additions & 2 deletions plyer/platforms/android/battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class AndroidBattery(Battery):
def _get_status(self):
status = {"connected": None, "percentage": None}
status = {"isCharging": None, "percentage": None}

ifilter = IntentFilter(Intent.ACTION_BATTERY_CHANGED)

Expand All @@ -24,7 +24,7 @@ def _get_status(self):
scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1)
percentage = level / float(scale)

status['connected'] = isCharging
status['isCharging'] = isCharging
status['percentage'] = percentage

return status
Expand Down
4 changes: 2 additions & 2 deletions plyer/platforms/linux/battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class LinuxBattery(Battery):
def _get_status(self):
status = {"connected": None, "percentage": None}
status = {"isCharging": None, "percentage": None}

# We are supporting only one battery now
dev = "/org/freedesktop/UPower/device/battery_BAT0"
Expand All @@ -23,7 +23,7 @@ def _get_status(self):
percentage = float(l.rpartition(':')[-1].strip()[:-1])

if(power_supply):
status['connected'] = power_supply == "yes"
status['isCharging'] = power_supply != "yes"

status['percentage'] = percentage

Expand Down
12 changes: 6 additions & 6 deletions plyer/platforms/macosx/battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class OSXBattery(Battery):
def _get_status(self):
status = {"connected": None, "percentage": None}
status = {"isCharging": None, "percentage": None}

ioreg_process = Popen(["ioreg", "-rc", "AppleSmartBattery"],
stdout=PIPE)
Expand All @@ -13,17 +13,17 @@ def _get_status(self):
if not output:
return status

ExternalConnected = MaxCapacity = CurrentCapacity = None
IsCharging = MaxCapacity = CurrentCapacity = None
for l in output.splitlines():
if 'ExternalConnected' in l:
ExternalConnected = l.rpartition('=')[-1].strip()
if 'IsCharging' in l:
IsCharging = l.rpartition('=')[-1].strip()
if 'MaxCapacity' in l:
MaxCapacity = float(l.rpartition('=')[-1].strip())
if 'CurrentCapacity' in l:
CurrentCapacity = float(l.rpartition('=')[-1].strip())

if (ExternalConnected):
status['connected'] = ExternalConnected == "Yes"
if (IsCharging):
status['isCharging'] = IsCharging == "Yes"

if (CurrentCapacity and MaxCapacity):
status['percentage'] = 100. * CurrentCapacity / MaxCapacity
Expand Down
4 changes: 2 additions & 2 deletions plyer/platforms/win/battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

class WinBattery(Battery):
def _get_status(self):
status = {"connected": None, "percentage": None}
status = {"isCharging": None, "percentage": None}

query = battery_status()

if (not query):
return status

status["connected"] = query["ACLineStatus"] == 1
status["isCharging"] = query["BatteryFlag"] == 8
status["percentage"] = query["BatteryLifePercent"]

return status
Expand Down