-
Notifications
You must be signed in to change notification settings - Fork 437
Open
Description
When I try out the battery.status on Mac OS it seems like the CurrentCapacity is the actually current battery percentage already, the calculation for percentage is not needed?
Also, not sure if anyone else on Mac OS have the same issue
max_capacity = float(line.rpartition('=')[-1].strip())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: could not convert string to float: '80}'
There is an extra } at the end, my fix if to add a string slice to drop the }
max_capacity = float(line.rpartition('=')[-1].strip()[:-1])
To summarize this is the changes I made to have an output for battery status {'isCharging': True, 'percentage': 98.0}
for line in output.decode('utf-8').splitlines():
if 'IsCharging' in line:
is_charging = line.rpartition('=')[-1].strip()
if 'MaxCapacity' in line:
# max_capacity = float(line.rpartition('=')[-1].strip())
max_capacity = float(line.rpartition('=')[-1].strip()[:-1])
# if 'CurrentCapacity' in line:
if 'CurrentCapacity' == line.rpartition('=')[0].strip()[1:-1]:
current_capacity = float(line.rpartition('=')[-1].strip())
if is_charging:
status['isCharging'] = is_charging == "Yes"
if current_capacity and max_capacity:
# status['percentage'] = 100.0 * current_capacity / max_capacity
status['percentage'] = current_capacity
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels