@espressif/rainmaker-base-cdf
    Preparing search index...

    SceneStore - Manages scene operations and state for ESP Rainmaker CDF

    This store handles all scene-related operations including:

    • Scene CRUD operations (Create, Read, Update, Delete)
    • Scene transformation from node configurations
    • Scene activation and synchronization
    • Payload generation for scene operations
    • Interceptor patterns for scene actions

    SceneStore

    Indexable

    • [key: string]: any

      Index signature for dynamic property access

    Index

    Constructors

    Properties

    afterSetSceneListHook: (scenes: default[]) => void = ...

    Hook called after setting scene list - for customization

    beforeSetSceneListHook: (scenes: default[]) => void = ...

    Hook called before setting scene list - for customization

    Accessors

    _scenesByID: any

    Observable map of scenes indexed by scene ID

    Methods

    • Activates multiple scenes concurrently

      This method activates multiple scenes in parallel using Promise.all.

      Parameters

      • sceneIds: string[]

        Array of scene IDs to activate

      Returns Promise<void>

      If any scene activation fails

      await sceneStore.activateMultipleScenes(['scene1', 'scene2', 'scene3']);
      
    • Activates a scene by triggering its action

      This method finds the scene by ID and calls its trigger method, which will activate the scene across all its associated nodes.

      Parameters

      • sceneId: string

        The ID of the scene to activate

      Returns Promise<void>

      If scene is not found or activation fails

      await sceneStore.activateScene('scene123');
      
    • Dynamically adds an observable property to the store

      This method adds a new observable property to the store and automatically creates getter and setter methods for it. The property name is capitalized for the getter/setter methods.

      Parameters

      • propertyName: string

        The name of the property to add

      • initialValue: any

        The initial value for the property

      Returns void

      sceneStore.addProperty('customField', 'initial value');
      sceneStore.setCustomField('new value');
    • Adds a single scene to the store

      Parameters

      Returns default

      The observable scene object

      const scene = sceneStore.addScene({
      id: 'scene123',
      name: 'New Scene',
      nodes: [],
      config: {}
      });
    • Clears all scenes and resets hooks to default values

      This method removes all scenes from the store and resets the beforeSetSceneListHook and afterSetSceneListHook to empty functions.

      Returns void

      sceneStore.clear();
      
    • Creates a new scene in the store

      This method creates a new scene with the provided data, makes it observable, and sets up interceptors for its operations. If no ID is provided, a timestamp-based ID is generated.

      Parameters

      • sceneData: Partial<default>

        Scene data to create

      Returns Promise<default>

      The created scene object

      If scene creation fails

      const newScene = await sceneStore.createScene({
      name: 'Living Room Scene',
      info: 'Cozy evening lighting',
      nodes: ['node1', 'node2'],
      config: { 'node1': { light: { power: true } } }
      });
    • Deletes multiple scenes by their IDs

      Parameters

      • ids: string[]

        Array of scene IDs to delete

      Returns void

      sceneStore.deleteScenes(['scene1', 'scene2', 'scene3']);
      
    • Retrieves a scene by its ID

      Parameters

      • sceneId: string

        The ID of the scene to retrieve

      Returns null | default

      The scene object or null if not found

      const scene = sceneStore.getScene('scene123');
      
    • Sets the entire scene list, replacing all existing scenes

      This method replaces all scenes in the store with the provided array. Each scene is made observable and has interceptors set up.

      Parameters

      • scenes: default[]

        Array of scenes to set

      Returns void

      sceneStore.setSceneList([
      { id: 'scene1', name: 'Scene 1', nodes: [], config: {} },
      { id: 'scene2', name: 'Scene 2', nodes: [], config: {} }
      ]);
    • Synchronizes scenes from specified nodes

      This action method:

      1. Clears existing scenes from the store
      2. Fetches scene configurations from specified nodes
      3. Transforms node configurations into Scene instances
      4. Updates the store with synchronized scenes

      Parameters

      • nodeIds: string[]

        Array of node IDs to sync scenes from

      Returns Promise<void>

      If synchronization fails

    • Updates a scene by ID without making it observable

      Parameters

      • id: string

        The scene ID

      • scene: default

        The scene object to set

      Returns void

      sceneStore.updateSceneByID('scene123', updatedScene);