Schedule Store
The ScheduleStore manages scheduling operations and schedule management within your application. Schedules allow you to automate device actions based on time-based triggers, enabling devices to perform actions at specific times or intervals.
Overview
The ScheduleStore provides:
- Schedule list management and synchronization
- Schedule creation and updates
- Schedule enable/disable functionality
- Automatic transformation from node configurations
- Multi-node schedule combination
- Out-of-sync detection and handling
- Automatic synchronization with NodeStore
- Reactive state management
How Schedules Work in CDF
Schedule Transformation from Node Configurations
Schedules in CDF are automatically transformed from node configurations. Each node's nodeConfig.services contains a schedules service, which includes a list of schedules. The ScheduleStore automatically extracts and combines these schedules.
No manual transformation needed - When using CDF, schedules are automatically transformed from:
node.nodeConfig.services[schedules].params[schedules].value
Identifying Schedule Service and Parameters
The ScheduleStore identifies schedules using specific service and parameter types:
-
Service Type:
esp.service.schedules(ESPRM_SERVICE_SCHEDULES)- Identifies the schedules service within a node's services array
- Found in
node.nodeConfig.services[]whereservice.type === "esp.service.schedules"
-
Parameter Type:
esp.param.schedules(ESPRM_PARAM_SCHEDULES)- Identifies the schedules parameter within the schedules service
- Found in
service.params[]whereparam.type === "esp.param.schedules" - Contains the actual schedule list in
param.value[]
Example Node Configuration Structure:
node.nodeConfig.services = [
{
type: "esp.service.schedules", // Service type identifier
params: [
{
type: "esp.param.schedules", // Parameter type identifier
value: [
// Array of schedules
{
id: "schedule1",
name: "Morning Routine",
info: "Wake up schedule",
action: { light: { power: true, brightness: 80 } },
triggers: [{ m: 420, d: 127 }], // 7:00 AM daily
enabled: true,
},
{
id: "schedule2",
name: "Evening Routine",
action: { fan: { power: false } },
triggers: [{ m: 1200, d: 127 }], // 8:00 PM daily
enabled: false,
},
],
},
],
},
];
Multi-Node Schedule Combination
Schedules with the same ID across multiple nodes are automatically combined into a single schedule. This allows you to manage schedules that span multiple devices.
Example:
- Node 1 has schedule with ID
schedule1→{ id: 'schedule1', nodes: ['node1'], action: { node1: {...} } } - Node 2 has schedule with ID
schedule1→ Combined with Node 1's schedule - Node 3 has schedule with ID
schedule1→ Combined with Node 1 and Node 2's schedule - Result:
{ id: 'schedule1', nodes: ['node1', 'node2', 'node3'], action: { node1: {...}, node2: {...}, node3: {...} } }
When multiple nodes share the same schedule ID, they are merged into one schedule object. You can check the nodes array property of a schedule to see which nodes it spans:
const schedule = scheduleStore.getSchedule("schedule1");
console.log("Schedule spans nodes:", schedule.nodes); // ['node1', 'node2', 'node3']
console.log("Actions per node:", schedule.action);
// {
// node1: { light: { power: true } },
// node2: { fan: { power: false } },
// node3: { switch: { power: true } }
// }
Out-of-Sync Detection
The ScheduleStore automatically detects when schedules are out of sync across nodes. If a schedule with the same ID exists on multiple nodes but has different properties (name, enabled, triggers, validity, flags, info), the store tracks this using outOfSyncMeta.
const schedule = scheduleStore.getSchedule("schedule1");
if (schedule.outOfSyncMeta && Object.keys(schedule.outOfSyncMeta).length > 0) {
console.log("Schedule is out of sync on nodes:", schedule.outOfSyncMeta);
// Example: { node2: { name: 'Different Name', enabled: false } }
}