Errors from API calls

I’m using the Power HAT Python API to get all the parameters from the device, but it only works intermittently.

For example, in one run just now, of the 13 parameters I read, 6 returned results and the others threw the exception 'NoneType' object is not subscriptable at, for example
Which calls work and which do not appears to be random.

In addition, I’m getting a confusing response to get_battery_charge(). At this moment it’s returning 16 while the Power software (website) shows the battery is at 97%. What’s going on there?

Hi @tyrelh ,

Maybe there is some noise or confusion on the bus that is causing this issue. Try calling the function a few times.

The values returned by the API are correct. Values in power software may not be up to date. You can check the status of the services.

Thank you.

This seems to happen if you try to run API requests locally while the power_agent is running.
If you stop the power_agent the errors will hopefully disappear.

I have not found a good way to enable both the power_agent and using the local api reliably at the same time.

Oh yes, thanks @ola that was the problem. I disabled the two power_* services and now I can reliably call the API.