diff --git a/src/features/machines/components/WakeComponent.js b/src/features/machines/components/WakeComponent.js index 4336f04..749b76e 100644 --- a/src/features/machines/components/WakeComponent.js +++ b/src/features/machines/components/WakeComponent.js @@ -7,6 +7,7 @@ import { useToast } from "../../../hooks"; import * as api from "../api"; const initialState = { on: false }; +const defaultPingInterval = 1200000; //20 minutes const WakeComponent = ({ machine, addLog }) => { const [state, setState] = useState(initialState); @@ -14,6 +15,9 @@ const WakeComponent = ({ machine, addLog }) => { const { t } = useTranslation(); const { success, error } = useToast(); + const pingInterval = + process.env.REACT_APP_MACHINE_PING_INTERVAL || defaultPingInterval; + const getCurrentDateTime = useCallback(() => { const currentDateTime = Date.now(); const result = t("DATE_FORMAT", { @@ -24,6 +28,7 @@ const WakeComponent = ({ machine, addLog }) => { const wakeMachine = useCallback(async () => { const result = await api.wakeMachine(machine.macAddress); + setState(prev => ({ ...prev, on: result.success })); addLog( `[${getCurrentDateTime()}] [Wake]: Success: ${result.success}. Status: ${ result.status @@ -47,8 +52,8 @@ const WakeComponent = ({ machine, addLog }) => { }); setTimeout(() => { setTrigger(prev => !prev); - }, 60000); - }, [machine, addLog, getCurrentDateTime, trigger]); + }, pingInterval); + }, [machine, addLog, getCurrentDateTime, pingInterval, trigger]); return (