Adding types to machine.lua

Fixing `powerWidget.getMiddleString` bug
This commit is contained in:
Gabriel Moreira Minossi 2021-01-14 21:11:27 -03:00
parent c4a46b15dc
commit 598cfeb95b
3 changed files with 33 additions and 30 deletions

View File

@ -251,16 +251,16 @@ end
function widget.createPowerWidget(address)
local getPowerStatus = require("domain.energy.get-energy-status-usecase")
local function update(self)
for key, value in pairs(getPowerStatus(address, "power")) do
for key, value in pairs(getPowerStatus(address, self.name)) do
self[key] = value
end
end
local function getMiddleString(self)
local time = self.timeToFull or self.timeToEmpty .. " s"
local time = self.timeToFull or self.timeToEmpty or 0
return (self.dProgress > 0 and "+" or "") ..
self.dProgress ..
" EU/s. " .. (self.dProgress > 0 and " Full in: " or "Empty in: ") .. Utility.splitNumber(time)
" EU/s. " .. (self.dProgress >= 0 and " Full in: " or "Empty in: ") .. Utility.splitNumber(time) .. " s"
end
local powerWidget = {

View File

@ -0,0 +1,30 @@
-- Import section
local mock = require("data.mock.mock-energy-provider")
EnergyProvider = require("data.datasource.energy-provider")
Inherits = require("utils.inherits")
--
local machine = Inherits(EnergyProvider)
local machines = {}
machine.types = {
energy = "energy",
multiblock = "multiblock",
singleblock = "singleblock"
}
function machine.getMachine(address, name, type)
if machines[address] then
return machines[address]
else
local mach = {}
if type == machine.types.energy then
print(machine.name)
elseif type == machine.types.multiblock then
end
mach = machine:new(address, name)
machines[address] = mach
return mach
end
end
return machine

View File

@ -1,27 +0,0 @@
-- Import section
local mock = require("data.mock.mock-energy-provider")
EnergyProvider = require("data.datasource.energy-provider")
Inherits = require("utils.inherits")
--
local machine =
Inherits(
EnergyProvider,
{
mock = mock,
name = "Generic Machine"
}
)
local machines = {}
function machine.getMachine(address, name)
if machines[address] then
return machines[address]
else
local mach = machine:new(address, name)
machines[address] = mach
return mach
end
end
return machine