Class HomeyIntervalManager<T>

Manages intervals for a given Homey device, allowing for starting, stopping, and restarting intervals based on configuration and device settings. This is useful for cases like when you need an OAuth2Device that polls multiple API endpoints in the background.

Type Parameters

Constructors

Properties

defaultIntervalSeconds: number

Methods

  • Clears an active interval associated with the given key. The key must be that used in the IntervalConfigurationCollection.

    Parameters

    • key: string

      The unique key representing the interval to clear.

    Returns Promise<void>

    A promise that resolves once the interval has been cleared.

  • Checks if a given key is active.

    Parameters

    • key: string

      The key to check.

    Returns boolean

    Returns true if active, otherwise false.

  • Restarts the services or processes identified by the given keys.

    Parameters

    • Rest...keys: string[]

      The keys identifying the services or processes to restart.

    Returns Promise<void>

    • A promise that resolves when the restart operation is complete.
  • Restarts intervals that have been configured with the provided function names.

    Parameters

    • Rest...functionNames: (keyof T & string)[]

      The names of the functions to restart intervals for.

    Returns Promise<void>

    A promise that resolves when the restart process is complete.

  • Restarts intervals that have been configured with the provided setting names. This is useful for use with Device.onSettings.

    Parameters

    • Rest...settingNames: (undefined | (T extends Device
          ? string
          : undefined))[] & string[]

      The names of the settings to restart the system by.

    Returns Promise<void>

    • A promise that resolves when the restart operation is complete.
    async onSettings(event) {
    // ... your normal event handling

    // trigger this a second later to allow homey to persist the new configurations after this method ends
    this.homey.setTimeout(async () => {
    await this.intervalManager.restartBySettings(...event.changedKeys);
    }, 1000);
    }
  • Sets an interval identified by the given key and starts it. The key must be that used in the IntervalConfigurationCollection.

    Parameters

    • key: string

      The identifier for the interval to be set and started.

    Returns Promise<void>

    A promise that resolves once the interval has been started.

  • Starts the specified intervals (by keys) or all managed intervals if no keys are provided.

    Parameters

    • Rest...keys: string[]

      The interval keys to start. If no keys are provided, all managed intervals are started.

    Returns Promise<void>

    A promise that resolves when the intervals have been started.

  • Stops the intervals associated with the provided keys. If no keys are provided, all managed intervals are cleared.

    Parameters

    • Rest...keys: string[]

      The keys for intervals that need to be stopped. If no keys are provided, all managed intervals will be stopped.

    Returns Promise<void>

    A promise that resolves when the intervals have been cleared.