diff --git a/ups-exporter.js b/ups-exporter.js index eb888dd..2b64e6a 100755 --- a/ups-exporter.js +++ b/ups-exporter.js @@ -11,12 +11,19 @@ async function scrape() { while(!!(found = r.exec(data))) map[found[1]] = found[2]; + if(map["Remaining Runtime"]) { + const parsed = /(\d+) (.)/gi.exec(map["Remaining Runtime"]); + const unit = parsed[2].toLowerCase(); + if(unit == 'm') map["Remaining Runtime"] = Number(parsed[1]) * 60; + if(unit == 'h') map["Remaining Runtime"] = Number(parsed[1]) * 60 * 60; + } + return { model: map["Model Name"], vendor: map["Power Supply by"], state: map["State"], charge: Number(/\d+/g.exec(map["Battery Capacity"])[0]) / 100, - remaining: map["Remaining Runtime"], + battery_time: map["Remaining Runtime"], rated_voltage: Number(/\d+/g.exec(map["Rating Voltage"])[0]), rated_wattage: Number(/\d+/g.exec(map["Rating Power"])[0]), input_voltage: Number(/\d+/g.exec(map["Utility Voltage"])[0]), @@ -34,8 +41,8 @@ function format(a) { .join(', '); if(labels) labels = `{${labels}}`; - return Object.entries(a).filter(([key, value]) => typeof value != 'string') - .map(([key, value]) => `${key}${labels} ${value}`) + return Object.entries(a) + .map(([key, value]) => `ups_${key}${labels} ${typeof value == 'string' ? 1 : value}`) .join('\n'); }