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

    ScheduleStore - Manages schedule operations and state for ESP Rainmaker CDF

    This store is responsible for managing schedules across multiple nodes in the ESP Rainmaker system. It provides a centralized way to handle schedule operations, state management, and node synchronization.

    Key Features:

    • Schedule CRUD operations (Create, Read, Update, Delete)
    • Schedule enable/disable functionality
    • Schedule transformation and payload generation
    • Node-specific schedule operations
    • Out-of-sync detection and metadata management
    • MobX-powered state management

    ScheduleStore

    Indexable

    • [key: string]: any

      Index signature for dynamic property access

    Index

    Constructors

    Properties

    afterSetScheduleListHook: (schedules: default[]) => void = ...

    Hook called after setting schedule list - for customization

    beforeSetScheduleListHook: (schedules: default[]) => void = ...

    Hook called before setting schedule list - for customization

    Accessors

    _schedulesByID: any

    Observable map of schedules indexed by schedule ID

    • get scheduleList(): default[]

      Returns an array of all schedules in the store This computed property provides a reactive list view of all schedules

      Returns default[]

      Array of all schedules in the store

    • get schedulesByID(): { [key: string]: default }

      Provides access to the schedule map indexed by schedule IDs This computed property ensures reactive access to the schedule store

      Returns { [key: string]: default }

      Map of schedules indexed by their IDs

    • set schedulesByID(value: { [key: string]: default }): void

      Setter for schedules indexed by ID

      Parameters

      • value: { [key: string]: default }

        Map of schedules to set

      Returns void

    Methods

    • 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');
    • 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 schedule with the provided configuration

      This action method:

      1. Generates a unique schedule ID if not provided
      2. Sets default values for optional parameters
      3. Creates an observable Schedule instance
      4. Adds the schedule to the store
      5. Triggers the schedule creation on the device

      Parameters

      • scheduleData: Partial<default>

        Partial schedule configuration

      Returns Promise<default>

      Created and initialized schedule instance

      If schedule creation fails

      // Create a daily morning schedule
      const schedule = await scheduleStore.createSchedule({
      name: 'Morning Routine',
      nodes: ['bedroom_light', 'kitchen_light'],
      action: {
      bedroom_light: { light: { power: true, brightness: 60 } },
      kitchen_light: { light: { power: true, brightness: 100 } }
      },
      triggers: [{ m: 420, d: 127 }], // 7:00 AM every day
      info: 'Automated morning lighting'
      });
    • Disable a schedule by its ID

      Parameters

      • scheduleId: string

        The ID of the schedule to disable

      Returns Promise<void>

      If schedule is not found or disabling fails

    • Enables a schedule by its ID

      This action method activates a schedule, allowing it to execute according to its triggers. The change is synchronized across all nodes associated with the schedule.

      Parameters

      • scheduleId: string

        ID of the schedule to enable

      Returns Promise<void>

      If schedule is not found or enabling fails

    • Determines if a schedule's configuration is synchronized with given schedule data This method performs deep comparison of schedule properties to detect any differences

      Parameters

      • existingSchedule: default

        The existing schedule instance to compare

      • scheduleData: any

        New schedule data to compare against

      • keys: string[]

        Array of property keys to compare (e.g., ['name', 'enabled', 'triggers'])

      Returns { isInSync: boolean; meta?: Record<string, any> }

      Sync status and any out-of-sync metadata

      // Check if schedule is in sync
      const { isInSync, meta } = scheduleStore.isScheduleInSync(
      existingSchedule,
      newScheduleData,
      ['name', 'enabled', 'triggers']
      );

      if (!isInSync) {
      console.log('Out of sync properties:', meta);
      // Handle out of sync state
      existingSchedule.addOutOfSyncMeta(nodeId, meta);
      }
      • Performs deep comparison for arrays and objects
      • Returns metadata about which properties are out of sync
      • Used internally during node synchronization
    • Synchronizes schedules from specified nodes

      This action method:

      1. Clears existing schedules from the store
      2. Fetches schedule configurations from specified nodes
      3. Transforms node configurations into Schedule instances
      4. Detects and handles out-of-sync configurations
      5. Updates the store with synchronized schedules

      Parameters

      • nodeIds: string[]

        Array of node IDs to sync schedules from

      Returns Promise<void>

      If synchronization fails