Skip to content

Commit

Permalink
working from home: better detection of active state
Browse files Browse the repository at this point in the history
make sure system has been in active state for ten minutes without any
halfwake transition etc before updating status
  • Loading branch information
tbjolset committed Mar 8, 2023
1 parent 2a329bc commit 667bcd2
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions Working From Home/wfh.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
*/
import xapi from 'xapi';

const deviceStatus = '🏠 Working from home';
const deviceStatus = '🏰 In office today';
const startHour = 8;
const endHour = 16;
const askBeforeChanging = true;
const durationHours = 8;
const pollIntervalMinutes = 5;
const minActiveMinutes = 10;
let timerId;

// If false, don't update status if one is already set (eg a holiday status)
const overrideExisting = false;
Expand Down Expand Up @@ -102,9 +103,15 @@ async function checkAndUpdateStatus() {
}
}

function onStandbyChanged(state) {
clearTimeout(timerId);
if (state === 'Off') {
timerId = setTimeout(checkAndUpdateStatus, minActiveMinutes * 60 * 1000);
}
}

function init() {
// dont check right away, we dont want to update if the device woke up by itself
setInterval(checkAndUpdateStatus, 1000 * 60 * pollIntervalMinutes);
xapi.Status.Standby.State.on(onStandbyChanged);
xapi.Event.UserInterface.Message.Prompt.Response.on(onResponse);
}

Expand Down

0 comments on commit 667bcd2

Please sign in to comment.