mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-08 16:59:50 +03:00
Merge branch 'dev' into dev
This commit is contained in:
@@ -102,7 +102,6 @@ const DashboardData: FC = () => {
|
||||
text-transform: uppercase;
|
||||
background-color: black;
|
||||
color: #90CAF9;
|
||||
|
||||
.th {
|
||||
border-bottom: 1px solid #565656;
|
||||
}
|
||||
@@ -111,18 +110,15 @@ const DashboardData: FC = () => {
|
||||
background-color: #1e1e1e;
|
||||
position: relative;
|
||||
cursor: pointer;
|
||||
|
||||
.td {
|
||||
padding: 8px;
|
||||
border-top: 1px solid #565656;
|
||||
border-bottom: 1px solid #565656;
|
||||
}
|
||||
|
||||
&.tr.tr-body.row-select.row-select-single-selected {
|
||||
background-color: #3d4752;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
&:hover .td {
|
||||
border-top: 1px solid #177ac9;
|
||||
border-bottom: 1px solid #177ac9;
|
||||
@@ -279,6 +275,53 @@ const DashboardData: FC = () => {
|
||||
}
|
||||
);
|
||||
|
||||
const fetchSensorData = async () => {
|
||||
try {
|
||||
setSensorData((await EMSESP.readSensorData()).data);
|
||||
} catch (error) {
|
||||
toast.error(extractErrorMessage(error, LL.PROBLEM_LOADING()));
|
||||
}
|
||||
};
|
||||
|
||||
const fetchDeviceData = async (id: string) => {
|
||||
const unique_id = parseInt(id);
|
||||
try {
|
||||
setDeviceData((await EMSESP.readDeviceData({ id: unique_id })).data);
|
||||
} catch (error) {
|
||||
toast.error(extractErrorMessage(error, LL.PROBLEM_LOADING()));
|
||||
}
|
||||
};
|
||||
|
||||
const fetchCoreData = useCallback(async () => {
|
||||
try {
|
||||
setCoreData((await EMSESP.readCoreData()).data);
|
||||
} catch (error) {
|
||||
toast.error(extractErrorMessage(error, LL.PROBLEM_LOADING()));
|
||||
}
|
||||
}, [LL]);
|
||||
|
||||
useEffect(() => {
|
||||
fetchCoreData();
|
||||
}, [fetchCoreData]);
|
||||
|
||||
const refreshDataIndex = (selectedDevice: string) => {
|
||||
if (selectedDevice === 'sensor') {
|
||||
fetchSensorData();
|
||||
return;
|
||||
}
|
||||
|
||||
setSensorData({ sensors: [], analogs: [] });
|
||||
if (selectedDevice) {
|
||||
fetchDeviceData(selectedDevice);
|
||||
} else {
|
||||
fetchCoreData();
|
||||
}
|
||||
};
|
||||
|
||||
const refreshData = () => {
|
||||
refreshDataIndex(device_select.state.id);
|
||||
};
|
||||
|
||||
function onSelectChange(action: any, state: any) {
|
||||
if (action.type === 'ADD_BY_ID_EXCLUSIVELY') {
|
||||
refreshData();
|
||||
@@ -337,36 +380,6 @@ const DashboardData: FC = () => {
|
||||
);
|
||||
};
|
||||
|
||||
const refreshDataIndex = (selectedDevice: string) => {
|
||||
if (selectedDevice === 'sensor') {
|
||||
fetchSensorData();
|
||||
return;
|
||||
}
|
||||
|
||||
setSensorData({ sensors: [], analogs: [] });
|
||||
if (selectedDevice) {
|
||||
fetchDeviceData(selectedDevice);
|
||||
} else {
|
||||
fetchCoreData();
|
||||
}
|
||||
};
|
||||
|
||||
const refreshData = () => {
|
||||
refreshDataIndex(device_select.state.id);
|
||||
};
|
||||
|
||||
const fetchCoreData = useCallback(async () => {
|
||||
try {
|
||||
setCoreData((await EMSESP.readCoreData()).data);
|
||||
} catch (error) {
|
||||
toast.error(extractErrorMessage(error, LL.PROBLEM_LOADING()));
|
||||
}
|
||||
}, [LL]);
|
||||
|
||||
useEffect(() => {
|
||||
fetchCoreData();
|
||||
}, [fetchCoreData]);
|
||||
|
||||
useEffect(() => {
|
||||
const timer = setInterval(() => refreshData(), 60000);
|
||||
return () => {
|
||||
@@ -375,23 +388,6 @@ const DashboardData: FC = () => {
|
||||
// eslint-disable-next-line
|
||||
}, [analog, sensor, deviceValue, sensorData]);
|
||||
|
||||
const fetchDeviceData = async (id: string) => {
|
||||
const unique_id = parseInt(id);
|
||||
try {
|
||||
setDeviceData((await EMSESP.readDeviceData({ id: unique_id })).data);
|
||||
} catch (error) {
|
||||
toast.error(extractErrorMessage(error, LL.PROBLEM_LOADING()));
|
||||
}
|
||||
};
|
||||
|
||||
const fetchSensorData = async () => {
|
||||
try {
|
||||
setSensorData((await EMSESP.readSensorData()).data);
|
||||
} catch (error) {
|
||||
toast.error(extractErrorMessage(error, LL.PROBLEM_LOADING()));
|
||||
}
|
||||
};
|
||||
|
||||
const isCmdOnly = (dv: DeviceValue) => dv.v === '' && dv.c;
|
||||
|
||||
const formatDurationMin = (duration_min: number) => {
|
||||
|
||||
@@ -63,14 +63,14 @@ const SettingsApplication: FC = () => {
|
||||
const [fieldErrors, setFieldErrors] = useState<ValidateFieldsError>();
|
||||
const [processingBoard, setProcessingBoard] = useState<boolean>(false);
|
||||
|
||||
const updateBoardProfile = async (board_profile: string) => {
|
||||
const updateBoardProfile = async (boardProfile: string) => {
|
||||
setProcessingBoard(true);
|
||||
try {
|
||||
const response = await EMSESP.getBoardProfile({ board_profile: board_profile });
|
||||
const response = await EMSESP.getBoardProfile({ board_profile: boardProfile });
|
||||
if (data) {
|
||||
setData({
|
||||
...data,
|
||||
board_profile: board_profile,
|
||||
board_profile: boardProfile,
|
||||
led_gpio: response.data.led_gpio,
|
||||
dallas_gpio: response.data.dallas_gpio,
|
||||
rx_gpio: response.data.rx_gpio,
|
||||
@@ -105,15 +105,15 @@ const SettingsApplication: FC = () => {
|
||||
};
|
||||
|
||||
const changeBoardProfile = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const board_profile = event.target.value;
|
||||
const boardProfile = event.target.value;
|
||||
updateFormValue(event);
|
||||
if (board_profile === 'CUSTOM') {
|
||||
if (boardProfile === 'CUSTOM') {
|
||||
setData({
|
||||
...data,
|
||||
board_profile: board_profile
|
||||
board_profile: boardProfile
|
||||
});
|
||||
} else {
|
||||
updateBoardProfile(board_profile);
|
||||
updateBoardProfile(boardProfile);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -70,6 +70,32 @@ const SettingsCustomization: FC = () => {
|
||||
// eslint-disable-next-line
|
||||
const [masks, setMasks] = useState(() => ['']);
|
||||
|
||||
function hasEntityChanged(de: DeviceEntity) {
|
||||
return (de?.cn || '') !== (de?.o_cn || '') || de.m !== de.o_m || de.ma !== de.o_ma || de.mi !== de.o_mi;
|
||||
}
|
||||
|
||||
const getChanges = () => {
|
||||
if (!deviceEntities || selectedDevice === -1) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return deviceEntities
|
||||
.filter((de) => hasEntityChanged(de))
|
||||
.map(
|
||||
(new_de) =>
|
||||
new_de.m.toString(16).padStart(2, '0') +
|
||||
new_de.id +
|
||||
(new_de.cn || new_de.mi || new_de.ma ? '|' : '') +
|
||||
(new_de.cn ? new_de.cn : '') +
|
||||
(new_de.mi ? '>' + new_de.mi : '') +
|
||||
(new_de.ma ? '<' + new_de.ma : '')
|
||||
);
|
||||
};
|
||||
|
||||
const countChanges = () => {
|
||||
setNumChanges(getChanges().length);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
countChanges();
|
||||
});
|
||||
@@ -262,32 +288,6 @@ const SettingsCustomization: FC = () => {
|
||||
}
|
||||
};
|
||||
|
||||
function hasEntityChanged(de: DeviceEntity) {
|
||||
return (de?.cn || '') !== (de?.o_cn || '') || de.m !== de.o_m || de.ma !== de.o_ma || de.mi !== de.o_mi;
|
||||
}
|
||||
|
||||
const getChanges = () => {
|
||||
if (!deviceEntities || selectedDevice === -1) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return deviceEntities
|
||||
.filter((de) => hasEntityChanged(de))
|
||||
.map(
|
||||
(new_de) =>
|
||||
new_de.m.toString(16).padStart(2, '0') +
|
||||
new_de.id +
|
||||
(new_de.cn || new_de.mi || new_de.ma ? '|' : '') +
|
||||
(new_de.cn ? new_de.cn : '') +
|
||||
(new_de.mi ? '>' + new_de.mi : '') +
|
||||
(new_de.ma ? '<' + new_de.ma : '')
|
||||
);
|
||||
};
|
||||
|
||||
const countChanges = () => {
|
||||
setNumChanges(getChanges().length);
|
||||
};
|
||||
|
||||
const restart = async () => {
|
||||
try {
|
||||
await EMSESP.restart();
|
||||
|
||||
@@ -92,6 +92,26 @@ const SettingsScheduler: FC = () => {
|
||||
return days.map((date) => formatter.format(date));
|
||||
}
|
||||
|
||||
function hasScheduleChanged(si: ScheduleItem) {
|
||||
return (
|
||||
si.id !== si.o_id ||
|
||||
(si?.name || '') !== (si?.o_name || '') ||
|
||||
si.active !== si.o_active ||
|
||||
si.deleted !== si.o_deleted ||
|
||||
si.flags !== si.o_flags ||
|
||||
si.time !== si.o_time ||
|
||||
si.cmd !== si.o_cmd ||
|
||||
si.value !== si.o_value
|
||||
);
|
||||
}
|
||||
|
||||
const getNumChanges = () => {
|
||||
if (!schedule) {
|
||||
return 0;
|
||||
}
|
||||
return schedule.filter((si) => hasScheduleChanged(si)).length;
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
setNumChanges(getNumChanges());
|
||||
});
|
||||
@@ -141,20 +161,6 @@ const SettingsScheduler: FC = () => {
|
||||
`
|
||||
});
|
||||
|
||||
const fetchSchedule = useCallback(async () => {
|
||||
try {
|
||||
const response = await EMSESP.readSchedule();
|
||||
setOriginalSchedule(response.data.schedule);
|
||||
} catch (error) {
|
||||
setErrorMessage(extractErrorMessage(error, LL.PROBLEM_LOADING()));
|
||||
}
|
||||
setDow(getDayNames());
|
||||
}, [LL]);
|
||||
|
||||
useEffect(() => {
|
||||
fetchSchedule();
|
||||
}, [fetchSchedule]);
|
||||
|
||||
const setOriginalSchedule = (data: ScheduleItem[]) => {
|
||||
setSchedule(
|
||||
data.map((si) => ({
|
||||
@@ -171,6 +177,20 @@ const SettingsScheduler: FC = () => {
|
||||
);
|
||||
};
|
||||
|
||||
const fetchSchedule = useCallback(async () => {
|
||||
try {
|
||||
const response = await EMSESP.readSchedule();
|
||||
setOriginalSchedule(response.data.schedule);
|
||||
} catch (error) {
|
||||
setErrorMessage(extractErrorMessage(error, LL.PROBLEM_LOADING()));
|
||||
}
|
||||
setDow(getDayNames());
|
||||
}, [LL]);
|
||||
|
||||
useEffect(() => {
|
||||
fetchSchedule();
|
||||
}, [fetchSchedule]);
|
||||
|
||||
const getFlagNumber = (newFlag: string[]) => {
|
||||
let new_flag = 0;
|
||||
for (const entry of newFlag) {
|
||||
@@ -208,26 +228,6 @@ const SettingsScheduler: FC = () => {
|
||||
return new_flags;
|
||||
};
|
||||
|
||||
function hasScheduleChanged(si: ScheduleItem) {
|
||||
return (
|
||||
si.id !== si.o_id ||
|
||||
(si?.name || '') !== (si?.o_name || '') ||
|
||||
si.active !== si.o_active ||
|
||||
si.deleted !== si.o_deleted ||
|
||||
si.flags !== si.o_flags ||
|
||||
si.time !== si.o_time ||
|
||||
si.cmd !== si.o_cmd ||
|
||||
si.value !== si.o_value
|
||||
);
|
||||
}
|
||||
|
||||
const getNumChanges = () => {
|
||||
if (!schedule) {
|
||||
return 0;
|
||||
}
|
||||
return schedule.filter((si) => hasScheduleChanged(si)).length;
|
||||
};
|
||||
|
||||
const saveSchedule = async () => {
|
||||
if (schedule) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user