Skip to content

Commit 2304d14

Browse files
committed
fix(timers): Allow execution of timers if time is plausible
1 parent e627da3 commit 2304d14

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

backend/lib/scheduler/Scheduler.js

+18-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const Logger = require("../Logger");
2+
const Tools = require("../utils/Tools");
23
const ValetudoFanSpeedControlTimerPreAction = require("./pre_actions/ValetudoFanSpeedControlTimerPreAction");
34
const ValetudoFullCleanupTimerAction = require("./actions/ValetudoFullCleanupTimerAction");
45
const ValetudoNTPClientDisabledState = require("../entities/core/ntpClient/ValetudoNTPClientDisabledState");
@@ -32,15 +33,23 @@ class Scheduler {
3233
}
3334

3435
evaluateTimers() {
35-
if (
36-
!(
37-
this.ntpClient.state instanceof ValetudoNTPClientSyncedState ||
38-
this.ntpClient.state instanceof ValetudoNTPClientDisabledState
39-
) && this.config.get("embedded") === true
40-
) {
41-
// Since some robots have no rtc, we absolutely require a synced time when embedded
42-
// Therefore, we're aborting without it unless you explicitly disable the NTPClient
43-
// In that case you're on your own to provide the correct time to the robot
36+
const NTPClientStateIsValid = this.ntpClient.state instanceof ValetudoNTPClientSyncedState;
37+
const isEmbedded = this.config.get("embedded") === true;
38+
const hasBuildTimestamp = Tools.GET_BUILD_TIMESTAMP() > new Date(-1);
39+
const timeIsPlausible = Tools.GET_BUILD_TIMESTAMP() < new Date();
40+
41+
let shouldEvaluateTimers;
42+
if (isEmbedded) {
43+
shouldEvaluateTimers = NTPClientStateIsValid || (hasBuildTimestamp && timeIsPlausible);
44+
} else {
45+
if (hasBuildTimestamp) {
46+
shouldEvaluateTimers = timeIsPlausible;
47+
} else { // Probably dev env
48+
shouldEvaluateTimers = true;
49+
}
50+
}
51+
52+
if (!shouldEvaluateTimers) {
4453
return;
4554
}
4655

frontend/src/valetudo/timers/res/TimersHelp.ts

+3-11
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,8 @@ export const TimersHelp = `
33
## Timers
44
55
Timers allow you to execute a task at a specified time (UTC).<br/>
6-
To operate, they require the system time to be synced using the NTP client built into Valetudo.
7-
If it is unable to reach the configured NTP server, no timers will be
8-
executed unless the NTP client was disabled explicitly which would
9-
imply the user is responsible for providing time by other means.
10-
11-
**Please note that timers are evaluated and stored as UTC. They are only displayed in your current browser timezone
12-
for your convenience.**
13-
14-
Timers in Valetudo are provided as a convenience feature.<br/>
15-
It is **highly recommended** to deploy a full-scale home automation system such as openHAB or Home Assistant to allow for
16-
better scheduled operation taking into account e.g. whether or not a room is currently occupied, you're currently on vacation etc.
6+
If the system time isn't plausible (e.g. like when it has never been synced), no timers will be executed.
177
8+
Please note that timers are evaluated and stored as UTC. They are only displayed in your current browser timezone.<br/>
9+
This means that they will not follow any DST rules and thus will have to be updated manually if so required.
1810
`;

0 commit comments

Comments
 (0)