From 5f8253f1f9e41ecdd5167dd262778beef0656d4a Mon Sep 17 00:00:00 2001 From: Cavon Lee Date: Tue, 26 Mar 2024 10:28:42 +0800 Subject: [PATCH] clean up log, add fan status --- src/components/cards/card.jsx | 1 - src/components/cards/fanCard.jsx | 46 ++++++++++++++++++++++------- src/components/home.jsx | 11 ++----- src/components/panels/dashboard.jsx | 10 ++++++- src/components/panels/history.jsx | 1 - src/components/panels/log.jsx | 14 +++++---- 6 files changed, 54 insertions(+), 29 deletions(-) diff --git a/src/components/cards/card.jsx b/src/components/cards/card.jsx index 1e866c5..e5c9e4d 100644 --- a/src/components/cards/card.jsx +++ b/src/components/cards/card.jsx @@ -5,7 +5,6 @@ import "./card.css"; const Card = (props) => { const { icon, width, details, title, data, chart, config, style } = props; - console.log("Card", style) return ( { const theme = useTheme(); - const detail = { - power: { - title: "Percentage", - unit: "%", - }, cpu_temperature: { title: "Temperature", unit: props.unit ? (props.unit === "C" ? "℃" : "℉") : "℃", @@ -20,11 +28,27 @@ const FanCard = (props) => { max: 100, }, } - let newData = props.data.map(obj => ({ - timestamp: timeFormatting(obj.time), - power: obj.fan_power, - cpu_temperature: obj.cpu_temperature, - })); + + let newData = props.data.map(obj => { + let tmp = { + timestamp: timeFormatting(obj.time), + cpu_temperature: obj.cpu_temperature, + } + + if ("pwm_fan_speed" in obj) { + tmp.speed = obj.pwm_fan_speed; + detail.speed = speedDetail; + } + if ("spc_fan_power" in obj) { + tmp.power = obj.spc_fan_power; + detail.power = powerDetail; + } + if ("gpio_fan_state" in obj) { + tmp.state = obj.gpio_fan_state === 1 ? "ON" : "OFF"; + detail.state = stateDetail; + } + return tmp; + }); let chartData = newData.map(({ state, mode, power, ...rest }) => rest) return ( diff --git a/src/components/home.jsx b/src/components/home.jsx index c62627c..b7439e7 100644 --- a/src/components/home.jsx +++ b/src/components/home.jsx @@ -10,7 +10,7 @@ import "./home.css"; const ip = window.location.hostname; const HOST = `http://${ip}:34001/api/v1.0/`; -// const HOST = `http://192.168.100.176:34001/api/v1.0/`; +// const HOST = `http://192.168.100.146:34001/api/v1.0/`; // const HOST = `http://homeassistant.local:34001/api/v1.0/`; const defaultConfigData = { @@ -99,9 +99,7 @@ const Home = (props) => { const getInitData = useCallback(async () => { let _configData = await request("get-config", "GET"); - console.log("getInitData, configData", _configData); let device_info = await request("get-device-info", "GET"); - console.log("getInitData, device_info", device_info); if (_configData) { setPeripherals(device_info.peripherals); setDeviceName(device_info.name); @@ -143,11 +141,8 @@ const Home = (props) => { } const handleSaveConfig = async () => { - // setBasicDialogShow(true); - console.log("set-config-data", configData); // 判断是否发送设置数据 let responseData = await sendData("set-config", configData); - console.log(responseData) if (responseData.status) { showSnackBar("success", "Save Successfully"); // setSettingPageDisplay(false); @@ -156,7 +151,6 @@ const Home = (props) => { const sendData = async (path, data) => { let payload = { data: data }; - console.log("sendData", payload) try { const response = await fetch(HOST + path, { method: "POST", @@ -171,11 +165,10 @@ const Home = (props) => { throw new Error(`HTTP error! Status: ${response.status}`); } const responseData = await response.json(); - console.log("服务器返回的结果:", responseData); return responseData; } catch (error) { - console.error("发生错误:", error); + console.error("Error", error); } } diff --git a/src/components/panels/dashboard.jsx b/src/components/panels/dashboard.jsx index a39d5a1..2fedfef 100644 --- a/src/components/panels/dashboard.jsx +++ b/src/components/panels/dashboard.jsx @@ -47,11 +47,19 @@ const DashboardPanel = (props) => { return value; }; + const isAvaialble = (key) => { + if (key === 'fan') { + return props.peripherals.includes('pwm_fan') || props.peripherals.includes('gpio_fan') || props.peripherals.includes('spc'); + } else { + return props.peripherals.includes(key); + } + } + return ( {props.peripherals.includes('external_input') && } - {props.peripherals.includes('fan') && } + {props.peripherals.includes('pwm_fan') && } {props.peripherals.includes('battery') && } {props.peripherals.includes('raspberry_pi_power') && } diff --git a/src/components/panels/history.jsx b/src/components/panels/history.jsx index 560f740..5219726 100644 --- a/src/components/panels/history.jsx +++ b/src/components/panels/history.jsx @@ -450,7 +450,6 @@ const Chart = (props) => { const theme = useTheme(); const tooltipFormatter = (value, name, props) => { - console.log("tooltipFormatter", value, name, props); return value; } diff --git a/src/components/panels/log.jsx b/src/components/panels/log.jsx index 84b68c6..67d5be0 100644 --- a/src/components/panels/log.jsx +++ b/src/components/panels/log.jsx @@ -42,6 +42,9 @@ const LogPanel = (props) => { const getLog = useCallback(async () => { if (!logFile) return; + if (!logList.includes(logFile)) { + setLogFile(logList[fileIndex]); + } let payload = { filename: logFile, filter: filter, @@ -56,13 +59,16 @@ const LogPanel = (props) => { const index = logList.indexOf(filename); window.localStorage.setItem("pm-dashboard-log-fileIndex", index); window.localStorage.setItem("pm-dashboard-log-logFile", filename); - console.log("handleFileSelect", filename, index); setFileIndex(index); setLogFile(filename); } const getLogList = useCallback(async () => { let result = await props.request('get-log-list', 'GET'); + if (!result) { + props.showSnackBar("error", "Failed to get log list"); + return; + } result.sort(); if (result.length > fileIndex) { setLogFile(result[fileIndex]); @@ -72,7 +78,6 @@ const LogPanel = (props) => { }, [fileIndex, props]); const handleConfigChange = (config) => { - console.log("handleConfigChange", config); if (config.lines !== undefined) { window.localStorage.setItem("pm-dashboard-log-lines", config.lines); setLines(config.lines); @@ -90,7 +95,6 @@ const LogPanel = (props) => { setAutoUpdate(config.autoUpdate); } if (config.autoScroll !== undefined) { - console.log("autoScroll", config.autoScroll); window.localStorage.setItem("pm-dashboard-log-autoScroll", config.autoScroll); setAutoScroll(config.autoScroll); } @@ -101,7 +105,6 @@ const LogPanel = (props) => { } const handleDownload = async () => { - console.log("download log file", fileContent); let content = fileContent.join(""); const blob = new Blob([content], { type: 'text/plain' }); const url = window.URL.createObjectURL(blob); @@ -170,7 +173,7 @@ const LogPanel = (props) => { - {fileContent.map((line, index) => { + {fileContent && fileContent.map((line, index) => { return {line} @@ -196,7 +199,6 @@ const Toolbox = (props) => { const handleToggleGroupChange = (event, newValues) => { setToggleGroupValues(newValues); - console.log("handleToggleGroupChange", newValues) props.onChange({ wrap: newValues.includes("wrap"), autoScroll: newValues.includes("autoScroll"),