1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 var BatterySettings = Polymer({
6 is: 'battery-settings',
10 * The system's battery percentage.
14 observer: 'batteryPercentChanged',
18 * A string representing a value in the
19 * PowerSupplyProperties_BatteryState enumeration.
23 observer: 'batteryStateChanged',
27 * An array representing the battery state options.
28 * The names are ordered based on the
29 * PowerSupplyProperties_BatteryState enumeration. These values must be
32 batteryStateOptions: {
34 value: function() { return ['Full', 'Charging', 'Disharging',
39 * A string representing a value in the
40 * PowerSupplyProperties_ExternalPower enumeration.
44 observer: 'externalPowerChanged',
48 * An array representing the external power options.
49 * The names are ordered based on the
50 * PowerSupplyProperties_ExternalPower enumeration. These values must be
53 externalPowerOptions: {
55 value: function() { return ['AC', 'USB (Low Power)', 'Disconnected']; }
59 * A string representing the time left until the battery is discharged.
63 observer: 'timeUntilEmptyChanged',
67 * A string representing the time left until the battery is at 100%.
71 observer: 'timeUntilFullChanged',
75 * The title for the settings section.
83 this.title = 'Power Settings';
86 batteryPercentChanged: function(percent, oldPercent) {
87 if (oldPercent != undefined)
88 chrome.send('updateBatteryPercent', [parseInt(percent)]);
91 batteryStateChanged: function(state) {
92 // Find the index of the selected battery state.
93 var index = this.batteryStateOptions.indexOf(state);
95 chrome.send('updateBatteryState', [index]);
98 externalPowerChanged: function(source) {
99 // Find the index of the selected power source.
100 var index = this.externalPowerOptions.indexOf(source);
102 chrome.send('updateExternalPower', [index]);
105 timeUntilEmptyChanged: function(time, oldTime) {
106 if (oldTime != undefined)
107 chrome.send('updateTimeToEmpty', [parseInt(time)]);
110 timeUntilFullChanged: function(time, oldTime) {
111 if (oldTime != undefined)
112 chrome.send('updateTimeToFull', [parseInt(time)]);
115 updatePowerProperties: function(power_properties) {
116 this.batteryPercent = power_properties.battery_percent;
118 this.batteryStateOptions[power_properties.battery_state];
120 this.externalPowerOptions[power_properties.external_power];
121 this.timeUntilEmpty = power_properties.battery_time_to_empty_sec;
122 this.timeUntilFull = power_properties.battery_time_to_full_sec;