Re: Battery Status API asynchronous amendment

On Thu, 1 May 2014, at 7:07, Marcos Caceres wrote:
> > On April 30, 2014 at 8:35:19 AM, Tim Volodine (timvolodine@google.com)
> wrote:
> > We are proposing a change to the current Battery Status API (
> > http://www.w3.org/TR/battery-status/) such that it is completely
> > asynchronous. This will allow for less constrained and more efficient
> > current and future implementations.
> >  
> > More concretely the proposal is to return the battery object asynchronously
> > as a promise, e.g.
> >  
> > function onBatterySuccess(battery) {
> > console.log(batery.level);
> > }
> > function onBatteryFailure(msg) {
> > console.log("battery information not available");
> > }
> > navigator.getBattery().then(onBatterySuccess, onBatteryFailure);
> 
> Maybe getBattery() could resolve to an array... might avoid issues down
> the road if any device ships with multiple batteries. 

If a device has two batteries, I do not think it should be exposed as
such by the API. If you have two batteries, it is simpler for the
developer to see this as one battery. Otherwise, the developers would
have to do a lot of work to guess how much battery power is left
depending on the internals of the system (is the system using both
batteries at the same time, one after each other, etc.).

Though, if it happens that developers would like more details,
navigator.getBatteries() could return a detailed version while
navigator.getBattery() would return merged data. WDYT?

-- Mounir

Received on Thursday, 1 May 2014 08:53:38 UTC