Add live status button
This commit is contained in:
8 files changed
+201
-10
No files matched your search
@@ -2,6 +2,12 @@
|
|||||||
|
|
||||||
**A Stream Deck plugin to control your DIY [BusyLight](https://code.igox.org/iGoX/busylight) (ESP32 + MicroPython + Microdot).**
|
**A Stream Deck plugin to control your DIY [BusyLight](https://code.igox.org/iGoX/busylight) (ESP32 + MicroPython + Microdot).**
|
||||||
|
|
||||||
|
You can download the Stream Deck plugin to control your BusyLight:
|
||||||
|
|
||||||
|
[](https://marketplace.elgato.com/product/igox-busylight-7448a0be-6dd6-4711-ba0d-86c52b9075b9)
|
||||||
|
|
||||||
|
Or directly from the [releases](https://code.igox.org/busylight/busylight-streamdeck-plugin/releases) page.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Screenshot
|
## Screenshot
|
||||||
|
|||||||
@@ -1,9 +1,26 @@
|
|||||||
{
|
{
|
||||||
"Name": "iGoX BusyLight",
|
"Name": "iGoX BusyLight",
|
||||||
"Version": "0.3.1.0",
|
"Version": "0.3.3.0",
|
||||||
"Author": "iGoX",
|
"Author": "iGoX",
|
||||||
"$schema": "https://schemas.elgato.com/streamdeck/plugins/manifest.json",
|
"$schema": "https://schemas.elgato.com/streamdeck/plugins/manifest.json",
|
||||||
"Actions": [
|
"Actions": [
|
||||||
|
{
|
||||||
|
"Name": "Live BusyLight status",
|
||||||
|
"UUID": "org.igox.busylight.status.live",
|
||||||
|
"Icon": "imgs/actions/icons/status/status",
|
||||||
|
"Tooltip": "Display the current BusyLight status",
|
||||||
|
"PropertyInspectorPath": "ui/live-status-config.html",
|
||||||
|
"SupportedInMultiActions": false,
|
||||||
|
"Controllers": [
|
||||||
|
"Keypad"
|
||||||
|
],
|
||||||
|
"States": [
|
||||||
|
{
|
||||||
|
"Image": "imgs/actions/icons/status/status",
|
||||||
|
"TitleAlignment": "bottom"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"Name": "Set BusyLight status",
|
"Name": "Set BusyLight status",
|
||||||
"UUID": "org.igox.busylight.status.set",
|
"UUID": "org.igox.busylight.status.set",
|
||||||
@@ -56,11 +73,11 @@
|
|||||||
"Category": "iGoX BusyLight",
|
"Category": "iGoX BusyLight",
|
||||||
"CategoryIcon": "imgs/plugin/category-icon",
|
"CategoryIcon": "imgs/plugin/category-icon",
|
||||||
"CodePath": "bin/plugin.js",
|
"CodePath": "bin/plugin.js",
|
||||||
"Description": "Control your DIY BusyLight (https://github.com/igox/busylight) from your Stream Deck",
|
"Description": "Control your DIY BusyLight (https://github.com/busylight/busylight) from your Stream Deck",
|
||||||
"Icon": "imgs/plugin/icon",
|
"Icon": "imgs/plugin/icon",
|
||||||
"SDKVersion": 2,
|
"SDKVersion": 3,
|
||||||
"Software": {
|
"Software": {
|
||||||
"MinimumVersion": "6.4"
|
"MinimumVersion": "7.5"
|
||||||
},
|
},
|
||||||
"OS": [
|
"OS": [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head lang="en">
|
||||||
|
<title>Live BusyLight status</title>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<script src="https://sdpi-components.dev/releases/v3/sdpi-components.js"></script>
|
||||||
|
<script>
|
||||||
|
function getGlobalSettings() {
|
||||||
|
const { streamDeckClient } = SDPIComponents;
|
||||||
|
const settings = streamDeckClient.getGlobalSettings();
|
||||||
|
return settings.url || 'http://busylight-esp32.local';
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<sdpi-item label="URL or IP">
|
||||||
|
<sdpi-textfield
|
||||||
|
setting="url"
|
||||||
|
placeholder="http://busylight-esp32.local"
|
||||||
|
global="true"
|
||||||
|
value="getGlobalSettings()">
|
||||||
|
</sdpi-textfield>
|
||||||
|
</sdpi-item>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Binary file not shown.
Generated
+16
-4
@@ -5,7 +5,8 @@
|
|||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@elgato/streamdeck": "^1.0.0"
|
"@elgato/streamdeck": "^1.0.0",
|
||||||
|
"ws": "^8.22.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@elgato/cli": "^1.1.0",
|
"@elgato/cli": "^1.1.0",
|
||||||
@@ -15,6 +16,7 @@
|
|||||||
"@rollup/plugin-typescript": "^12.1.0",
|
"@rollup/plugin-typescript": "^12.1.0",
|
||||||
"@tsconfig/node20": "^20.1.2",
|
"@tsconfig/node20": "^20.1.2",
|
||||||
"@types/node": "~20.15.0",
|
"@types/node": "~20.15.0",
|
||||||
|
"@types/ws": "^8.18.2",
|
||||||
"rollup": "^4.0.2",
|
"rollup": "^4.0.2",
|
||||||
"tslib": "^2.6.2",
|
"tslib": "^2.6.2",
|
||||||
"typescript": "^5.2.2"
|
"typescript": "^5.2.2"
|
||||||
@@ -704,6 +706,16 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/ws": {
|
||||||
|
"version": "8.18.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.18.2.tgz",
|
||||||
|
"integrity": "sha512-67MQl+fpWKVTT1NYdnmo3U4sc/xPo/zQBncVnI74qmQa0z/b+1g6iYqNmGCPbxO+zz2aklb08a0oHfegiVd0/w==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@zip.js/zip.js": {
|
"node_modules/@zip.js/zip.js": {
|
||||||
"version": "2.7.54",
|
"version": "2.7.54",
|
||||||
"resolved": "https://registry.npmjs.org/@zip.js/zip.js/-/zip.js-2.7.54.tgz",
|
"resolved": "https://registry.npmjs.org/@zip.js/zip.js/-/zip.js-2.7.54.tgz",
|
||||||
@@ -2348,9 +2360,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/ws": {
|
"node_modules/ws": {
|
||||||
"version": "8.18.0",
|
"version": "8.22.0",
|
||||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.18.0.tgz",
|
"resolved": "https://registry.npmjs.org/ws/-/ws-8.22.0.tgz",
|
||||||
"integrity": "sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==",
|
"integrity": "sha512-Ydggc987+RO0AnWtZ/7Wq9FtNvcrL1b/RO0ud9mWjUPgDrsAAwQSF51sm2hm1XofbU/4jkpGEsLFsZZxU+1DOg==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10.0.0"
|
"node": ">=10.0.0"
|
||||||
|
|||||||
@@ -12,11 +12,13 @@
|
|||||||
"@rollup/plugin-typescript": "^12.1.0",
|
"@rollup/plugin-typescript": "^12.1.0",
|
||||||
"@tsconfig/node20": "^20.1.2",
|
"@tsconfig/node20": "^20.1.2",
|
||||||
"@types/node": "~20.15.0",
|
"@types/node": "~20.15.0",
|
||||||
|
"@types/ws": "^8.18.2",
|
||||||
"rollup": "^4.0.2",
|
"rollup": "^4.0.2",
|
||||||
"tslib": "^2.6.2",
|
"tslib": "^2.6.2",
|
||||||
"typescript": "^5.2.2"
|
"typescript": "^5.2.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@elgato/streamdeck": "^1.0.0"
|
"@elgato/streamdeck": "^1.0.0",
|
||||||
|
"ws": "^8.22.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,127 @@
|
|||||||
|
import streamDeck, { action, SingletonAction, type KeyAction, type WillAppearEvent, type WillDisappearEvent } from "@elgato/streamdeck";
|
||||||
|
import WebSocket from "ws";
|
||||||
|
|
||||||
|
const statuses = new Set(["available", "away", "busy", "on", "off", "colored"]);
|
||||||
|
|
||||||
|
@action({ UUID: "org.igox.busylight.status.live" })
|
||||||
|
export class LiveStatus extends SingletonAction {
|
||||||
|
private readonly keys = new Map<string, KeyAction>();
|
||||||
|
private socket?: WebSocket;
|
||||||
|
private reconnectTimer?: ReturnType<typeof setTimeout>;
|
||||||
|
private url?: string;
|
||||||
|
private status?: string;
|
||||||
|
private title = "Connecting";
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
streamDeck.settings.onDidReceiveGlobalSettings<{ url?: string }>(ev => {
|
||||||
|
this.configure(ev.settings.url);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
override async onWillAppear(ev: WillAppearEvent): Promise<void> {
|
||||||
|
if (!ev.action.isKey()) return;
|
||||||
|
this.keys.set(ev.action.id, ev.action);
|
||||||
|
this.render(ev.action);
|
||||||
|
const settings = await streamDeck.settings.getGlobalSettings<{ url?: string }>();
|
||||||
|
this.configure(settings.url);
|
||||||
|
}
|
||||||
|
|
||||||
|
override onWillDisappear(ev: WillDisappearEvent): void {
|
||||||
|
this.keys.delete(ev.action.id);
|
||||||
|
if (this.keys.size === 0) {
|
||||||
|
this.disconnect();
|
||||||
|
this.status = undefined;
|
||||||
|
this.title = "Connecting";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private configure(serverUrl?: string): void {
|
||||||
|
let url: URL;
|
||||||
|
try {
|
||||||
|
url = new URL(serverUrl?.trim() || "http://busylight-esp32.local");
|
||||||
|
if (!["http:", "https:", "ws:", "wss:"].includes(url.protocol)) {
|
||||||
|
throw new Error("Unsupported BusyLight URL protocol");
|
||||||
|
}
|
||||||
|
url.protocol = ["https:", "wss:"].includes(url.protocol) ? "wss:" : "ws:";
|
||||||
|
url.pathname = "/ws/status";
|
||||||
|
url.search = "";
|
||||||
|
url.hash = "";
|
||||||
|
} catch {
|
||||||
|
this.disconnect();
|
||||||
|
this.url = undefined;
|
||||||
|
this.update(undefined, "Invalid URL");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const nextUrl = url.toString();
|
||||||
|
if (this.url !== nextUrl) {
|
||||||
|
this.disconnect();
|
||||||
|
this.url = nextUrl;
|
||||||
|
this.update(undefined, "Connecting");
|
||||||
|
}
|
||||||
|
if (this.keys.size > 0 && !this.socket && !this.reconnectTimer) {
|
||||||
|
this.connect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private connect(): void {
|
||||||
|
if (!this.url || this.keys.size === 0) return;
|
||||||
|
const socket = new WebSocket(this.url, { handshakeTimeout: 5000 });
|
||||||
|
this.socket = socket;
|
||||||
|
|
||||||
|
socket.on("message", data => {
|
||||||
|
if (this.socket !== socket) return;
|
||||||
|
try {
|
||||||
|
const message: unknown = JSON.parse(data.toString());
|
||||||
|
if (typeof message !== "object" || message === null || !("status" in message)
|
||||||
|
|| typeof message.status !== "string" || !statuses.has(message.status)) {
|
||||||
|
streamDeck.logger.warn("Ignoring invalid BusyLight status message");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.update(message.status, message.status.charAt(0).toUpperCase() + message.status.slice(1));
|
||||||
|
} catch {
|
||||||
|
streamDeck.logger.warn("Ignoring malformed BusyLight status message");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
socket.on("error", error => {
|
||||||
|
if (this.socket !== socket) return;
|
||||||
|
streamDeck.logger.warn(`BusyLight WebSocket error: ${error.message}`);
|
||||||
|
socket.terminate();
|
||||||
|
});
|
||||||
|
socket.on("close", () => {
|
||||||
|
if (this.socket !== socket) return;
|
||||||
|
this.socket = undefined;
|
||||||
|
this.update(undefined, "Offline");
|
||||||
|
if (this.keys.size > 0) {
|
||||||
|
this.reconnectTimer = setTimeout(() => {
|
||||||
|
this.reconnectTimer = undefined;
|
||||||
|
this.connect();
|
||||||
|
}, 2000);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private disconnect(): void {
|
||||||
|
clearTimeout(this.reconnectTimer);
|
||||||
|
this.reconnectTimer = undefined;
|
||||||
|
const socket = this.socket;
|
||||||
|
this.socket = undefined;
|
||||||
|
socket?.terminate();
|
||||||
|
}
|
||||||
|
|
||||||
|
private update(status: string | undefined, title: string): void {
|
||||||
|
this.status = status;
|
||||||
|
this.title = title;
|
||||||
|
for (const key of this.keys.values()) this.render(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
private render(key: KeyAction): void {
|
||||||
|
const image = this.status
|
||||||
|
? `imgs/actions/buttons/${this.status}/${this.status}.png`
|
||||||
|
: "imgs/actions/icons/status/status.png";
|
||||||
|
void Promise.all([key.setImage(image), key.setTitle(this.title)]).catch(error => {
|
||||||
|
streamDeck.logger.error("Failed to update BusyLight status button", error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ import streamDeck, { LogLevel, SingletonAction, action, type DidReceiveSettingsE
|
|||||||
import { SetStatus} from "./actions/set-status";
|
import { SetStatus} from "./actions/set-status";
|
||||||
import { SetBrightness } from "./actions/set-brightness";
|
import { SetBrightness } from "./actions/set-brightness";
|
||||||
import { SetColor } from "./actions/set-color";
|
import { SetColor } from "./actions/set-color";
|
||||||
|
import { LiveStatus } from "./actions/live-status";
|
||||||
|
|
||||||
// We can enable "trace" logging so that all messages between the Stream Deck, and the plugin are recorded. When storing sensitive information
|
// We can enable "trace" logging so that all messages between the Stream Deck, and the plugin are recorded. When storing sensitive information
|
||||||
streamDeck.logger.setLevel(LogLevel.INFO);
|
streamDeck.logger.setLevel(LogLevel.INFO);
|
||||||
@@ -11,6 +12,7 @@ streamDeck.logger.setLevel(LogLevel.INFO);
|
|||||||
streamDeck.actions.registerAction(new SetStatus());
|
streamDeck.actions.registerAction(new SetStatus());
|
||||||
streamDeck.actions.registerAction(new SetBrightness());
|
streamDeck.actions.registerAction(new SetBrightness());
|
||||||
streamDeck.actions.registerAction(new SetColor());
|
streamDeck.actions.registerAction(new SetColor());
|
||||||
|
streamDeck.actions.registerAction(new LiveStatus());
|
||||||
|
|
||||||
// Finally, connect to the Stream Deck.
|
// Finally, connect to the Stream Deck.
|
||||||
streamDeck.connect();
|
streamDeck.connect();
|
||||||
Reference in new issue
Block a user