Skip to content

Commit

Permalink
Remove duplicates into getTempStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
remittor committed Jan 21, 2024
1 parent 8146f53 commit 456bbee
Showing 1 changed file with 38 additions and 12 deletions.
50 changes: 38 additions & 12 deletions root/usr/libexec/rpcd/luci.temp-status
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env lua

local sys = require "luci.sys"
local json = require "luci.jsonc"
local fs = require "nixio.fs"

Expand All @@ -18,24 +19,26 @@ end
local function getTempStatus()
local sensors = {}
-- /sys/class/hwmon
local hwmon = {}
local hwmonDir = fs.dir(sysHwmon)
if hwmonDir then
local hwmon = {}
for item in hwmonDir do
if item:match("^hwmon[0-9]+$") then
local deviceDirPath = string.format("%s/%s", sysHwmon, item)
local deviceDir = fs.dir(deviceDirPath)
if deviceDir then
local hwmonDirPath = string.format("%s/%s", sysHwmon, item)
local deviceDirPath = string.format("%s/device", hwmonDirPath)
local realDevPath = sys.exec("readlink -f " .. deviceDirPath .. " 2>/dev/null | xargs echo -n") or ""
local hwmonDir = fs.dir(hwmonDirPath)
if hwmonDir then
local dNumber = tonumber(item:match("[0-9]+"))
local title = readFile(deviceDirPath .. "/name")
local title = readFile(hwmonDirPath .. "/name")
local sources = {}
for source in deviceDir do
for source in hwmonDir do
if source:match("^temp[0-9]+_input$") then
local sNumber = tonumber(source:match("[0-9]+"))
local temp = readFile(
string.format("%s/%s", deviceDirPath, source))
string.format("%s/%s", hwmonDirPath, source))
local label = readFile(
string.format("%s/%s", deviceDirPath, source:gsub("_input$", "_label")))
string.format("%s/%s", hwmonDirPath, source:gsub("_input$", "_label")))
if sNumber ~= nil and temp ~= nil then
sources[#sources + 1] = {
number = sNumber,
Expand All @@ -51,6 +54,7 @@ local function getTempStatus()
hwmon[#hwmon + 1] = {
number = dNumber,
item = item,
devpath = realDevPath,
title = title,
sources = sources,
}
Expand All @@ -68,13 +72,35 @@ local function getTempStatus()
if dir then
local thermal = {}
for item in dir do
if item:match("^thermal_zone[0-9]+$") then
local deviceDirPath
local realDevPath
local skip = false
if not item:match("^thermal_zone[0-9]+$") then
skip = true
end
if not skip then
deviceDirPath = string.format("%s/%s", sysThermal, item)
realDevPath = sys.exec("readlink -f " .. deviceDirPath .. " 2>/dev/null | xargs echo -n") or ""
for _, hw in pairs(hwmon) do
if hw.devpath ~= nil and #hw.devpath > 0 then
if hw.devpath == realDevPath then
skip = true
break
end
end
end
end
if not skip then
local number = tonumber(item:match("[0-9]+"))
local temp = readFile(string.format("%s/%s/temp", sysThermal, item))
local title = readFile(string.format("%s/%s/type", sysThermal, item))
local temp = readFile(string.format("%s/temp", deviceDirPath))
local title = readFile(string.format("%s/type", deviceDirPath))
if number ~= nil and temp ~= nil then
thermal[#thermal + 1] = {
number = number, item = item, title = title, sources = {
number = number,
item = item,
devpath = realDevPath,
title = title,
sources = {
[1] = { number = 0, item = nil, label = nil, temp = tonumber(temp) }
}
}
Expand Down

0 comments on commit 456bbee

Please sign in to comment.