mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 09:10:30 +08:00
report a serial number
This commit is contained in:
parent
2294b5a9e1
commit
293490298c
@ -20,6 +20,7 @@
|
|||||||
# ========================================================================== #
|
# ========================================================================== #
|
||||||
|
|
||||||
|
|
||||||
|
import os
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
from typing import List
|
from typing import List
|
||||||
@ -53,9 +54,12 @@ class HwInfoSubmanager(BaseInfoSubmanager):
|
|||||||
self.__vcgencmd_cmd = vcgencmd_cmd
|
self.__vcgencmd_cmd = vcgencmd_cmd
|
||||||
self.__state_poll = state_poll
|
self.__state_poll = state_poll
|
||||||
|
|
||||||
|
self.__dt_cache: Dict[str, str] = {}
|
||||||
|
|
||||||
async def get_state(self) -> Dict:
|
async def get_state(self) -> Dict:
|
||||||
(model, cpu_temp, throttling) = await asyncio.gather(
|
(model, serial, cpu_temp, throttling) = await asyncio.gather(
|
||||||
self.__get_dt_model(),
|
self.__read_dt_file("model"),
|
||||||
|
self.__read_dt_file("serial-number"),
|
||||||
self.__get_cpu_temp(),
|
self.__get_cpu_temp(),
|
||||||
self.__get_throttling(),
|
self.__get_throttling(),
|
||||||
)
|
)
|
||||||
@ -63,6 +67,7 @@ class HwInfoSubmanager(BaseInfoSubmanager):
|
|||||||
"platform": {
|
"platform": {
|
||||||
"type": "rpi",
|
"type": "rpi",
|
||||||
"base": model,
|
"base": model,
|
||||||
|
"serial": serial,
|
||||||
},
|
},
|
||||||
"health": {
|
"health": {
|
||||||
"temp": {
|
"temp": {
|
||||||
@ -83,13 +88,15 @@ class HwInfoSubmanager(BaseInfoSubmanager):
|
|||||||
|
|
||||||
# =====
|
# =====
|
||||||
|
|
||||||
async def __get_dt_model(self) -> Optional[str]:
|
async def __read_dt_file(self, name: str) -> Optional[str]:
|
||||||
model_path = f"{env.PROCFS_PREFIX}/proc/device-tree/model"
|
if name not in self.__dt_cache:
|
||||||
try:
|
path = os.path.join(f"{env.PROCFS_PREFIX}/proc/device-tree", name)
|
||||||
return (await aiofs.read(model_path)).strip(" \t\r\n\0")
|
try:
|
||||||
except Exception as err:
|
self.__dt_cache[name] = (await aiofs.read(path)).strip(" \t\r\n\0")
|
||||||
get_logger(0).error("Can't read DT model from %s: %s", model_path, err)
|
except Exception as err:
|
||||||
return None
|
get_logger(0).error("Can't read DT %s from %s: %s", name, path, err)
|
||||||
|
return None
|
||||||
|
return self.__dt_cache[name]
|
||||||
|
|
||||||
async def __get_cpu_temp(self) -> Optional[float]:
|
async def __get_cpu_temp(self) -> Optional[float]:
|
||||||
temp_path = f"{env.SYSFS_PREFIX}/sys/class/thermal/thermal_zone0/temp"
|
temp_path = f"{env.SYSFS_PREFIX}/sys/class/thermal/thermal_zone0/temp"
|
||||||
|
|||||||
1
testenv/fakes/proc/device-tree/serial-number
Normal file
1
testenv/fakes/proc/device-tree/serial-number
Normal file
@ -0,0 +1 @@
|
|||||||
|
0000000000000000
|
||||||
@ -130,7 +130,8 @@ export function Session() {
|
|||||||
let html = "";
|
let html = "";
|
||||||
if (__info_hw_state !== null) {
|
if (__info_hw_state !== null) {
|
||||||
html += `
|
html += `
|
||||||
Platform base: <span class="code-comment">${__info_hw_state.platform.base}</span><br>
|
Platform:
|
||||||
|
${__formatPlatform(__info_hw_state.platform)}
|
||||||
<hr>
|
<hr>
|
||||||
Temperature:
|
Temperature:
|
||||||
${__formatTemp(__info_hw_state.health.temp)}
|
${__formatTemp(__info_hw_state.health.temp)}
|
||||||
@ -151,6 +152,10 @@ export function Session() {
|
|||||||
$("about-hardware").innerHTML = html;
|
$("about-hardware").innerHTML = html;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var __formatPlatform = function(state) {
|
||||||
|
return __formatUl([["Base", state.base], ["Serial", state.serial]]);
|
||||||
|
};
|
||||||
|
|
||||||
var __formatFan = function(state) {
|
var __formatFan = function(state) {
|
||||||
if (!state.monitored) {
|
if (!state.monitored) {
|
||||||
return __formatUl([["Status", "Not monitored"]]);
|
return __formatUl([["Status", "Not monitored"]]);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user