Skip to content

Commit

Permalink
clean up log, add fan status
Browse files Browse the repository at this point in the history
  • Loading branch information
cavonlee committed Mar 26, 2024
1 parent 45d2d56 commit 5f8253f
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 29 deletions.
1 change: 0 additions & 1 deletion src/components/cards/card.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Paper className="card"
color={props.color}
Expand Down
46 changes: 35 additions & 11 deletions src/components/cards/fanCard.jsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import React from 'react';
import Card from './card.jsx';
import Chart from './chart.jsx';
import { timeFormatting, firstUpperCase } from '../../js/utils.js';
import { timeFormatting } from '../../js/utils.js';
import { useTheme } from '@mui/material/styles';

const powerDetail = {
title: "Percentage",
unit: "%",
};
const speedDetail = {
title: "PWM Fan Speed",
unit: "RPM",
};
const stateDetail = {
title: "GPIO Fan State",
unit: "",
};

const FanCard = (props) => {
const theme = useTheme();

const detail = {
power: {
title: "Percentage",
unit: "%",
},
cpu_temperature: {
title: "Temperature",
unit: props.unit ? (props.unit === "C" ? "℃" : "℉") : "℃",
Expand All @@ -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 (
Expand Down
11 changes: 2 additions & 9 deletions src/components/home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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",
Expand All @@ -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);
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/components/panels/dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (<Box sx={{ width: "100%", height: "100%", overflowY: "scroll", overflowX: "hidden" }}>
<Panel title={props.deviceName} {...props}>
<Box sx={{ display: "flex", flexFlow: "wrap", gap: "70px 40px" }}>
{props.peripherals.includes('external_input') && <ExternalInputCard data={data} bytesFormatter={bytesFormatter} />}
{props.peripherals.includes('fan') && <FanCard data={data} request={props.request} unit={props.temperatureUnit || "C"} />}
{props.peripherals.includes('pwm_fan') && <FanCard data={data} request={props.request} unit={props.temperatureUnit || "C"} />}
{props.peripherals.includes('battery') && <BatteryCard data={data} />}
{props.peripherals.includes('raspberry_pi_power') && <RaspberryPiPowerCard data={data} />}

Expand Down
1 change: 0 additions & 1 deletion src/components/panels/history.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,6 @@ const Chart = (props) => {
const theme = useTheme();

const tooltipFormatter = (value, name, props) => {
console.log("tooltipFormatter", value, name, props);
return value;
}

Expand Down
14 changes: 8 additions & 6 deletions src/components/panels/log.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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]);
Expand All @@ -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);
Expand All @@ -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);
}
Expand All @@ -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);
Expand Down Expand Up @@ -170,7 +173,7 @@ const LogPanel = (props) => {
<Toolbox lines={lines} level={level} filter={filter} wrap={wrap} autoUpdate={autoUpdate} autoScroll={autoScroll} onChange={handleConfigChange} />
<Box ref={contentRef} sx={{ flexGrow: 1, overflow: `${wrap ? "hidden" : "auto"} auto` }}>
<List>
{fileContent.map((line, index) => {
{fileContent && fileContent.map((line, index) => {
return <ListItem key={index} disablePadding>
<Typography sx={{ fontFamily: "Courier New", textWrap: wrap ? "wrap" : "nowrap" }}> {line} </Typography>
</ListItem>
Expand All @@ -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"),
Expand Down

0 comments on commit 5f8253f

Please sign in to comment.