lumia-plugin 0.1.12 → 0.1.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "lumia-plugin",
3
- "version": "0.1.12",
3
+ "version": "0.1.16",
4
4
  "description": "Command-line tools for creating, building, and validating Lumia Stream plugins.",
5
5
  "bin": {
6
6
  "lumia-plugin": "scripts/cli.js"
7
7
  },
8
8
  "files": [
9
9
  "scripts",
10
- "examples/base-plugin",
10
+ "examples/base_plugin",
11
11
  "README.md",
12
12
  "LICENSE"
13
13
  ],
@@ -20,7 +20,7 @@
20
20
  "author": "Lumia Stream",
21
21
  "license": "MIT",
22
22
  "dependencies": {
23
- "@lumiastream/plugin": "^0.1.12",
23
+ "@lumiastream/plugin": "^0.1.16",
24
24
  "jszip": "3.10.1"
25
25
  }
26
26
  }
@@ -2,7 +2,7 @@
2
2
  const path = require("path");
3
3
  const fs = require("fs");
4
4
 
5
- const TEMPLATE_DIR = path.resolve(__dirname, "..", "examples", "base-plugin");
5
+ const TEMPLATE_DIR = path.resolve(__dirname, "..", "examples", "base_plugin");
6
6
 
7
7
  function toSafeId(value) {
8
8
  const cleaned = value
@@ -1,243 +0,0 @@
1
- # Getting Started with Showcase Plugin Template
2
-
3
- Welcome to your new Lumia Stream plugin! This guide will help you understand the plugin structure and start building your custom functionality.
4
-
5
- ## Project Structure
6
-
7
- ```
8
- your-plugin/
9
- ├── manifest.json # Plugin metadata and configuration
10
- ├── main.js # Your plugin's main code
11
- ├── package.json # npm dependencies (optional)
12
- └── README.md # Plugin documentation
13
- ```
14
-
15
- ## Understanding the Files
16
-
17
- ### 📋 manifest.json
18
-
19
- This file defines your plugin's metadata and capabilities:
20
-
21
- - **id**: Unique identifier using letters, numbers, or underscores (e.g., "my_awesome_plugin")
22
- - **name**: Display name shown to users
23
- - **description**: Short description for the plugin marketplace
24
- - **main**: Entry point file (usually "main.js")
25
- - **config**: Defines settings, actions, and variables
26
-
27
- **Key sections:**
28
- - `settings`: User-configurable options for your plugin
29
- - `actions`: Functions users can trigger (e.g., send a message, change color)
30
- - `variables`: Data your plugin exposes to Lumia Stream
31
-
32
- ### 🔧 main.js
33
-
34
- Your plugin's logic lives here. The main class extends the `Plugin` base class:
35
-
36
- ```javascript
37
- class YourPlugin extends Plugin {
38
- constructor(props) {
39
- super(props);
40
- // Initialize your plugin
41
- }
42
-
43
- async onload() {
44
- // Called when plugin is loaded
45
- }
46
-
47
- async onsettingsupdate() {
48
- // Called when settings change
49
- }
50
-
51
- async onunload() {
52
- // Called when plugin is unloaded
53
- }
54
- }
55
- ```
56
-
57
- ## Common Tasks
58
-
59
- ### Adding a New Setting
60
-
61
- 1. Edit `manifest.json` in the `config.settings` array:
62
-
63
- ```json
64
- {
65
- "key": "myNewSetting",
66
- "label": "My New Setting",
67
- "type": "text",
68
- "defaultValue": "default value",
69
- "required": false
70
- }
71
- ```
72
-
73
- 2. Access in `main.js`:
74
-
75
- ```javascript
76
- const value = this.getSetting('myNewSetting');
77
- ```
78
-
79
- ### Adding a New Action
80
-
81
- 1. Define in `manifest.json` under `config.actions`:
82
-
83
- ```json
84
- {
85
- "type": "my_custom_action",
86
- "label": "Do Something Cool",
87
- "fields": [
88
- {
89
- "key": "message",
90
- "label": "Message",
91
- "type": "text",
92
- "required": true
93
- }
94
- ]
95
- }
96
- ```
97
-
98
- 2. Handle in `main.js`:
99
-
100
- ```javascript
101
- async onAction(action) {
102
- if (action.type === 'my_custom_action') {
103
- const message = action.fields.message;
104
- // Your logic here
105
- }
106
- }
107
- ```
108
-
109
- ### Creating Variables
110
-
111
- Variables let other Lumia features access your plugin's data:
112
-
113
- 1. Define in `manifest.json` under `config.variables`:
114
-
115
- ```json
116
- {
117
- "name": "my_variable",
118
- "key": "myVariable",
119
- "origin": "your_plugin_id",
120
- "type": "string",
121
- "example": "Sample value"
122
- }
123
- ```
124
-
125
- 2. Update in `main.js`:
126
-
127
- ```javascript
128
- this.setVariable('myVariable', 'new value');
129
- ```
130
-
131
- ## Testing Your Plugin
132
-
133
- 1. **Install dependencies** (if using package.json):
134
- ```bash
135
- npm install
136
- ```
137
-
138
- 2. **Load in Lumia Stream**:
139
- - Open Lumia Stream
140
- - Go to Plugins section
141
- - Load your plugin directory
142
- - Enable your plugin
143
-
144
- 3. **Check logs**:
145
- ```javascript
146
- this.log('Debug message');
147
- this.error('Error message');
148
- ```
149
-
150
- ## Next Steps
151
-
152
- - [ ] Customize `manifest.json` with your plugin details
153
- - [ ] Update the plugin name and description
154
- - [ ] Add your custom settings
155
- - [ ] Implement your actions
156
- - [ ] Test your plugin in Lumia Stream
157
- - [ ] Write tests (optional)
158
- - [ ] Update README.md with usage instructions
159
-
160
- ## API Reference
161
-
162
- ### Plugin Methods
163
-
164
- - `this.getSetting(key)` - Get a setting value
165
- - `this.setVariable(key, value)` - Update a variable
166
- - `this.log(message)` - Log info message
167
- - `this.error(message)` - Log error message
168
- - `this.sendAlert(type, data)` - Trigger an alert
169
-
170
- ### Lifecycle Hooks
171
-
172
- - `onload()` - Plugin initialization
173
- - `onunload()` - Cleanup when plugin is disabled
174
- - `onsettingsupdate()` - Respond to setting changes
175
- - `onAction(action)` - Handle triggered actions
176
-
177
- ## Common Patterns
178
-
179
- ### Making HTTP Requests
180
-
181
- ```javascript
182
- const response = await fetch('https://api.example.com/data');
183
- const data = await response.json();
184
- ```
185
-
186
- ### Using Timers
187
-
188
- ```javascript
189
- async onload() {
190
- this.interval = setInterval(() => {
191
- // Do something periodically
192
- }, 5000);
193
- }
194
-
195
- async onunload() {
196
- if (this.interval) {
197
- clearInterval(this.interval);
198
- }
199
- }
200
- ```
201
-
202
- ### Error Handling
203
-
204
- ```javascript
205
- try {
206
- // Your code
207
- } catch (error) {
208
- this.error(`Something went wrong: ${error.message}`);
209
- }
210
- ```
211
-
212
- ## Troubleshooting
213
-
214
- **Plugin not loading?**
215
- - Check manifest.json syntax (use a JSON validator)
216
- - Ensure the `main` field points to the correct file
217
- - Check Lumia Stream logs for errors
218
-
219
- **Settings not showing?**
220
- - Verify the `settings` array in manifest.json
221
- - Ensure required fields are filled
222
-
223
- **Actions not working?**
224
- - Check the action type matches your handler
225
- - Verify field keys match what you're accessing
226
-
227
- ## Resources
228
-
229
- - [Lumia Stream Documentation](https://docs.lumiastream.com)
230
- - [Plugin API Reference](https://docs.lumiastream.com/plugins/api)
231
- - [Example Plugins](https://github.com/lumiastream/plugins)
232
- - [Community Discord](https://discord.gg/lumiastream)
233
-
234
- ## Need Help?
235
-
236
- - Join the Lumia Stream Discord community
237
- - Check the documentation
238
- - Review example plugins
239
- - Ask questions in the developer channel
240
-
241
- ---
242
-
243
- Happy coding! 🚀
@@ -1,17 +0,0 @@
1
- # Showcase Plugin Template
2
-
3
- This template demonstrates a handful of common Lumia Stream plugin capabilities:
4
-
5
- - Logs lifecycle events and recent actions
6
- - Stores and updates variables that other Lumia features can consume
7
- - Responds to custom actions for logging, variable updates, and alert triggering
8
- - Triggers a sample alert effect using configurable colors and duration
9
- - Shows how to react to setting changes inside `onsettingsupdate`
10
-
11
- Use the CLI to copy and customise the template:
12
-
13
- ```
14
- npx lumia-plugin create my_plugin
15
- ```
16
-
17
- After scaffolding you can tailor the manifest, code, and README to match your idea.
@@ -1,150 +0,0 @@
1
- const { Plugin } = require("@lumiastream/plugin");
2
-
3
- const VARIABLE_NAMES = {
4
- lastMessage: "last_message",
5
- lastAlertColor: "last_alert_color",
6
- };
7
-
8
- const DEFAULTS = {
9
- welcomeMessage: "Hello from Showcase Plugin!",
10
- color: "#00c2ff",
11
- alertDuration: 5,
12
- };
13
-
14
- class ShowcasePluginTemplate extends Plugin {
15
- async onload() {
16
- const message = this._currentMessage();
17
- await this._log("Plugin loaded");
18
- await this._rememberMessage(message);
19
-
20
- if (this.settings.autoAlert === "load") {
21
- await this._triggerSampleAlert({
22
- color: this.settings.favoriteColor,
23
- duration: DEFAULTS.alertDuration,
24
- });
25
- }
26
- }
27
-
28
- async onunload() {
29
- await this._log("Plugin unloaded");
30
- }
31
-
32
- async onsettingsupdate(settings, previous = {}) {
33
- await this._log("Settings updated");
34
-
35
- if (
36
- settings?.welcomeMessage &&
37
- settings.welcomeMessage !== previous?.welcomeMessage
38
- ) {
39
- await this._rememberMessage(settings.welcomeMessage);
40
- }
41
-
42
- if (settings?.autoAlert === "load" && previous?.autoAlert !== "load") {
43
- await this._log("Auto alert configured to fire on load");
44
- }
45
- }
46
-
47
- async actions(config = {}) {
48
- const actions = Array.isArray(config.actions) ? config.actions : [];
49
- for (const action of actions) {
50
- switch (action?.type) {
51
- case "log_message":
52
- await this._handleLogMessage(action.data);
53
- break;
54
- case "update_variable":
55
- await this._handleUpdateVariable(action.data);
56
- break;
57
- case "trigger_alert":
58
- await this._triggerSampleAlert(action.data);
59
- break;
60
- default:
61
- await this._log(
62
- `Unknown action type: ${action?.type ?? "undefined"}`
63
- );
64
- }
65
- }
66
- }
67
-
68
- _tag() {
69
- return `[${this.manifest?.id ?? "showcase_plugin"}]`;
70
- }
71
-
72
- _currentMessage() {
73
- return (
74
- this.settings?.welcomeMessage ||
75
- `Hello from ${this.manifest?.name ?? "Showcase Plugin"}!`
76
- );
77
- }
78
-
79
- async _log(message, severity = "info") {
80
- const prefix = this._tag();
81
- const decorated =
82
- severity === "warn"
83
- ? `${prefix} ⚠️ ${message}`
84
- : severity === "error"
85
- ? `${prefix} ❌ ${message}`
86
- : `${prefix} ${message}`;
87
-
88
- await this.lumia.addLog(decorated);
89
- }
90
-
91
- async _rememberMessage(value) {
92
- await this.lumia.setVariable(VARIABLE_NAMES.lastMessage, value);
93
- }
94
-
95
- async _handleLogMessage(data = {}) {
96
- const message = data?.message || this._currentMessage();
97
- const severity = data?.severity || "info";
98
-
99
- await this._log(message, severity);
100
-
101
- if (typeof this.lumia.showToast === "function") {
102
- await this.lumia.showToast({
103
- message: `${this.manifest?.name ?? "Plugin"}: ${message}`,
104
- time: 4,
105
- });
106
- }
107
-
108
- if (this.settings.autoAlert === "after-log") {
109
- await this._triggerSampleAlert({
110
- color: this.settings.favoriteColor,
111
- duration: DEFAULTS.alertDuration,
112
- });
113
- }
114
- }
115
-
116
- async _handleUpdateVariable(data = {}) {
117
- const value = data?.value ?? new Date().toISOString();
118
- await this._rememberMessage(value);
119
- await this._log(`Stored variable value: ${value}`);
120
- }
121
-
122
- async _triggerSampleAlert(data = {}) {
123
- const color = data?.color || this.settings?.favoriteColor || DEFAULTS.color;
124
- const duration = Number(data?.duration) || DEFAULTS.alertDuration;
125
-
126
- try {
127
- const success = await this.lumia.triggerAlert({
128
- alert: "sample_light",
129
- extraSettings: { color, duration },
130
- });
131
-
132
- if (!success) {
133
- await this._log("Sample alert reported failure", "warn");
134
- return;
135
- }
136
-
137
- await this.lumia.setVariable(VARIABLE_NAMES.lastAlertColor, color);
138
- await this._log(
139
- `Triggered sample alert with color ${color} for ${duration}s`
140
- );
141
- } catch (error) {
142
- await this._log(
143
- `Failed to trigger sample alert: ${error.message ?? error}`,
144
- "error"
145
- );
146
- }
147
- }
148
- }
149
-
150
- module.exports = ShowcasePluginTemplate;
@@ -1,149 +0,0 @@
1
- {
2
- "id": "showcase_plugin",
3
- "name": "Showcase Plugin",
4
- "version": "1.0.0",
5
- "author": "LumiaStream",
6
- "email": "",
7
- "website": "",
8
- "repository": "",
9
- "description": "Sample plugin that demonstrates Lumia Stream logging, variables, alerts, and settings.",
10
- "license": "MIT",
11
- "lumiaVersion": "^9.0.0",
12
- "keywords": "sample, demo, lumia",
13
- "category": "examples",
14
- "icon": "",
15
- "changelog": "",
16
- "config": {
17
- "settings": [
18
- {
19
- "key": "welcomeMessage",
20
- "label": "Welcome Message",
21
- "type": "text",
22
- "defaultValue": "Hello from Showcase Plugin!",
23
- "helperText": "Shown when the plugin loads and stored in the sample variable."
24
- },
25
- {
26
- "key": "favoriteColor",
27
- "label": "Favorite Color",
28
- "type": "color",
29
- "defaultValue": "#00c2ff",
30
- "helperText": "Used when triggering the sample light alert."
31
- },
32
- {
33
- "key": "autoAlert",
34
- "label": "Trigger Sample Alert",
35
- "type": "select",
36
- "defaultValue": "never",
37
- "options": [
38
- { "label": "Never", "value": "never" },
39
- { "label": "On Load", "value": "load" },
40
- { "label": "After Log Action", "value": "after-log" }
41
- ],
42
- "helperText": "Automatically fire the sample alert at different times."
43
- }
44
- ],
45
- "actions": [
46
- {
47
- "type": "log_message",
48
- "label": "Log Message",
49
- "description": "Write a formatted message to the Lumia log panel and optionally trigger the sample alert.",
50
- "fields": [
51
- {
52
- "key": "message",
53
- "label": "Message",
54
- "type": "text",
55
- "defaultValue": "Hello from Showcase Plugin!"
56
- },
57
- {
58
- "key": "severity",
59
- "label": "Severity",
60
- "type": "select",
61
- "defaultValue": "info",
62
- "options": [
63
- { "label": "Info", "value": "info" },
64
- { "label": "Warning", "value": "warn" },
65
- { "label": "Error", "value": "error" }
66
- ]
67
- }
68
- ]
69
- },
70
- {
71
- "type": "update_variable",
72
- "label": "Update Variable",
73
- "description": "Persist a value into the sample Lumia variable.",
74
- "fields": [
75
- {
76
- "key": "value",
77
- "label": "Value",
78
- "type": "text",
79
- "defaultValue": "Triggered from an action"
80
- }
81
- ]
82
- },
83
- {
84
- "type": "trigger_alert",
85
- "label": "Trigger Sample Alert",
86
- "description": "Fire the sample alert with optional overrides.",
87
- "fields": [
88
- {
89
- "key": "color",
90
- "label": "Color",
91
- "type": "color",
92
- "defaultValue": "#ff5f5f"
93
- },
94
- {
95
- "key": "duration",
96
- "label": "Duration (seconds)",
97
- "type": "number",
98
- "defaultValue": 5,
99
- "min": 1,
100
- "max": 60
101
- }
102
- ]
103
- }
104
- ],
105
- "variables": [
106
- {
107
- "name": "last_message",
108
- "system": false,
109
- "origin": "showcase_plugin",
110
- "allowedPlaces": ["automations", "overlays"],
111
- "description": "Stores the most recent message handled by the plugin.",
112
- "value": "",
113
- "example": "Hello from Showcase Plugin!"
114
- },
115
- {
116
- "name": "last_alert_color",
117
- "system": false,
118
- "origin": "showcase_plugin",
119
- "allowedPlaces": ["automations", "overlays"],
120
- "description": "Tracks the color used by the latest sample alert.",
121
- "value": "",
122
- "example": "#00c2ff"
123
- }
124
- ],
125
- "alerts": [
126
- {
127
- "id": "sample_light",
128
- "label": "Sample Light Alert",
129
- "description": "Change lights to the selected color for a few seconds.",
130
- "fields": [
131
- {
132
- "key": "color",
133
- "label": "Color",
134
- "type": "color",
135
- "defaultValue": "#00c2ff"
136
- },
137
- {
138
- "key": "duration",
139
- "label": "Duration (seconds)",
140
- "type": "number",
141
- "defaultValue": 5,
142
- "min": 1,
143
- "max": 60
144
- }
145
- ]
146
- }
147
- ]
148
- }
149
- }
@@ -1,10 +0,0 @@
1
- {
2
- "name": "lumia-showcase-plugin-template",
3
- "version": "1.0.0",
4
- "private": true,
5
- "description": "Internal template illustrating logging, variables, actions, and alerts for Lumia Stream plugins.",
6
- "main": "main.js",
7
- "dependencies": {
8
- "@lumiastream/plugin": "^0.1.0"
9
- }
10
- }