Interface CompanionActionDefinition

The definition of an action

interface CompanionActionDefinition {
    callback: (
        action: CompanionActionEvent,
        context: CompanionActionContext,
    ) => void | Promise<void>;
    description?: string;
    learn?: (
        action: CompanionActionEvent,
        context: CompanionActionContext,
    ) =>
        | undefined
        | CompanionOptionValues
        | Promise<undefined | CompanionOptionValues>;
    learnTimeout?: number;
    name: string;
    options: SomeCompanionActionInputField[];
    optionsToIgnoreForSubscribe?: string[];
    skipUnsubscribeOnOptionsChange?: boolean;
    subscribe?: (
        action: CompanionActionInfo,
        context: CompanionActionContext,
    ) => void | Promise<void>;
    unsubscribe?: (
        action: CompanionActionInfo,
        context: CompanionActionContext,
    ) => void | Promise<void>;
}

Properties

callback: (
    action: CompanionActionEvent,
    context: CompanionActionContext,
) => void | Promise<void>

Called to execute the action

description?: string

Additional description of the action

learn?: (
    action: CompanionActionEvent,
    context: CompanionActionContext,
) =>
    | undefined
    | CompanionOptionValues
    | Promise<undefined | CompanionOptionValues>

The user requested to 'learn' the values for this action.

learnTimeout?: number

Timeout for the 'learn' function (in milliseconds) Companion sets a default value of 5s, to ensure that the learn does not get stuck never completing You can change this if this number does not work for you, but you should keep it to a sensible value

name: string

Name to show in the actions list

The input fields for the action

optionsToIgnoreForSubscribe?: string[]

Ignore changes to certain options and don't allow them to trigger the subscribe/unsubscribe callbacks This allows for ensuring that the subscribe callback is only called when values the action cares about change

skipUnsubscribeOnOptionsChange?: boolean

If true, the unsubscribe callback will not be called when the options change, only when the action is removed or disabled

subscribe?: (
    action: CompanionActionInfo,
    context: CompanionActionContext,
) => void | Promise<void>

Called to report the existence of an action Useful to ensure necessary data is loaded

unsubscribe?: (
    action: CompanionActionInfo,
    context: CompanionActionContext,
) => void | Promise<void>

Called to report an action has been edited/removed Useful to cleanup subscriptions setup in subscribe