Skip to content

Commit

Permalink
fix(timers): Allow execution of timers if time is plausible
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypfer committed Nov 1, 2024
1 parent e627da3 commit 4fc3863
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
27 changes: 18 additions & 9 deletions backend/lib/scheduler/Scheduler.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const Logger = require("../Logger");
const Tools = require("../utils/Tools");
const ValetudoFanSpeedControlTimerPreAction = require("./pre_actions/ValetudoFanSpeedControlTimerPreAction");
const ValetudoFullCleanupTimerAction = require("./actions/ValetudoFullCleanupTimerAction");
const ValetudoNTPClientDisabledState = require("../entities/core/ntpClient/ValetudoNTPClientDisabledState");
Expand Down Expand Up @@ -32,15 +33,23 @@ class Scheduler {
}

evaluateTimers() {
if (
!(
this.ntpClient.state instanceof ValetudoNTPClientSyncedState ||
this.ntpClient.state instanceof ValetudoNTPClientDisabledState
) && this.config.get("embedded") === true
) {
// Since some robots have no rtc, we absolutely require a synced time when embedded
// Therefore, we're aborting without it unless you explicitly disable the NTPClient
// In that case you're on your own to provide the correct time to the robot
const NTPClientStateIsValid = this.ntpClient.state instanceof ValetudoNTPClientSyncedState;
const isEmbedded = this.config.get("embedded") === true;
const hasBuildTimestamp = Tools.GET_BUILD_TIMESTAMP() > new Date(-1);
const timeIsPlausible = Tools.GET_BUILD_TIMESTAMP() < new Date();

let shouldEvaluateTimers;
if (isEmbedded) {
shouldEvaluateTimers = NTPClientStateIsValid || (hasBuildTimestamp && timeIsPlausible);
} else {
if (hasBuildTimestamp) {
shouldEvaluateTimers = timeIsPlausible;
} else { // Probably dev env
shouldEvaluateTimers = true;
}
}

if (!shouldEvaluateTimers) {
return;
}

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

0 comments on commit 4fc3863

Please sign in to comment.