From 50400459ee12b8427b1245ac0e05c5a5781d86f3 Mon Sep 17 00:00:00 2001 From: Proddy Date: Sat, 25 Feb 2023 16:13:47 +0100 Subject: [PATCH] add NTP check to scheduler --- interface/src/i18n/de/index.ts | 9 ++- interface/src/i18n/en/index.ts | 9 ++- interface/src/i18n/fr/index.ts | 9 ++- interface/src/i18n/nl/index.ts | 9 ++- interface/src/i18n/no/index.ts | 9 ++- interface/src/i18n/pl/index.ts | 9 ++- interface/src/i18n/sv/index.ts | 9 ++- interface/src/project/SettingsScheduler.tsx | 56 +++++++++++---- interface/src/project/api.ts | 3 +- interface/src/project/types.ts | 1 + mock-api/server.js | 79 +++++++++++---------- 11 files changed, 129 insertions(+), 73 deletions(-) diff --git a/interface/src/i18n/de/index.ts b/interface/src/i18n/de/index.ts index 5fa222f3d..0b6e8b2cf 100644 --- a/interface/src/i18n/de/index.ts +++ b/interface/src/i18n/de/index.ts @@ -309,13 +309,16 @@ const de: Translation = { STAY: 'Stay', // TODO translate LEAVE: 'Leave', // TODO translate SCHEDULER: 'Scheduler', // TODO translate - SCHEDULER_HELP_1: 'Add custom scheduled commands to automate EMS-ESP.', // TODO translate - SCHEDULER_HELP_2: 'The NTP service needs to be active if using the calendar.', // TODO translate + SCHEDULER_HELP_1: 'Add custom scheduled commands to automate EMS-ESP', // TODO translate + SCHEDULER_HELP_2: 'The NTP service needs to be active if using the calendar', // TODO translate SCHEDULE: 'Schedule', // TODO translate TIME: 'Time', // TODO translate TIMER: 'Timer', // TODO translate WEEKLY: 'Weekly', // TODO translate - SCHEDULE_SAVED: 'Schedule updated' // TODO translate + SCHEDULE_SAVED: 'Schedule updated', // TODO translate + SCHEDULE_TIMER_1: 'on startup', // TODO translate + SCHEDULE_TIMER_2: 'every minute', // TODO translate + SCHEDULE_TIMER_3: 'every hour' // TODO translate }; export default de; diff --git a/interface/src/i18n/en/index.ts b/interface/src/i18n/en/index.ts index 63c4f2f93..e7330c0a0 100644 --- a/interface/src/i18n/en/index.ts +++ b/interface/src/i18n/en/index.ts @@ -309,13 +309,16 @@ const en: Translation = { STAY: 'Stay', LEAVE: 'Leave', SCHEDULER: 'Scheduler', - SCHEDULER_HELP_1: 'Add custom scheduled commands to automate EMS-ESP.', - SCHEDULER_HELP_2: 'The NTP service needs to be active if using the calendar.', + SCHEDULER_HELP_1: 'Add custom scheduled commands to automate EMS-ESP', + SCHEDULER_HELP_2: 'The NTP service needs to be active if using the calendar', SCHEDULE: 'Schedule', TIME: 'Time', TIMER: 'Timer', WEEKLY: 'Weekly', - SCHEDULE_SAVED: 'Schedule updated' + SCHEDULE_SAVED: 'Schedule updated', + SCHEDULE_TIMER_1: 'on startup', + SCHEDULE_TIMER_2: 'every minute', + SCHEDULE_TIMER_3: 'every hour' }; export default en; diff --git a/interface/src/i18n/fr/index.ts b/interface/src/i18n/fr/index.ts index 028078da3..1d6752dc0 100644 --- a/interface/src/i18n/fr/index.ts +++ b/interface/src/i18n/fr/index.ts @@ -309,13 +309,16 @@ const fr: Translation = { STAY: 'Stay', // TODO translate LEAVE: 'Leave', // TODO translate SCHEDULER: 'Scheduler', // TODO translate - SCHEDULER_HELP_1: 'Add custom scheduled commands to automate EMS-ESP.', // TODO translate - SCHEDULER_HELP_2: 'The NTP service needs to be active if using the calendar.', // TODO translate + SCHEDULER_HELP_1: 'Add custom scheduled commands to automate EMS-ESP', // TODO translate + SCHEDULER_HELP_2: 'The NTP service needs to be active if using the calendar', // TODO translate SCHEDULE: 'Schedule', // TODO translate TIME: 'Time', // TODO translate TIMER: 'Timer', // TODO translate WEEKLY: 'Weekly', // TODO translate - SCHEDULE_SAVED: 'Schedule updated' // TODO translate + SCHEDULE_SAVED: 'Schedule updated', // TODO translate + SCHEDULE_TIMER_1: 'on startup', // TODO translate + SCHEDULE_TIMER_2: 'every minute', // TODO translate + SCHEDULE_TIMER_3: 'every hour' // TODO translate }; export default fr; diff --git a/interface/src/i18n/nl/index.ts b/interface/src/i18n/nl/index.ts index 5a2f33f16..c963f6bb1 100644 --- a/interface/src/i18n/nl/index.ts +++ b/interface/src/i18n/nl/index.ts @@ -309,13 +309,16 @@ const nl: Translation = { STAY: 'Stay', // TODO translate LEAVE: 'Leave', // TODO translate SCHEDULER: 'Scheduler', // TODO translate - SCHEDULER_HELP_1: 'Add custom scheduled commands to automate EMS-ESP.', // TODO translate - SCHEDULER_HELP_2: 'The NTP service needs to be active if using the calendar.', // TODO translate + SCHEDULER_HELP_1: 'Add custom scheduled commands to automate EMS-ESP', // TODO translate + SCHEDULER_HELP_2: 'The NTP service needs to be active if using the calendar', // TODO translate SCHEDULE: 'Schedule', // TODO translate TIME: 'Time', // TODO translate TIMER: 'Timer', // TODO translate WEEKLY: 'Weekly', // TODO translate - SCHEDULE_SAVED: 'Schedule updated' // TODO translate + SCHEDULE_SAVED: 'Schedule updated', // TODO translate + SCHEDULE_TIMER_1: 'on startup', // TODO translate + SCHEDULE_TIMER_2: 'every minute', // TODO translate + SCHEDULE_TIMER_3: 'every hour' // TODO translate }; export default nl; diff --git a/interface/src/i18n/no/index.ts b/interface/src/i18n/no/index.ts index 8ee684b00..1e143b8fb 100644 --- a/interface/src/i18n/no/index.ts +++ b/interface/src/i18n/no/index.ts @@ -309,13 +309,16 @@ const no: Translation = { STAY: 'Stay', // TODO translate LEAVE: 'Leave', // TODO translate SCHEDULER: 'Scheduler', // TODO translate - SCHEDULER_HELP_1: 'Add custom scheduled commands to automate EMS-ESP.', // TODO translate - SCHEDULER_HELP_2: 'The NTP service needs to be active if using the calendar.', // TODO translate + SCHEDULER_HELP_1: 'Add custom scheduled commands to automate EMS-ESP', // TODO translate + SCHEDULER_HELP_2: 'The NTP service needs to be active if using the calendar', // TODO translate SCHEDULE: 'Schedule', // TODO translate TIME: 'Time', // TODO translate TIMER: 'Timer', // TODO translate WEEKLY: 'Weekly', // TODO translate - SCHEDULE_SAVED: 'Schedule updated' // TODO translate + SCHEDULE_SAVED: 'Schedule updated', // TODO translate + SCHEDULE_TIMER_1: 'on startup', // TODO translate + SCHEDULE_TIMER_2: 'every minute', // TODO translate + SCHEDULE_TIMER_3: 'every hour' // TODO translate }; export default no; diff --git a/interface/src/i18n/pl/index.ts b/interface/src/i18n/pl/index.ts index f584388b5..2a7c7d893 100644 --- a/interface/src/i18n/pl/index.ts +++ b/interface/src/i18n/pl/index.ts @@ -309,13 +309,16 @@ const pl: BaseTranslation = { STAY: 'Stay', // TODO translate LEAVE: 'Leave', // TODO translate SCHEDULER: 'Scheduler', // TODO translate - SCHEDULER_HELP_1: 'Add custom scheduled commands to automate EMS-ESP.', // TODO translate - SCHEDULER_HELP_2: 'The NTP service needs to be active if using the calendar.', // TODO translate + SCHEDULER_HELP_1: 'Add custom scheduled commands to automate EMS-ESP', // TODO translate + SCHEDULER_HELP_2: 'The NTP service needs to be active if using the calendar', // TODO translate SCHEDULE: 'Schedule', // TODO translate SCHEDULE: 'Schedule', // TODO translate TIME: 'Time', // TODO translate TIMER: 'Timer', // TODO translate WEEKLY: 'Weekly', // TODO translate - SCHEDULE_SAVED: 'Schedule updated' // TODO translate + SCHEDULE_SAVED: 'Schedule updated', // TODO translate + SCHEDULE_TIMER_1: 'on startup', // TODO translate + SCHEDULE_TIMER_2: 'every minute', // TODO translate + SCHEDULE_TIMER_3: 'every hour' // TODO translate }; export default pl; diff --git a/interface/src/i18n/sv/index.ts b/interface/src/i18n/sv/index.ts index f4ab275b4..cc258c7b8 100644 --- a/interface/src/i18n/sv/index.ts +++ b/interface/src/i18n/sv/index.ts @@ -309,13 +309,16 @@ const sv: Translation = { STAY: 'Stay', // TODO translate LEAVE: 'Leave', // TODO translate SCHEDULER: 'Scheduler', // TODO translate - SCHEDULER_HELP_1: 'Add custom scheduled commands to automate EMS-ESP.', // TODO translate - SCHEDULER_HELP_2: 'The NTP service needs to be active if using the calendar.', // TODO translate + SCHEDULER_HELP_1: 'Add custom scheduled commands to automate EMS-ESP', // TODO translate + SCHEDULER_HELP_2: 'The NTP service needs to be active if using the calendar', // TODO translate SCHEDULE: 'Schedule', // TODO translate TIME: 'Time', // TODO translate TIMER: 'Timer', // TODO translate WEEKLY: 'Weekly', // TODO translate - SCHEDULE_SAVED: 'Schedule updated' // TODO translate + SCHEDULE_SAVED: 'Schedule updated', // TODO translate + SCHEDULE_TIMER_1: 'on startup', // TODO translate + SCHEDULE_TIMER_2: 'every minute', // TODO translate + SCHEDULE_TIMER_3: 'every hour' // TODO translate }; export default sv; diff --git a/interface/src/project/SettingsScheduler.tsx b/interface/src/project/SettingsScheduler.tsx index 4d2e78ff8..334fbeb7f 100644 --- a/interface/src/project/SettingsScheduler.tsx +++ b/interface/src/project/SettingsScheduler.tsx @@ -11,6 +11,7 @@ import { DialogContent, DialogTitle, ToggleButton, + MenuItem, ToggleButtonGroup, Checkbox, TextField @@ -27,7 +28,15 @@ import WarningIcon from '@mui/icons-material/Warning'; import CancelIcon from '@mui/icons-material/Cancel'; import DoneIcon from '@mui/icons-material/Done'; -import { ButtonRow, FormLoader, BlockFormControlLabel, SectionContent, BlockNavigation } from 'components'; +import { + ValidatedTextField, + MessageBox, + ButtonRow, + FormLoader, + BlockFormControlLabel, + SectionContent, + BlockNavigation +} from 'components'; import * as EMSESP from './api'; @@ -62,6 +71,8 @@ const SettingsScheduler: FC = () => { const [schedule, setSchedule] = useState([emptySchedule]); const [scheduleItem, setScheduleItem] = useState(); + const [ntpAvailable, setNTPavailable] = useState(true); + const [dow, setDow] = useState([]); function getDayNames() { @@ -136,7 +147,9 @@ const SettingsScheduler: FC = () => { const fetchSchedule = useCallback(async () => { try { - setOriginalSchedule((await EMSESP.readSchedule()).data); + const response = await EMSESP.readSchedule(); + setNTPavailable(response.data.ntp_available); + setOriginalSchedule(response.data.schedule); } catch (error) { setErrorMessage(extractErrorMessage(error, LL.PROBLEM_LOADING())); } @@ -222,6 +235,7 @@ const SettingsScheduler: FC = () => { if (schedule) { try { const response = await EMSESP.writeSchedule({ + ntp_available: ntpAvailable, schedule: schedule .filter((si) => !si.deleted) .map((new_si) => { @@ -406,7 +420,6 @@ const SettingsScheduler: FC = () => { label={LL.DESCRIPTION()} value={scheduleItem.description} fullWidth - autoFocus margin="normal" sx={{ width: '60ch' }} onChange={updateValue(setScheduleItem)} @@ -415,14 +428,33 @@ const SettingsScheduler: FC = () => { control={} label={LL.ACTIVE()} /> - + + {(scheduleItem.flags & ScheduleFlag.SCHEDULE_TIMER) === ScheduleFlag.SCHEDULE_TIMER ? ( + + {LL.SCHEDULE_TIMER_1()} + {LL.SCHEDULE_TIMER_2()} + {LL.SCHEDULE_TIMER_3()} + + ) : ( + + )} + { {blocker ? : null} {LL.SCHEDULER_HELP_1()} - {LL.SCHEDULER_HELP_2()} + {!ntpAvailable && } {renderSchedule()} {renderEditSchedule()} diff --git a/interface/src/project/api.ts b/interface/src/project/api.ts index 6de15adf2..6dcc380bf 100644 --- a/interface/src/project/api.ts +++ b/interface/src/project/api.ts @@ -17,7 +17,6 @@ import { WriteSensor, WriteAnalog, SensorData, - ScheduleItem, Schedule } from './types'; @@ -97,7 +96,7 @@ export function getCustomizations(): AxiosPromise { return AXIOS.get('/getCustomizations'); } -export function readSchedule(): AxiosPromise { +export function readSchedule(): AxiosPromise { return AXIOS.get('/getSchedule'); } diff --git a/interface/src/project/types.ts b/interface/src/project/types.ts index f5d7d5c74..a564e2b4d 100644 --- a/interface/src/project/types.ts +++ b/interface/src/project/types.ts @@ -323,6 +323,7 @@ export interface ScheduleItem { } export interface Schedule { + ntp_available: boolean; schedule: ScheduleItem[]; } diff --git a/mock-api/server.js b/mock-api/server.js index fb8586885..84b847acc 100644 --- a/mock-api/server.js +++ b/mock-api/server.js @@ -600,44 +600,47 @@ const emsesp_devicedata_4 = { }; // SCHEDULE -let emsesp_schedule = [ - { - id: '1', - active: true, - flags: 31, - time: '07:30', - cmd: 'hc1/mode', - value: 'day', - description: 'Turn on central heating in morning' - }, - { - id: '2', - active: true, - flags: 31, - time: '23:00', - cmd: 'hc1/mode', - value: 'night', - description: 'Turn off central heating for the night' - }, - { - id: '3', - active: true, - flags: 128, - time: '00:01', - cmd: 'thermostat/hc2/seltemp', - value: '20', - description: 'Force thermostat temperature to 20 degrees every minute' - }, - { - id: '4', - active: false, - flags: 85, - time: '04:00', - cmd: 'system/restart', - value: '', - description: 'auto restart EMS-EPS at 4am every other day' - } -]; +let emsesp_schedule = { + ntp_available: true, + schedule: [ + { + id: '1', + active: true, + flags: 31, + time: '07:30', + cmd: 'hc1/mode', + value: 'day', + description: 'Turn on central heating in morning' + }, + { + id: '2', + active: true, + flags: 31, + time: '23:00', + cmd: 'hc1/mode', + value: 'night', + description: 'Turn off central heating for the night' + }, + { + id: '3', + active: true, + flags: 128, + time: '00:01', + cmd: 'thermostat/hc2/seltemp', + value: '20', + description: 'Force thermostat temperature to 20 degrees every minute' + }, + { + id: '4', + active: false, + flags: 85, + time: '04:00', + cmd: 'system/restart', + value: '', + description: 'auto restart EMS-EPS at 4am every other day' + } + ] +}; // CUSTOMIZATIONS