Skip to content

Commit

Permalink
Exact match lookup for MacOS battery status
Browse files Browse the repository at this point in the history
Fix kivy#799
Use exact string math instead of partial match to look for battery status. This will prevent fields like AppleRawMaxCapacity and AppleRawCurrentCapacity from being read as MaxCapacity and CurrentCapacity.
  • Loading branch information
Ocean48 committed Jan 24, 2024
1 parent 47fbce1 commit 09e39e5
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions plyer/platforms/macosx/battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ def _get_state(self):

is_charging = max_capacity = current_capacity = None
for line in output.decode('utf-8').splitlines():
if 'IsCharging' in line:
if 'IsCharging' == line.rpartition('=')[0].strip()[1:-1]:
is_charging = line.rpartition('=')[-1].strip()
if 'MaxCapacity' in line:
if 'MaxCapacity' == line.rpartition('=')[0].strip()[1:-1]:
max_capacity = float(line.rpartition('=')[-1].strip())
if 'CurrentCapacity' in line:
if 'CurrentCapacity' == line.rpartition('=')[0].strip()[1:-1]:
current_capacity = float(line.rpartition('=')[-1].strip())

if is_charging:
Expand Down

0 comments on commit 09e39e5

Please sign in to comment.