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.
86 initialize: function() {
87 if (!this.initialized) {
88 chrome.send('requestPowerInfo');
89 this.initialized = true;
93 batteryPercentChanged: function(percent, oldPercent) {
94 if (oldPercent != undefined)
95 chrome.send('updateBatteryPercent', [parseInt(percent)]);
98 batteryStateChanged: function(state) {
99 // Find the index of the selected battery state.
100 var index = this.batteryStateOptions.indexOf(state);
102 chrome.send('updateBatteryState', [index]);
105 externalPowerChanged: function(source) {
106 // Find the index of the selected power source.
107 var index = this.externalPowerOptions.indexOf(source);
109 chrome.send('updateExternalPower', [index]);
112 timeUntilEmptyChanged: function(time, oldTime) {
113 if (oldTime != undefined)
114 chrome.send('updateTimeToEmpty', [parseInt(time)]);
117 timeUntilFullChanged: function(time, oldTime) {
118 if (oldTime != undefined)
119 chrome.send('updateTimeToFull', [parseInt(time)]);
122 updatePowerProperties: function(power_properties) {
123 this.batteryPercent = power_properties.battery_percent;
125 this.batteryStateOptions[power_properties.battery_state];
127 this.externalPowerOptions[power_properties.external_power];
128 this.timeUntilEmpty = power_properties.battery_time_to_empty_sec;
129 this.timeUntilFull = power_properties.battery_time_to_full_sec;