mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 08:19:52 +03:00
alova update #6
This commit is contained in:
@@ -69,7 +69,7 @@ const DashboardDevices: FC = () => {
|
||||
immediate: true
|
||||
});
|
||||
|
||||
const { data: deviceData, send: readDeviceData } = useRequest((id) => EMSESP.readDeviceData(id), {
|
||||
const { data: deviceData, send: readDeviceData } = useRequest((data) => EMSESP.readDeviceData(data), {
|
||||
initialData: {
|
||||
data: []
|
||||
},
|
||||
@@ -77,12 +77,9 @@ const DashboardDevices: FC = () => {
|
||||
immediate: false
|
||||
});
|
||||
|
||||
const { loading: submitting, send: writeDeviceValue } = useRequest(
|
||||
(id: number, deviceValue: DeviceValue) => EMSESP.writeDeviceValue(id, deviceValue),
|
||||
{
|
||||
immediate: false
|
||||
}
|
||||
);
|
||||
const { loading: submitting, send: writeDeviceValue } = useRequest((data) => EMSESP.writeDeviceValue(data), {
|
||||
immediate: false
|
||||
});
|
||||
|
||||
useLayoutEffect(() => {
|
||||
function updateSize() {
|
||||
@@ -350,7 +347,7 @@ const DashboardDevices: FC = () => {
|
||||
toast.success(LL.WRITE_CMD_SENT());
|
||||
})
|
||||
.catch((error) => {
|
||||
toast.error(LL.HTTP_ERROR(error));
|
||||
toast.error(error.message);
|
||||
})
|
||||
.finally(async () => {
|
||||
setDeviceValueDialogOpen(false);
|
||||
|
||||
@@ -64,6 +64,8 @@ const showQuality = (stat: Stat) => {
|
||||
};
|
||||
|
||||
const DashboardStatus: FC = () => {
|
||||
// TODO missing update!
|
||||
|
||||
const { loadData, data, errorMessage } = useRest<Status>({ read: EMSESP.readStatus });
|
||||
|
||||
const { LL } = useI18nContext();
|
||||
|
||||
@@ -23,7 +23,7 @@ import {
|
||||
|
||||
import RestartMonitor from 'framework/system/RestartMonitor';
|
||||
import { useI18nContext } from 'i18n/i18n-react';
|
||||
import { numberValue, extractErrorMessage, updateValueDirty, useRest } from 'utils';
|
||||
import { numberValue, extractErrorMessage, updateValueDirty, useRest2 } from 'utils';
|
||||
import { validate } from 'validators';
|
||||
|
||||
export function boardProfileSelectItems() {
|
||||
@@ -47,7 +47,7 @@ const SettingsApplication: FC = () => {
|
||||
blocker,
|
||||
errorMessage,
|
||||
restartNeeded
|
||||
} = useRest<Settings>({
|
||||
} = useRest2<Settings>({
|
||||
read: EMSESP.readSettings,
|
||||
update: EMSESP.writeSettings
|
||||
});
|
||||
@@ -60,6 +60,12 @@ const SettingsApplication: FC = () => {
|
||||
const [fieldErrors, setFieldErrors] = useState<ValidateFieldsError>();
|
||||
const [processingBoard, setProcessingBoard] = useState<boolean>(false);
|
||||
|
||||
// TODO remove - just for testing loaddata
|
||||
// useEffect(() => {
|
||||
// void loadData();
|
||||
// }, []);
|
||||
|
||||
// TODO replace with Alova!
|
||||
const updateBoardProfile = async (boardProfile: string) => {
|
||||
setProcessingBoard(true);
|
||||
try {
|
||||
|
||||
@@ -14,8 +14,7 @@ import type {
|
||||
WriteAnalogSensor,
|
||||
SensorData,
|
||||
Schedule,
|
||||
Entities,
|
||||
DeviceValue
|
||||
Entities
|
||||
} from './types';
|
||||
import type { AxiosPromise } from 'axios';
|
||||
import { AXIOS, AXIOS_API, AXIOS_BIN, alovaInstance } from 'api/endpoints';
|
||||
@@ -28,8 +27,11 @@ export const readDeviceData = (id: number) =>
|
||||
responseType: 'arraybuffer' // uses msgpack
|
||||
});
|
||||
|
||||
export const writeDeviceValue = (id: number, devicevalue: DeviceValue) =>
|
||||
alovaInstance.Post('/writeDeviceValue', { id, devicevalue });
|
||||
export const writeDeviceValue = (data: any) => alovaInstance.Post('/writeDeviceValue', data);
|
||||
|
||||
// SettingsApplication
|
||||
export const readSettings = () => alovaInstance.Get<Settings>('/settings');
|
||||
export const writeSettings = (data: any) => alovaInstance.Post('/settings', data);
|
||||
|
||||
//
|
||||
// TODO change below to use alova
|
||||
@@ -39,14 +41,6 @@ export function restart(): AxiosPromise<void> {
|
||||
return AXIOS.post('/restart');
|
||||
}
|
||||
|
||||
export function readSettings(): AxiosPromise<Settings> {
|
||||
return AXIOS.get('/settings');
|
||||
}
|
||||
|
||||
export function writeSettings(settings: Settings): AxiosPromise<Settings> {
|
||||
return AXIOS.post('/settings', settings); // call command
|
||||
}
|
||||
|
||||
// TODO change to GET
|
||||
export function getBoardProfile(boardProfile: BoardProfileName): AxiosPromise<BoardProfile> {
|
||||
return AXIOS.post('/boardProfile', boardProfile);
|
||||
|
||||
@@ -280,13 +280,6 @@ export interface APIcall {
|
||||
entity: string;
|
||||
id: any;
|
||||
}
|
||||
|
||||
// TODO can be removed?
|
||||
export interface WriteDeviceValue {
|
||||
id: number;
|
||||
devicevalue: DeviceValue;
|
||||
}
|
||||
|
||||
export interface WriteAnalogSensor {
|
||||
id: number;
|
||||
gpio: number;
|
||||
|
||||
Reference in New Issue
Block a user