-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcheck_update_backup.js
More file actions
48 lines (40 loc) · 1.65 KB
/
check_update_backup.js
File metadata and controls
48 lines (40 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* Check if Backup or Update is running - if so, it returns systemBusy TRUE with relevant tags, eg. updateRunning TRUE etc.
* It can be used as triggers, eg. disable Homey monitoring when update started (...and it's expected it will get installed and Homey restarted)
* Outcome: true if update OR backup is running
*/
const updateState = await Homey.updates.getState();
const backupState = await Homey.backup.getState();
// UPDATE
const updateDownloading = updateState?.downloading === true;
const updateInstalling = updateState?.installing === true;
const updateProgress =
(typeof updateState?.downloads_progress === 'number')
? updateState.downloads_progress
: 0;
const updateRunning = updateDownloading || updateInstalling || updateProgress > 0;
// BACKUP
const backupStateValue = backupState?.backupState ?? 'unknown';
const backupRunning = backupStateValue !== 'idle';
// TAGS
await tag('updateRunning', Boolean(updateRunning));
await tag('updateDownloading', Boolean(updateDownloading));
await tag('updateInstalling', Boolean(updateInstalling));
await tag('updateProgress', Number(updateProgress));
await tag('backupRunning', Boolean(backupRunning));
await tag('backupState', String(backupStateValue));
await tag('backupStateString', String(backupState?.backupStateString ?? ''));
await tag('backupError', String(backupState?.backupError ?? ''));
// DEBUG
const systemBusy = (updateRunning || backupRunning);
console.log(JSON.stringify({
updateRunning,
updateDownloading,
updateInstalling,
updateProgress,
backupRunning,
backupState: backupStateValue,
systemBusy,
}, null, 2));
// ✅ Flow outcome comes from this return:
return systemBusy;