-
Notifications
You must be signed in to change notification settings - Fork 427
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
Mac OS battery status #799
Comments
I don't have a Mac and can't answer this directly. Does the Plyer unit-tests exercise this code? If so, whether they pass when run on your machine. What does the output of the command How does it compare to this example, which has I was going to suggest that you submit a PR with your changes, but it seems to me there is a bigger issue with Do we need to specify more commandline options to override different defaults? Do we need the code to be able to handle the different formats? |
~ % ioreg -rc AppleSmartBattery It looks like the output for |
What a mess. Let's go through this. Under the OLD system (e.g. in 2017, according to the link above): MaxCapacity and CurrentCapacity were arbitrary units. Under the new system: @Ocean48 is proposing to remove the second renormalising formula, and just use CurrentCapacity. I would argue against. The formula is doing no harm, and allows it to work on the old and new systems. But wait... there is a bug. Plyer doesn't read in the field called CurrentCapacity. It reads in the last field that contains the text CurrentCapacity. Under the new system, this is whichever appears last: CurrentCapacity or AppleRawCurrentCapacity. Ditto with MaxCapacity or AppleRawMaxCapacity. Because the values are normalised, this will continue to work, but only if the order is consistent (e.g. both AppleRaws are last). This bug should be fixed so it isn't as fragile to changes in ioreg. But there is still another issue: @Ocean48 complained that the MaxCapacity was "80}". I can't see how that happened here. This needs debugging. So my position:
|
Long story short, the problem is because Plyer is checking string contains MaxCapacity or CurrentCapacity, so brackets just slips in. All needed is to do exact match lookup with string slicing leave everything else the same, and still will work on older version |
@Ocean48: Look at the string you posted a couple of hours ago. Where are these brackets? They are nowhere to be seen. It would be good to see what the value of |
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.
I forgot to include the string, here is the string
In this string it contains MaxCapacity, but it ends with 82}. |
Wha??? Ohhhhhh! I see!! It was truncated in the previous example. before, so I didn't know it contained the string. I agree with your conclusion completely! Thanks for bringing me along. |
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
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}
The text was updated successfully, but these errors were encountered: