Skip to content

Commit

Permalink
feat: Add Mechanical Pipe input adapter
Browse files Browse the repository at this point in the history
these were so easy wtf
  • Loading branch information
bananasov committed Oct 8, 2023
1 parent 483bb0b commit 85d7005
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions src/telem/lib/input/mekanism/MechanicalPipeInputAdapter.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
local o = require 'telem.lib.ObjectModel'
local t = require 'telem.lib.util'

local InputAdapter = require 'telem.lib.InputAdapter'
local Metric = require 'telem.lib.Metric'
local MetricCollection = require 'telem.lib.MetricCollection'

local MechanicalPipeInputAdapter = o.class(InputAdapter)
MechanicalPipeInputAdapter.type = 'MechanicalPipeInputAdapter'

function MechanicalPipeInputAdapter:constructor (peripheralName, categories)
self:super('constructor')

-- TODO this will be a configurable feature later
self.prefix = 'mekmechpipe:'

-- TODO make these constants
local allCategories = {
'basic',
}

if not categories then
self.categories = { 'basic' }
elseif categories == '*' then
self.categories = allCategories
else
self.categories = categories
end

-- boot components
self:setBoot(function ()
self.components = {}

self:addComponentByPeripheralID(peripheralName)
end)()
end

function MechanicalPipeInputAdapter:read ()
self:boot()

local source, tube = next(self.components)

local metrics = MetricCollection()

local loaded = {}

for _,v in ipairs(self.categories) do
-- skip, already loaded
if loaded[v] then
-- do nothing

-- Literally all we have lmao
elseif v == 'basic' then
metrics:insert(Metric{ name = self.prefix .. 'buffer', value = tube.getBuffer() / 1000, unit = "B", source = source })
metrics:insert(Metric{ name = self.prefix .. 'capacity', value = tube.getCapacity() / 1000, unit = "B", source = source }) -- might error might not, no clue!
metrics:insert(Metric{ name = self.prefix .. 'needed', value = tube.getNeeded() / 1000, unit = "B", source = source })
metrics:insert(Metric{ name = self.prefix .. 'filled_percentage', value = tube.getFilledPercentage(), unit = nil, source = source })
end

loaded[v] = true
end

return metrics
end

return MechanicalPipeInputAdapter

0 comments on commit 85d7005

Please sign in to comment.