import { AnyString } from '../../../utils/types'; import IPostMessage from '../../IPostMessage'; import { IProprietaryTimer, ProprietaryTimerType } from '../helpers/ProprietaryTimerHelper'; import { ITimer, TimerType } from '../helpers/TimerHelper'; import IPower, { IScheduledRebootAction, IScheduledRebootRule, ShortWeekdayType } from './IPower'; /** * The `sos.management.power` API groups together methods related to the power state of the device. Such as rebooting, shutting down, * setting timers. * *
* Power Management Capabilities * | Capability | Description | * |:------------|:-------------| * | `SYSTEM_REBOOT` | If device supports system reboot power action | * | `APP_RESTART` | If device supports app restart power action | * | `TIMERS_PROPRIETARY` | If device supports proprietary timers | * | `TIMERS_NATIVE` | If device supports native timers | * | `SCHEDULE_POWER_ACTION` | If device supports scheduled power actions | * * If you want to check if the device supports those capabilities, use [`sos.management.supports()`](https://developers.signageos.io/sdk/sos_management/#supports). *
*/ export default class Power implements IPower { private messagePrefix; private postMessage; /** @internal */ constructor(messagePrefix: string, postMessage: IPostMessage); /** * The `systemReboot()` method initializes a system reboot. * * @returns {Promise} Resolves when the system reboot is initiated. * @since 3.0.0 * * @example // {@link https://github.com/signageos/applet-examples/tree/master/examples/management-js-api/system-reboot | Applet Example for System Reboot} * * @example * await sos.management.power.systemReboot(); */ systemReboot(): Promise; /** * The `appRestart()` method initializes a restart of the signageOS app. * * @returns {Promise} Resolves when the app restart is initiated. * @since 3.0.0 * * @example * await sos.management.power.appRestart(); */ appRestart(): Promise; /** * The `getTimers()` method returns a list of currently set native timers. * * @returns {Promise} Resolves with an array of timers. * @since 4.0.0 * * @example * await sos.management.power.getTimers(); */ getTimers(): Promise; /** * The `setTimer()` method creates or updates a native timer. * * @param type The type of the timer (`TIMER_1`, ..., `TIMER_7`). * @param timeOn The time when the device should turn on. * @param timeOff The time when the device should turn off. * @param {ShortWeekdayType} weekdays The days of the week when the timer should be active (`mon`, ..., `sun`). * @param volume The volume level set when the device is turned on. * @return {Promise} Resolves when the timer is set. * @throws {Error} If the timer type is invalid. * @throws {Error} If the time format is incorrect. * @throws {Error} If the weekdays array contains an invalid weekday. * @throws {Error} If the `volume` parameter is not a number between 0 and 100. * @throws {Error} If the `timeOn` or `timeOff` parameters do not match the expected time format (`HH:mm:ss`). * @throws {Error} If the `weekdays` parameter is not an array of strings. * @throws {Error} If the `type` parameter is not a valid timer type (e.g., `TIMER_1`, `TIMER_2`, ..., `TIMER_7`). * @since 3.0.0 * * @example // {@link https://github.com/signageos/applet-examples/tree/master/examples/management-js-api/timer | Applet Example for Native Timers} * * @example * await sos.management.power.setTimer("TIMER_1", "08:00:00", "22:00:00", ["mon", "tue", "wed", "thu", "fri", "sat", "sun"], 30); */ setTimer(type: keyof typeof TimerType, timeOn: string | null, timeOff: string | null, weekdays: (ShortWeekdayType | AnyString)[], // TODO: remove AnyString in the next major release volume: number): Promise; /** * The `unsetTimer()` method removes the specified native timer. * * @param type The type of the timer (`TIMER_1`, ..., `TIMER_7`). * @returns {Promise} Resolves when the timer is removed. * @throws {Error} If the timer type is invalid. * @since 4.0.0 * * @example * await sos.management.power.unsetTimer("TIMER_2"); */ unsetTimer(type: keyof typeof TimerType): Promise; /** * The `getProprietaryTimers()` method returns a list of currently set * [proprietary timers](https://docs.signageos.io/hc/en-us/articles/4416384202642-Timers#h_01HCD14GEDP96AZV58NRSN2HNQ). * * @returns {Promise} Resolves with an array of proprietary timers. * @throws {Error} If the timers cannot be retrieved. * @since 5.10.0 * * @example * const timers = await sos.management.power.getProprietaryTimers(); */ getProprietaryTimers(): Promise; /** * The `setProprietaryTimer()` method creates or updates a * [proprietary timer](https://docs.signageos.io/hc/en-us/articles/4416384202642-Timers#h_01HCD14GEDP96AZV58NRSN2HNQ). * * @param type The type of the timer (`TIMER_1`, ..., `TIMER_7`). * @param timeOn The time when the device should turn on. * @param timeOff The time when the device should turn off. * @param weekdays The days of the week when the timer should be active (`mon`, ..., `sun`). * @param keepAppletRunning If `true`, the applet will be kept running when the timer is active on certain devices. * @return {Promise} Resolves when the proprietary timer is set. * @throws {Error} If the timer type is invalid or if the time format is incorrect. * @throws {Error} If the weekdays array contains an invalid weekday. * @throws {Error} If the `keepAppletRunning` parameter is not a boolean. * @throws {Error} If the `timeOn` or `timeOff` parameters do not match the expected time format (`HH:mm:ss`). * @throws {Error} If the `weekdays` parameter is not an array of strings. * @throws {Error} If the `weekdays` array contains an invalid weekday. * @throws {Error} If the `timeOn` or `timeOff` parameters do not match the expected time format (`HH:mm:ss`). * @throws {Error} If the `type` parameter is not a valid timer type (e.g., `TIMER_1`, `TIMER_2`, ..., `TIMER_7`). * @since 5.10.0 * * @example * await sos.management.power.setProprietaryTimer("TIMER_2", "08:00:00", "22:00:00", ["mon", "tue", "wed", "thu", "fri", "sat", "sun"], false); */ setProprietaryTimer(type: ProprietaryTimerType, timeOn: string | null, timeOff: string | null, weekdays: (ShortWeekdayType | AnyString)[], // TODO: remove AnyString in the next major release keepAppletRunning?: boolean): Promise; /** * The `unsetProprietaryTimer()` method removes the specified * [proprietary timer](https://docs.signageos.io/hc/en-us/articles/4416384202642-Timers#h_01HCD14GEDP96AZV58NRSN2HNQ). * * @param type The type of the timer (`TIMER_1`, ..., `TIMER_7`). * @returns {Promise} Resolves when the proprietary timer is removed. * @throws {Error} If the timer type is invalid. * @since 5.10.0 * * @example * await sos.management.power.unsetProprietaryTimer("TIMER_2"); */ unsetProprietaryTimer(type: ProprietaryTimerType): Promise; /** * Removes all scheduled reboot rules from the device. * * @returns {Promise} Resolves when all scheduled reboots are cleared. * @since 8.1.0 * * @example * await sos.management.power.clearScheduledReboots(); */ clearScheduledReboots(): Promise; /** * Returns all scheduled reboot rules on the device set by the `setScheduledReboot()` method. * * @returns {Promise} Resolves with an array of scheduled reboot actions. * @since 8.1.0 * * @example * await sos.management.power.getScheduledReboots(); */ getScheduledReboots(): Promise[]>; /** * Removes scheduled reboot rule from the device (if it exists). * @param id {string} ID of the rule to be removed. * @throws {Error} If the `id` is not a string or is empty. * @returns {Promise} Resolves when the scheduled reboot is removed. * @since 8.1.0 * * @example * // Get scheduled reboots * const scheduledReboots = await sos.management.power.getScheduledReboots(); * * // Remove scheduled reboot on the first position * await sos.management.power.removeScheduledReboot(scheduledReboots[0].id); */ removeScheduledReboot(id: string): Promise; /** * Schedule an automatic reboot on the device. Calling this function will create one rule. * It is possible to set multiple rules, which can be later obtained by the `getScheduledReboots` function. * * :::note * - Setting a new scheduled reboot on the device might take up to 10 minutes to show in the Box. * - Every new scheduled reboot rule gets a unique identifier generated by the device, which might be later returned by `getScheduledReboots()`. * ::: * * @param weekdays {@link WeekdayType[]} Array of weekdays when the reboot should be executed. * @param time {string} Time when the reboot should be executed. Format is `HH:mm:ss`. * @throws {Error} If the `weekdays` parameter is not an array of strings. * @throws {Error} If the `time` parameter does not match the expected time format (`HH:mm:ss`). * @throws {Error} If the `weekdays` array contains an invalid weekday. * @throws {Error} If the `time` parameter is not a string or does not match the expected format (`HH:mm:ss`). * @throws {Error} If the `weekdays` array is empty or contains invalid values. * @returns {Promise} Resolves when the scheduled reboot is set. * @since 8.1.0 * * @example * // Schedule reboot every Monday at 3:00 AM * await sos.management.power.setScheduledReboot(["MONDAY"], "03:00:00"); * * // Schedule reboot every Monday and Friday at 7:30 PM / 19:30 * await sos.management.power.setScheduledReboot(["MONDAY", "FRIDAY"], "19:30:00"); */ setScheduledReboot(weekdays: (ShortWeekdayType | AnyString)[], // TODO: remove AnyString in the next major release time: string): Promise; private getMessage; }