Skip to content

Commit

Permalink
Tweak sleep mode trigger for shutdown sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphiiko committed Aug 15, 2024
1 parent 91d348c commit 03cc296
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src-ui/app/services/shutdown-automations.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,23 +199,26 @@ export class ShutdownAutomationsService {
private async handleTriggerOnSleep() {
interval(1000)
.pipe(
filter(() => this._stage.value === 'IDLE'),
// Only trigger if this trigger is enabled
filter(() => this.config.triggersEnabled),
filter(() => this.config.triggerOnSleep),
// Only trigger if the shutdown sequence isn't running
filter(() => this._stage.value === 'IDLE'),
// Only trigger if the sleep mode is active
filter(() => this.sleepMode),
// Only trigger if we haven't already triggered this sleep (resets once sleep mode disables)
filter(() => !this.triggeredThisSleep),
// Only trigger if the sleep mode has been active for long enough
filter(() => Date.now() - this.sleepModeLastSet >= this.config.triggerOnSleepDuration),
// Only trigger if we're in the activation window, if it's configured
filter(
() =>
!this.config.triggerOnSleepActivationWindow ||
this.isInActivationWindow(
this.config.triggerOnSleepActivationWindowStart,
this.config.triggerOnSleepActivationWindowEnd
)
),
// Only trigger once every 5 minutes at most
throttleTime(300000, asyncScheduler, { leading: true, trailing: false })
)
)
.subscribe(() => {
this.triggeredThisSleep = true;
Expand Down

0 comments on commit 03cc296

Please sign in to comment.