Battery stats plugin: fix and improvements (#5626)
- fix incorrectly shown awake, sleeping, charging and discharging,
- remove unneeded debug mode and logging to external file,
- prevent showing values like inf, -inf, nan in estimated times
(we now show "n/a"), and values below zero,
- show extra confirm box when we want to reset data,
- show time in format xxhxxm instead of only pure minutes,
- check at initialization that the device was charging when it was
turned off (battery level larger than at the time of exit).
2019-11-26 13:21:14 +00:00
|
|
|
local ConfirmBox = require("ui/widget/confirmbox")
|
2017-03-24 06:36:15 +00:00
|
|
|
local DataStorage = require("datastorage")
|
|
|
|
local KeyValuePage = require("ui/widget/keyvaluepage")
|
|
|
|
local LuaSettings = require("luasettings")
|
|
|
|
local PowerD = require("device"):getPowerDevice()
|
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
2017-05-16 09:11:11 +00:00
|
|
|
local dbg = require("dbg")
|
Battery stats plugin: fix and improvements (#5626)
- fix incorrectly shown awake, sleeping, charging and discharging,
- remove unneeded debug mode and logging to external file,
- prevent showing values like inf, -inf, nan in estimated times
(we now show "n/a"), and values below zero,
- show extra confirm box when we want to reset data,
- show time in format xxhxxm instead of only pure minutes,
- check at initialization that the device was charging when it was
turned off (battery level larger than at the time of exit).
2019-11-26 13:21:14 +00:00
|
|
|
local util = require("util")
|
2017-03-24 06:36:15 +00:00
|
|
|
local _ = require("gettext")
|
|
|
|
|
|
|
|
local State = {}
|
|
|
|
|
|
|
|
function State:new(o)
|
|
|
|
o = o or {}
|
|
|
|
setmetatable(o, self)
|
|
|
|
self.__index = self
|
|
|
|
if o.percentage == nil or o.timestamp == nil then
|
2017-06-24 14:53:20 +00:00
|
|
|
o.percentage = PowerD:getCapacityHW()
|
2017-03-24 06:36:15 +00:00
|
|
|
o.timestamp = os.time()
|
|
|
|
end
|
|
|
|
return o
|
|
|
|
end
|
|
|
|
|
|
|
|
function State:toString()
|
|
|
|
return string.format("{%d @ %s}", self.percentage, os.date("%c", self.timestamp))
|
|
|
|
end
|
|
|
|
|
|
|
|
local Usage = {}
|
Battery stats plugin: fix and improvements (#5626)
- fix incorrectly shown awake, sleeping, charging and discharging,
- remove unneeded debug mode and logging to external file,
- prevent showing values like inf, -inf, nan in estimated times
(we now show "n/a"), and values below zero,
- show extra confirm box when we want to reset data,
- show time in format xxhxxm instead of only pure minutes,
- check at initialization that the device was charging when it was
turned off (battery level larger than at the time of exit).
2019-11-26 13:21:14 +00:00
|
|
|
local INDENTATION = " " -- Three spaces.
|
2017-03-24 06:36:15 +00:00
|
|
|
|
|
|
|
function Usage:new(o)
|
|
|
|
o = o or {}
|
|
|
|
setmetatable(o, self)
|
|
|
|
self.__index = self
|
|
|
|
if o.percentage == nil or o.time == nil then
|
|
|
|
o.percentage = 0
|
|
|
|
o.time = 0
|
|
|
|
end
|
|
|
|
return o
|
|
|
|
end
|
|
|
|
|
|
|
|
function Usage:append(state)
|
|
|
|
local curr = State:new()
|
Battery stats plugin: fix and improvements (#5626)
- fix incorrectly shown awake, sleeping, charging and discharging,
- remove unneeded debug mode and logging to external file,
- prevent showing values like inf, -inf, nan in estimated times
(we now show "n/a"), and values below zero,
- show extra confirm box when we want to reset data,
- show time in format xxhxxm instead of only pure minutes,
- check at initialization that the device was charging when it was
turned off (battery level larger than at the time of exit).
2019-11-26 13:21:14 +00:00
|
|
|
self.percentage = self.percentage + math.abs(state.percentage - curr.percentage)
|
2017-03-24 06:36:15 +00:00
|
|
|
self.time = self.time + os.difftime(curr.timestamp - state.timestamp)
|
|
|
|
end
|
|
|
|
|
|
|
|
function Usage:minutes()
|
|
|
|
return self.time / 60
|
|
|
|
end
|
|
|
|
|
|
|
|
function Usage:hours()
|
|
|
|
return self:minutes() / 60
|
|
|
|
end
|
|
|
|
|
|
|
|
function Usage:percentagePerHour()
|
|
|
|
if self.time == 0 then
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return self.percentage / self:hours()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Usage:remainingHours()
|
Battery stats plugin: fix and improvements (#5626)
- fix incorrectly shown awake, sleeping, charging and discharging,
- remove unneeded debug mode and logging to external file,
- prevent showing values like inf, -inf, nan in estimated times
(we now show "n/a"), and values below zero,
- show extra confirm box when we want to reset data,
- show time in format xxhxxm instead of only pure minutes,
- check at initialization that the device was charging when it was
turned off (battery level larger than at the time of exit).
2019-11-26 13:21:14 +00:00
|
|
|
if self:percentagePerHour() == 0 then return "n/a" end
|
2017-03-24 06:36:15 +00:00
|
|
|
local curr = State:new()
|
|
|
|
return curr.percentage / self:percentagePerHour()
|
|
|
|
end
|
|
|
|
|
|
|
|
function Usage:chargingHours()
|
Battery stats plugin: fix and improvements (#5626)
- fix incorrectly shown awake, sleeping, charging and discharging,
- remove unneeded debug mode and logging to external file,
- prevent showing values like inf, -inf, nan in estimated times
(we now show "n/a"), and values below zero,
- show extra confirm box when we want to reset data,
- show time in format xxhxxm instead of only pure minutes,
- check at initialization that the device was charging when it was
turned off (battery level larger than at the time of exit).
2019-11-26 13:21:14 +00:00
|
|
|
if self:percentagePerHour() == 0 then return "n/a" end
|
2017-03-24 06:36:15 +00:00
|
|
|
local curr = State:new()
|
Battery stats plugin: fix and improvements (#5626)
- fix incorrectly shown awake, sleeping, charging and discharging,
- remove unneeded debug mode and logging to external file,
- prevent showing values like inf, -inf, nan in estimated times
(we now show "n/a"), and values below zero,
- show extra confirm box when we want to reset data,
- show time in format xxhxxm instead of only pure minutes,
- check at initialization that the device was charging when it was
turned off (battery level larger than at the time of exit).
2019-11-26 13:21:14 +00:00
|
|
|
return math.abs(curr.percentage - 100) / self:percentagePerHour()
|
2017-03-24 06:36:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local function shorten(number)
|
Battery stats plugin: fix and improvements (#5626)
- fix incorrectly shown awake, sleeping, charging and discharging,
- remove unneeded debug mode and logging to external file,
- prevent showing values like inf, -inf, nan in estimated times
(we now show "n/a"), and values below zero,
- show extra confirm box when we want to reset data,
- show time in format xxhxxm instead of only pure minutes,
- check at initialization that the device was charging when it was
turned off (battery level larger than at the time of exit).
2019-11-26 13:21:14 +00:00
|
|
|
if number == "n/a" then return _("n/a") end
|
2017-03-24 06:36:15 +00:00
|
|
|
return string.format("%.2f", number);
|
|
|
|
end
|
|
|
|
|
|
|
|
function Usage:dump(kv_pairs)
|
Battery stats plugin: fix and improvements (#5626)
- fix incorrectly shown awake, sleeping, charging and discharging,
- remove unneeded debug mode and logging to external file,
- prevent showing values like inf, -inf, nan in estimated times
(we now show "n/a"), and values below zero,
- show extra confirm box when we want to reset data,
- show time in format xxhxxm instead of only pure minutes,
- check at initialization that the device was charging when it was
turned off (battery level larger than at the time of exit).
2019-11-26 13:21:14 +00:00
|
|
|
table.insert(kv_pairs, {INDENTATION .. _("Consumed %"), shorten(self.percentage)})
|
|
|
|
table.insert(kv_pairs, {INDENTATION .. _("Total time"), util.secondsToHClock(self.time, true, true)})
|
|
|
|
table.insert(kv_pairs, {INDENTATION .. _("% per hour"), shorten(self:percentagePerHour())})
|
2017-03-24 06:36:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Usage:dumpRemaining(kv_pairs)
|
Battery stats plugin: fix and improvements (#5626)
- fix incorrectly shown awake, sleeping, charging and discharging,
- remove unneeded debug mode and logging to external file,
- prevent showing values like inf, -inf, nan in estimated times
(we now show "n/a"), and values below zero,
- show extra confirm box when we want to reset data,
- show time in format xxhxxm instead of only pure minutes,
- check at initialization that the device was charging when it was
turned off (battery level larger than at the time of exit).
2019-11-26 13:21:14 +00:00
|
|
|
table.insert(kv_pairs, {INDENTATION .. _("Estimated remaining hours"), shorten(self:remainingHours())})
|
2017-03-24 06:36:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Usage:dumpCharging(kv_pairs)
|
Battery stats plugin: fix and improvements (#5626)
- fix incorrectly shown awake, sleeping, charging and discharging,
- remove unneeded debug mode and logging to external file,
- prevent showing values like inf, -inf, nan in estimated times
(we now show "n/a"), and values below zero,
- show extra confirm box when we want to reset data,
- show time in format xxhxxm instead of only pure minutes,
- check at initialization that the device was charging when it was
turned off (battery level larger than at the time of exit).
2019-11-26 13:21:14 +00:00
|
|
|
table.insert(kv_pairs, {INDENTATION .. _("Estimated hours for charging"), shorten(self:chargingHours())})
|
2017-03-24 06:36:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local BatteryStat = {
|
Battery stats plugin: fix and improvements (#5626)
- fix incorrectly shown awake, sleeping, charging and discharging,
- remove unneeded debug mode and logging to external file,
- prevent showing values like inf, -inf, nan in estimated times
(we now show "n/a"), and values below zero,
- show extra confirm box when we want to reset data,
- show time in format xxhxxm instead of only pure minutes,
- check at initialization that the device was charging when it was
turned off (battery level larger than at the time of exit).
2019-11-26 13:21:14 +00:00
|
|
|
settings = LuaSettings:open(DataStorage:getSettingsDir() .. "/battery_stats.lua"),
|
2017-05-16 09:11:11 +00:00
|
|
|
kv_page = nil,
|
2017-03-24 06:36:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function BatteryStat:init()
|
|
|
|
self.awake = Usage:new(self.settings:readSetting("awake"))
|
|
|
|
self.sleeping = Usage:new(self.settings:readSetting("sleeping"))
|
Battery stats plugin: fix and improvements (#5626)
- fix incorrectly shown awake, sleeping, charging and discharging,
- remove unneeded debug mode and logging to external file,
- prevent showing values like inf, -inf, nan in estimated times
(we now show "n/a"), and values below zero,
- show extra confirm box when we want to reset data,
- show time in format xxhxxm instead of only pure minutes,
- check at initialization that the device was charging when it was
turned off (battery level larger than at the time of exit).
2019-11-26 13:21:14 +00:00
|
|
|
self.charging = Usage:new(self.settings:readSetting("charging"))
|
|
|
|
self.discharging = Usage:new(self.settings:readSetting("discharging"))
|
2017-03-24 06:36:15 +00:00
|
|
|
|
|
|
|
-- Note: these fields are not the "real" timestamp and battery usage, but
|
|
|
|
-- the unaccumulated values.
|
Battery stats plugin: fix and improvements (#5626)
- fix incorrectly shown awake, sleeping, charging and discharging,
- remove unneeded debug mode and logging to external file,
- prevent showing values like inf, -inf, nan in estimated times
(we now show "n/a"), and values below zero,
- show extra confirm box when we want to reset data,
- show time in format xxhxxm instead of only pure minutes,
- check at initialization that the device was charging when it was
turned off (battery level larger than at the time of exit).
2019-11-26 13:21:14 +00:00
|
|
|
self.awake_state = State:new()
|
|
|
|
self.charging_state = State:new()
|
|
|
|
|
2017-05-31 18:31:27 +00:00
|
|
|
-- Whether the device was suspending before current timestamp.
|
|
|
|
self.was_suspending = false
|
|
|
|
-- Whether the device was charging before current timestamp.
|
|
|
|
self.was_charging = PowerD:isCharging()
|
Battery stats plugin: fix and improvements (#5626)
- fix incorrectly shown awake, sleeping, charging and discharging,
- remove unneeded debug mode and logging to external file,
- prevent showing values like inf, -inf, nan in estimated times
(we now show "n/a"), and values below zero,
- show extra confirm box when we want to reset data,
- show time in format xxhxxm instead of only pure minutes,
- check at initialization that the device was charging when it was
turned off (battery level larger than at the time of exit).
2019-11-26 13:21:14 +00:00
|
|
|
if self.was_charging then
|
|
|
|
self:reset(true, false)
|
|
|
|
end
|
|
|
|
-- Check if the battery was charging when KO was turned off.
|
|
|
|
local battery_before_off = self.settings:readSetting("awake_state")
|
|
|
|
if battery_before_off and battery_before_off.percentage
|
|
|
|
and self.awake_state.percentage > battery_before_off.percentage then
|
|
|
|
self:reset(false, true)
|
2017-03-24 06:36:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function BatteryStat:onFlushSettings()
|
|
|
|
self.settings:reset({
|
|
|
|
charging = self.charging,
|
2017-05-16 09:11:11 +00:00
|
|
|
discharging = self.discharging,
|
2017-03-24 06:36:15 +00:00
|
|
|
awake = self.awake,
|
|
|
|
sleeping = self.sleeping,
|
|
|
|
charging_state = self.charging_state,
|
|
|
|
awake_state = self.awake_state,
|
|
|
|
})
|
|
|
|
self.settings:flush()
|
|
|
|
end
|
|
|
|
|
|
|
|
function BatteryStat:accumulate()
|
Battery stats plugin: fix and improvements (#5626)
- fix incorrectly shown awake, sleeping, charging and discharging,
- remove unneeded debug mode and logging to external file,
- prevent showing values like inf, -inf, nan in estimated times
(we now show "n/a"), and values below zero,
- show extra confirm box when we want to reset data,
- show time in format xxhxxm instead of only pure minutes,
- check at initialization that the device was charging when it was
turned off (battery level larger than at the time of exit).
2019-11-26 13:21:14 +00:00
|
|
|
if self.was_suspending and not self.was_charging then
|
2017-03-24 06:36:15 +00:00
|
|
|
-- Suspending to awake.
|
|
|
|
self.sleeping:append(self.awake_state)
|
Battery stats plugin: fix and improvements (#5626)
- fix incorrectly shown awake, sleeping, charging and discharging,
- remove unneeded debug mode and logging to external file,
- prevent showing values like inf, -inf, nan in estimated times
(we now show "n/a"), and values below zero,
- show extra confirm box when we want to reset data,
- show time in format xxhxxm instead of only pure minutes,
- check at initialization that the device was charging when it was
turned off (battery level larger than at the time of exit).
2019-11-26 13:21:14 +00:00
|
|
|
elseif not self.was_suspending and not self.was_charging then
|
2017-03-24 06:36:15 +00:00
|
|
|
-- Awake to suspending, time between self.awake_state and now should belong to awake.
|
|
|
|
self.awake:append(self.awake_state)
|
|
|
|
end
|
|
|
|
if self.was_charging then
|
|
|
|
-- Decharging to charging.
|
|
|
|
self.charging:append(self.charging_state)
|
|
|
|
else
|
2017-05-16 09:11:11 +00:00
|
|
|
self.discharging:append(self.charging_state)
|
2017-03-24 06:36:15 +00:00
|
|
|
end
|
|
|
|
self.awake_state = State:new()
|
|
|
|
self.charging_state = State:new()
|
|
|
|
end
|
|
|
|
|
|
|
|
function BatteryStat:onSuspend()
|
2017-08-08 06:29:57 +00:00
|
|
|
if not self.was_suspending then
|
|
|
|
self:accumulate()
|
|
|
|
end
|
|
|
|
self.was_suspending = true
|
2017-03-24 06:36:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function BatteryStat:onResume()
|
2017-08-08 06:29:57 +00:00
|
|
|
if self.was_suspending then
|
|
|
|
self:accumulate()
|
|
|
|
end
|
|
|
|
self.was_suspending = false
|
2017-03-24 06:36:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function BatteryStat:onCharging()
|
2017-08-08 06:29:57 +00:00
|
|
|
if not self.was_charging then
|
Battery stats plugin: fix and improvements (#5626)
- fix incorrectly shown awake, sleeping, charging and discharging,
- remove unneeded debug mode and logging to external file,
- prevent showing values like inf, -inf, nan in estimated times
(we now show "n/a"), and values below zero,
- show extra confirm box when we want to reset data,
- show time in format xxhxxm instead of only pure minutes,
- check at initialization that the device was charging when it was
turned off (battery level larger than at the time of exit).
2019-11-26 13:21:14 +00:00
|
|
|
self:reset(true, true)
|
2017-08-08 06:29:57 +00:00
|
|
|
self:accumulate()
|
|
|
|
end
|
|
|
|
self.was_charging = true
|
2017-03-24 06:36:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function BatteryStat:onNotCharging()
|
2017-08-08 06:29:57 +00:00
|
|
|
if self.was_charging then
|
|
|
|
self:reset(false, true)
|
|
|
|
self:accumulate()
|
|
|
|
end
|
|
|
|
self.was_charging = false
|
2017-03-24 06:36:15 +00:00
|
|
|
end
|
|
|
|
|
2017-04-02 21:46:19 +00:00
|
|
|
function BatteryStat:showStatistics()
|
Battery stats plugin: fix and improvements (#5626)
- fix incorrectly shown awake, sleeping, charging and discharging,
- remove unneeded debug mode and logging to external file,
- prevent showing values like inf, -inf, nan in estimated times
(we now show "n/a"), and values below zero,
- show extra confirm box when we want to reset data,
- show time in format xxhxxm instead of only pure minutes,
- check at initialization that the device was charging when it was
turned off (battery level larger than at the time of exit).
2019-11-26 13:21:14 +00:00
|
|
|
local function askResetData()
|
|
|
|
UIManager:show(ConfirmBox:new{
|
|
|
|
text = _("Are you sure that you want to clear battery statistics?"),
|
|
|
|
ok_text = _("Clear"),
|
|
|
|
ok_callback = function()
|
|
|
|
self:resetAll()
|
|
|
|
self:restart()
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2017-03-24 06:36:15 +00:00
|
|
|
self:accumulate()
|
|
|
|
local kv_pairs = self:dump()
|
|
|
|
table.insert(kv_pairs, "----------")
|
2017-05-16 09:11:11 +00:00
|
|
|
table.insert(kv_pairs, {_("If you would like to reset the data,"), "",
|
|
|
|
callback = function()
|
Battery stats plugin: fix and improvements (#5626)
- fix incorrectly shown awake, sleeping, charging and discharging,
- remove unneeded debug mode and logging to external file,
- prevent showing values like inf, -inf, nan in estimated times
(we now show "n/a"), and values below zero,
- show extra confirm box when we want to reset data,
- show time in format xxhxxm instead of only pure minutes,
- check at initialization that the device was charging when it was
turned off (battery level larger than at the time of exit).
2019-11-26 13:21:14 +00:00
|
|
|
UIManager:setDirty(self.kv_page, "fast")
|
|
|
|
UIManager:scheduleIn(0.1, function()
|
|
|
|
askResetData()
|
|
|
|
end)
|
2017-05-16 09:11:11 +00:00
|
|
|
end})
|
|
|
|
table.insert(kv_pairs, {_("please tap here."), "",
|
|
|
|
callback = function()
|
Battery stats plugin: fix and improvements (#5626)
- fix incorrectly shown awake, sleeping, charging and discharging,
- remove unneeded debug mode and logging to external file,
- prevent showing values like inf, -inf, nan in estimated times
(we now show "n/a"), and values below zero,
- show extra confirm box when we want to reset data,
- show time in format xxhxxm instead of only pure minutes,
- check at initialization that the device was charging when it was
turned off (battery level larger than at the time of exit).
2019-11-26 13:21:14 +00:00
|
|
|
UIManager:setDirty(self.kv_page, "fast")
|
|
|
|
UIManager:scheduleIn(0.1, function()
|
|
|
|
askResetData()
|
|
|
|
end)
|
2017-05-16 09:11:11 +00:00
|
|
|
end})
|
|
|
|
self.kv_page = KeyValuePage:new{
|
2017-03-24 06:36:15 +00:00
|
|
|
title = _("Battery statistics"),
|
|
|
|
kv_pairs = kv_pairs,
|
2017-05-16 09:11:11 +00:00
|
|
|
}
|
|
|
|
UIManager:show(self.kv_page)
|
|
|
|
end
|
|
|
|
|
|
|
|
function BatteryStat:reset(withCharging, withDischarging)
|
|
|
|
self.awake = Usage:new()
|
|
|
|
self.sleeping = Usage:new()
|
|
|
|
|
|
|
|
if withCharging then
|
|
|
|
self.charging = Usage:new()
|
|
|
|
end
|
|
|
|
if withDischarging then
|
|
|
|
self.discharging = Usage:new()
|
|
|
|
end
|
Battery stats plugin: fix and improvements (#5626)
- fix incorrectly shown awake, sleeping, charging and discharging,
- remove unneeded debug mode and logging to external file,
- prevent showing values like inf, -inf, nan in estimated times
(we now show "n/a"), and values below zero,
- show extra confirm box when we want to reset data,
- show time in format xxhxxm instead of only pure minutes,
- check at initialization that the device was charging when it was
turned off (battery level larger than at the time of exit).
2019-11-26 13:21:14 +00:00
|
|
|
self.awake_state = State:new()
|
2017-05-16 09:11:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function BatteryStat:resetAll()
|
|
|
|
self:reset(true, true)
|
|
|
|
self.charging_state = State:new()
|
|
|
|
self.awake_state = State:new()
|
|
|
|
end
|
|
|
|
|
|
|
|
function BatteryStat:restart()
|
|
|
|
dbg.dassert(self.kv_page ~= nil)
|
|
|
|
UIManager:close(self.kv_page)
|
|
|
|
self:showStatistics()
|
2017-03-24 06:36:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function BatteryStat:dump()
|
|
|
|
local kv_pairs = {}
|
|
|
|
table.insert(kv_pairs, {_("Awake since last charge"), ""})
|
|
|
|
self.awake:dump(kv_pairs)
|
|
|
|
self.awake:dumpRemaining(kv_pairs)
|
|
|
|
table.insert(kv_pairs, {_("Sleeping since last charge"), ""})
|
|
|
|
self.sleeping:dump(kv_pairs)
|
|
|
|
self.sleeping:dumpRemaining(kv_pairs)
|
|
|
|
table.insert(kv_pairs, {_("During last charge"), ""})
|
|
|
|
self.charging:dump(kv_pairs)
|
|
|
|
self.charging:dumpCharging(kv_pairs)
|
|
|
|
table.insert(kv_pairs, {_("Since last charge"), ""})
|
2017-05-16 09:11:11 +00:00
|
|
|
self.discharging:dump(kv_pairs)
|
|
|
|
self.discharging:dumpRemaining(kv_pairs)
|
2017-03-24 06:36:15 +00:00
|
|
|
return kv_pairs
|
|
|
|
end
|
|
|
|
|
|
|
|
BatteryStat:init()
|
|
|
|
|
2017-04-02 21:46:19 +00:00
|
|
|
local BatteryStatWidget = WidgetContainer:new{
|
|
|
|
name = "batterystat",
|
|
|
|
}
|
2017-03-24 06:36:15 +00:00
|
|
|
|
|
|
|
function BatteryStatWidget:init()
|
2017-08-08 06:29:57 +00:00
|
|
|
-- self.ui is nil in test cases.
|
|
|
|
if not self.ui or not self.ui.menu then return end
|
2017-03-24 06:36:15 +00:00
|
|
|
self.ui.menu:registerToMainMenu(self)
|
|
|
|
end
|
|
|
|
|
2017-03-26 09:27:43 +00:00
|
|
|
function BatteryStatWidget:addToMainMenu(menu_items)
|
|
|
|
menu_items.battery_statistics = {
|
2017-03-24 06:36:15 +00:00
|
|
|
text = _("Battery statistics"),
|
2018-09-04 21:55:58 +00:00
|
|
|
keep_menu_open = true,
|
2017-03-24 06:36:15 +00:00
|
|
|
callback = function()
|
2017-04-02 21:46:19 +00:00
|
|
|
BatteryStat:showStatistics()
|
2017-03-24 06:36:15 +00:00
|
|
|
end,
|
2017-03-26 10:57:47 +00:00
|
|
|
}
|
2017-03-24 06:36:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function BatteryStatWidget:onFlushSettings()
|
|
|
|
BatteryStat:onFlushSettings()
|
|
|
|
end
|
|
|
|
|
|
|
|
function BatteryStatWidget:onSuspend()
|
|
|
|
BatteryStat:onSuspend()
|
|
|
|
end
|
|
|
|
|
|
|
|
function BatteryStatWidget:onResume()
|
|
|
|
BatteryStat:onResume()
|
|
|
|
end
|
|
|
|
|
|
|
|
function BatteryStatWidget:onCharging()
|
|
|
|
BatteryStat:onCharging()
|
|
|
|
end
|
|
|
|
|
|
|
|
function BatteryStatWidget:onNotCharging()
|
|
|
|
BatteryStat:onNotCharging()
|
|
|
|
end
|
|
|
|
|
2017-08-08 06:29:57 +00:00
|
|
|
-- Test only
|
|
|
|
function BatteryStatWidget:stat()
|
|
|
|
return BatteryStat
|
|
|
|
end
|
|
|
|
|
2017-03-24 06:36:15 +00:00
|
|
|
return BatteryStatWidget
|