Re: [battery] CfC to update Battery with async/promises proposal (implies LC return); deadline 22 May 2014.

Summary of changes to the Battery Status API specification.

Current specification:
https://dvcs.w3.org/hg/dap/raw-file/tip/battery/Overview.html

1. Obtaining a BatteryManager object using getBattery() method.

Replace the current partial Navigator interface with:
partial interface Navigator {
    Promise<BatteryManager> getBattery();
}

When getBattery() method is invoked it returns a Promise object which is
settled once the battery status information is available. If the promise
succeeds a BatteryManager object is returned and its fields can be
inspected and event listeners can be added as in the code snippet below.
The promise should normally succeed even if there is no battery or no
battery information is available from the platform. In this case default
values should be provided (as in the original specification). Because event
handlers can be attached to the BatteryManager object it is important that
the same BatteryManager object is returned upon multiple invocations of
navigator.getBattery().

If the promise is rejected a DOMException is supplied describing the reason
for rejection. An example would be if the user is not allowed to obtain the
battery status e.g. the DOMException would have the name “SecurityError”
with code exception value 18.

In case of multiple batteries the API should provide aggregate information
where possible for level, chargingTime and dischargingTime.

2. Sample Code.

navigator.getBattery().then(
  function(battery) {
    console.log(battery.level);
    battery.addEventListener('levelchange', function() {
      console.log(battery.level);
    }, false);
  }, function(err) {
    console.log(err.name); // Failed to provide BatteryManager object
});


thanks,
Tim

-------------------
On Wed, May 21, 2014 at 7:37 AM, Kostiainen, Anssi <
anssi.kostiainen@intel.com> wrote:

> On 15 May 2014, at 21:30, Frederick Hirsch <w3c@fjhirsch.com> wrote:
>
> > This is a Call for Consensus to  change update the Battery specification
> with the async proposal as outlined in
> http://lists.w3.org/Archives/Public/public-device-apis/2014Apr/0037.html
>
> +1
>
> With a disclaimer that I’d like the group to work closely with
> implementers who have shipped the current API to ensure a smooth transition
> as I noted earlier:
>
> http://lists.w3.org/Archives/Public/public-device-apis/2014May/0005.html
>
> Thanks,
>
> -Anssi

Received on Thursday, 22 May 2014 09:59:45 UTC