up some deprecated fixes
Build / Build (push) Successful in 10s

This commit is contained in:
wt committed 2026-03-19 14:54:33 +07:00
1 parent fca32c2233
commit 7f0e5b7b10
8 files changed
+21 -105

No files matched your search

+7 -15
View File
@@ -3,8 +3,8 @@ package api
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"strings"
)
@@ -15,44 +15,38 @@ func HandleTemperature(w http.ResponseWriter, r *http.Request) {
// Thermal zones 0–3
for i := 0; i < 4 && !success; i++ {
tempPath := fmt.Sprintf("/sys/class/thermal/thermal_zone%d/temp", i)
data, err := ioutil.ReadFile(tempPath)
data, err := os.ReadFile(tempPath)
if err != nil {
continue
}
// Читаем тип зоны, если доступен
typePath := fmt.Sprintf("/sys/class/thermal/thermal_zone%d/type", i)
typeData, _ := ioutil.ReadFile(typePath) // ошибку игнорируем
typeData, _ := os.ReadFile(typePath)
zoneType := strings.TrimSpace(string(typeData))
// Парсим температуру
var tempRaw int
if _, err := fmt.Sscanf(string(data), "%d", &tempRaw); err != nil {
continue
}
temp := float64(tempRaw) / 1000.0
// Проверяем, является ли зона CPU/SOC
isCPU := strings.Contains(strings.ToLower(zoneType), "cpu") ||
strings.Contains(strings.ToLower(zoneType), "soc")
temperature = temp
success = true
if isCPU {
break // предпочитаем CPU
break
}
// иначе продолжаем искать CPU
}
// Если thermal не дал результата, пробуем hwmon 0–3
for i := 0; i < 4 && !success; i++ {
tempPath := fmt.Sprintf("/sys/class/hwmon/hwmon%d/temp1_input", i)
data, err := ioutil.ReadFile(tempPath)
data, err := os.ReadFile(tempPath)
if err != nil {
continue
}
// Читаем имя сенсора
namePath := fmt.Sprintf("/sys/class/hwmon/hwmon%d/name", i)
nameData, _ := ioutil.ReadFile(namePath)
nameData, _ := os.ReadFile(namePath)
sensorName := strings.TrimSpace(string(nameData))
var tempRaw int
@@ -72,7 +66,6 @@ func HandleTemperature(w http.ResponseWriter, r *http.Request) {
}
}
// Финальный fallback – просто temp1_input для первых 4 hwmon
if !success {
fallbackPaths := []string{
"/sys/class/hwmon/hwmon0/temp1_input",
@@ -81,7 +74,7 @@ func HandleTemperature(w http.ResponseWriter, r *http.Request) {
"/sys/class/hwmon/hwmon3/temp1_input",
}
for _, path := range fallbackPaths {
data, err := ioutil.ReadFile(path)
data, err := os.ReadFile(path)
if err != nil {
continue
}
@@ -95,7 +88,6 @@ func HandleTemperature(w http.ResponseWriter, r *http.Request) {
}
}
// Формируем JSON-ответ
response := map[string]interface{}{
"success": success,
"temperature": temperature,