Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exports.get_battery_status = function(cb) {
var keys = 'Availability,BatteryStatus,EstimatedChargeRemaining,EstimatedRunTime';
var get_state = function(num) {
if (num == 1)
return 'discharging';
else if (num == 2 || num == 3)
return 'charged';
else if (num == 5)
return 'critical';
else
return 'charging';
}
wmic.get_values('Path Win32_Battery', keys, null, function(err, obj) {
if (err) return cb(err);
if (obj.Availability == '11')
return cb(new Error('No battery found.'))
var data = {
percentage_remaining: parseInt(obj.EstimatedChargeRemaining),
state: get_state(parseInt(obj.BatteryStatus)),
time_remaining: obj.EstimatedRunTime || 'unknown'
}
cb(null, data);
});
};