InfOS/Programs/monitor-system/domain/multiblock/get-multiblock-status-usecase.lua
Gabriel Moreira Minossi f1d77a7eee Adjusting getMultiblockStatusUsecase
Returning status outside of a table
Using `isWorkAllowed` instead of an unexistent method
2021-01-17 23:16:26 -03:00

39 lines
954 B
Lua
Executable File

-- Import section
Machine = require("data.datasource.machine")
--
local function exec(address, name)
local multiblock = Machine.getMachine(address, name, Machine.types.multiblock)
local status = {}
local problems = multiblock:getNumberOfProblems()
local state = {}
if multiblock:isWorkAllowed() then
if multiblock:hasWork() then
state = Machine.states.ON
else
state = Machine.states.IDLE
end
else
state = Machine.states.OFF
end
if problems > 0 then
state = Machine.states.BROKEN
end
local totalProgress = multiblock:getProgress()
status = {
progress = totalProgress.current,
maxProgress = totalProgress.maximum,
problems = problems,
probablyUses = multiblock:getEnergyUsage(),
efficiencyPercentage = multiblock:getEfficiencyPercentage(),
state = state
}
return status
end
return exec