Interface CompanionActionDefinition

The definition of an action

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

Properties

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

Called to execute the action

description?: string

Additional description of the action

learn?: ((action: CompanionActionEvent, context: CompanionCommonCallbackContext) => 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

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

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

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

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