The NozzleModel provides the availability of pourables that are associated with the nozzle.

Its primary purpose is to provide a mechanism for selecting from available pourables and initiating a pour.

It is possible for a dispenser to have multiple asymmetrical nozzles. For example, a dispenser may have a nozzle that is used for dispensing a syrups and flavors and another that is just dispensing water.

The NozzleModel is a IKosDataModel and is registered with the model registry using the Nozzle type.

See

Lifecycle

Load

During the load phase of the model lifecycle, the set of Availability nodes will be retrieved for the nozzle. The nodes will be indexed based on the defined groupId for the node. The groupId is defined in the dispenser beverage graph and is used to group availability nodes.

Extension Points

The load lifecycle hook will first call into the ExtensionType.AvailabilityLoader extension point in order to establish the context that will be used to populate the availability nodes.

The load lifecycle hook will then call into the ExtensionType.AvailabilityMapper for each Availability node that is retrieved. The extension point will be called the the Availability context data and the NozzleServices.BeverageResponse for the availability node.

interface NozzleModel {
    id: string;
    setSelectedBrand(brand?): void;
    setSelectedPourable(pourable): Promise<void>;
    getGroupAvailabilityItems<D>(groupId): AvailabilityModel<D, Record<string, any>>[];
    getAvailabilityByParent<D>(parentId): AvailabilityModel<D, Record<string, any>>[];
    handlePouringStart(): void;
    onFutureUpdate(future): void;
    pour(tracker?): Promise<void>;
    fixedPour(name, tracker?): Promise<void>;
    cancelPour(): Promise<void>;
    currentState: PourState;
    isFsmInitialized: boolean;
    isTransitioning: boolean;
    allowedTransitions: PourEvent[];
    transition(event): void;
    canTransition(event): boolean;
    isInState(state): boolean;
    stateHistory?: {
        state: PourState;
        timestamp: Date;
        event?: PourEvent;
    }[];
}

Properties

id: string

the unique identifier for this nozzle.

currentState: PourState

Current state of the state machine. Observable property that updates automatically via @kosModel. Always initialized to the initial state immediately.

isFsmInitialized: boolean

Indicates whether the state machine has been initialized. FSM initializes at the configured lifecycle phase (READY, ACTIVATE, etc.).

  • Before initialization: false, currentState === undefined
  • After initialization: true, currentState === initial
isTransitioning: boolean

Indicates whether a state transition is currently in progress. Observable property that updates during transitions.

allowedTransitions: PourEvent[]

Computed array of valid events that can be triggered from the current state. Updates automatically when state changes. Returns empty array if FSM is not initialized.

stateHistory?: {
    state: PourState;
    timestamp: Date;
    event?: PourEvent;
}[]

History of state transitions (if trackHistory is enabled). Each entry contains the state, timestamp, and optional event that caused the transition.

Only available when trackHistory: true is set in options.

Type declaration

  • state: PourState
  • timestamp: Date
  • Optional event?: PourEvent

Methods

  • -------------------LIFECYCLE----------------------------

    Parameters

    Returns void

  • Set the values used to determine the selected pourable for this nozzle.

    Parameters

    Returns Promise<void>

  • Utility method that will return the availability nodes that belong to the specified group as defined in the dispenser beverage graph. For example, a dispenser implementation may group availability nodes by Brand, Beverage, or Flavors

    Type Parameters

    • D extends object = any

    Parameters

    • groupId: string

      The group to filter by.

    Returns AvailabilityModel<D, Record<string, any>>[]

    The availability nodes that are available to be dispensed from this nozzle and are in the specified group.

  • Utility method that will return the availability nodes that are tagged with the specified parent id.

    This is useful when brandsets use the taggedIds property to associate nodes with a parent node. For example, when organizing a brandset into brands and beverages, the brand nodes will be tagged with the beverage nodes.

    Type Parameters

    • D extends object = any

    Parameters

    • parentId: string

      The parent id to filter by.

    Returns AvailabilityModel<D, Record<string, any>>[]

    the availability nodes that are tagged with the specified parent id.

  • An action that will initiate a pour for this nozzle.

    The invocation of this action will result in a Future being returned that will provide the status of the pour and return any errors that may occur.

    Parameters

    • Optional tracker: string

    Returns Promise<void>

    See

    kosFuture

  • An action that will initiate a fixed volume pour for this nozzle using the specified pourable volume name.

    The invocation of this action will result in a Future being returned that will provide the status of the pour and return any errors that may occur.

    Parameters

    • name: string
    • Optional tracker: string

    Returns Promise<void>

    See

    kosFuture

  • An action that will cancel a pour for this nozzle.

    Returns Promise<void>

  • Trigger a state transition by event.

    Parameters

    • event: PourEvent

      The event to trigger

    Returns void

    Throws

    Error if FSM not initialized (unless throwOnInvalid is false)

    Throws

    Error if transition is invalid (unless throwOnInvalid is false)

    Example

    this.transition('START'); // idle -> active
    this.transition('STOP'); // active -> idle
  • Check if a transition is valid from the current state. Returns false if FSM is not initialized.

    Parameters

    • event: PourEvent

      The event to check

    Returns boolean

    true if the transition is valid, false otherwise

    Example

    if (this.canTransition('START')) {
    this.transition('START');
    }
  • Check if the state machine is currently in a specific state. Returns false if FSM is not initialized.

    Parameters

    • state: PourState

      The state to check

    Returns boolean

    true if currently in the specified state, false otherwise

    Example

    if (this.isInState('idle')) {
    console.log('System is idle');
    }