@bobfrankston/lxlan 0.1.0
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/.claude/settings.local.json +13 -0
- package/client.d.ts +65 -0
- package/client.d.ts.map +1 -0
- package/client.js +176 -0
- package/client.js.map +1 -0
- package/client.ts +214 -0
- package/device.d.ts +75 -0
- package/device.d.ts.map +1 -0
- package/device.js +149 -0
- package/device.js.map +1 -0
- package/device.ts +170 -0
- package/index.d.ts +5 -0
- package/index.d.ts.map +1 -0
- package/index.js +5 -0
- package/index.js.map +1 -0
- package/index.ts +4 -0
- package/notes.md +530 -0
- package/package.json +31 -0
- package/protocol.d.ts +56 -0
- package/protocol.d.ts.map +1 -0
- package/protocol.js +174 -0
- package/protocol.js.map +1 -0
- package/protocol.ts +209 -0
- package/tsconfig.json +20 -0
- package/types.d.ts +64 -0
- package/types.d.ts.map +1 -0
- package/types.js +86 -0
- package/types.js.map +1 -0
- package/types.ts +129 -0
package/device.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { parseColor, hsbkTo16 } from '@bobfrankston/colorlib';
|
|
2
|
+
import { MessageType, Products, LIFX_PORT } from './types.js';
|
|
3
|
+
import { encodeMessage, encodeSetPower, encodeSetColor, encodeSetLabel, encodeSetGroup, encodeSetLocation } from './protocol.js';
|
|
4
|
+
/**
|
|
5
|
+
* Represents a LIFX device on the LAN.
|
|
6
|
+
* State is cached and updated via events from LxClient.
|
|
7
|
+
*/
|
|
8
|
+
export class LxDevice {
|
|
9
|
+
/** MAC address (lowercase, colon-separated) */
|
|
10
|
+
mac;
|
|
11
|
+
/** Current IP address */
|
|
12
|
+
ip;
|
|
13
|
+
/** UDP port (default 56700) */
|
|
14
|
+
port = LIFX_PORT;
|
|
15
|
+
/** Power state (true = on) */
|
|
16
|
+
power = false;
|
|
17
|
+
/** Current color in HSBK format */
|
|
18
|
+
color = { h: 0, s: 0, b: 0, k: 3500 };
|
|
19
|
+
/** Device label (user-assigned name) */
|
|
20
|
+
label = '';
|
|
21
|
+
/** Whether device is responding */
|
|
22
|
+
online = false;
|
|
23
|
+
/** Last message timestamp (Date.now()) */
|
|
24
|
+
lastSeen = 0;
|
|
25
|
+
/** Vendor ID (1 = LIFX) */
|
|
26
|
+
vendor = 0;
|
|
27
|
+
/** Product ID (see Products table) */
|
|
28
|
+
product = 0;
|
|
29
|
+
/** Group membership */
|
|
30
|
+
group = { id: '', label: '', updatedAt: 0 };
|
|
31
|
+
/** Location membership */
|
|
32
|
+
location = { id: '', label: '', updatedAt: 0 };
|
|
33
|
+
socket;
|
|
34
|
+
constructor(mac, ip, socket) {
|
|
35
|
+
this.mac = mac.toLowerCase();
|
|
36
|
+
this.ip = ip;
|
|
37
|
+
this.socket = socket;
|
|
38
|
+
}
|
|
39
|
+
/** Get product name from product ID */
|
|
40
|
+
get productName() {
|
|
41
|
+
return Products[this.product] ?? `Unknown (${this.product})`;
|
|
42
|
+
}
|
|
43
|
+
/** Send raw message to device */
|
|
44
|
+
send(type, payload) {
|
|
45
|
+
const msg = encodeMessage({
|
|
46
|
+
type,
|
|
47
|
+
target: this.mac,
|
|
48
|
+
payload,
|
|
49
|
+
ackRequired: false,
|
|
50
|
+
resRequired: true
|
|
51
|
+
});
|
|
52
|
+
this.socket.send(this.ip, this.port, msg);
|
|
53
|
+
}
|
|
54
|
+
/** Set power on/off */
|
|
55
|
+
setPower(on) {
|
|
56
|
+
const msg = encodeMessage({
|
|
57
|
+
type: MessageType.SetPower,
|
|
58
|
+
target: this.mac,
|
|
59
|
+
payload: encodeSetPower(on),
|
|
60
|
+
ackRequired: true
|
|
61
|
+
});
|
|
62
|
+
this.socket.send(this.ip, this.port, msg);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Set color - accepts flexible input formats
|
|
66
|
+
* @param color - Color as hex "#ff0000", RGB {r,g,b}, HSL {h,s,l}, HSB {h,s,b}, HSBK {h,s,b,k}, or Kelvin number
|
|
67
|
+
* @param duration - Transition time in milliseconds (default 0)
|
|
68
|
+
*/
|
|
69
|
+
setColor(color, duration = 0) {
|
|
70
|
+
const hsbk = parseColor(color);
|
|
71
|
+
const hsbk16 = hsbkTo16(hsbk);
|
|
72
|
+
const msg = encodeMessage({
|
|
73
|
+
type: MessageType.SetColor,
|
|
74
|
+
target: this.mac,
|
|
75
|
+
payload: encodeSetColor(hsbk16, duration),
|
|
76
|
+
ackRequired: true
|
|
77
|
+
});
|
|
78
|
+
this.socket.send(this.ip, this.port, msg);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Set white color temperature
|
|
82
|
+
* @param kelvin - Color temperature (1500-9000, warm to cool)
|
|
83
|
+
* @param brightness - Brightness 0-100 (default 100)
|
|
84
|
+
* @param duration - Transition time in milliseconds (default 0)
|
|
85
|
+
*/
|
|
86
|
+
setWhite(kelvin, brightness = 100, duration = 0) {
|
|
87
|
+
this.setColor({ h: 0, s: 0, b: brightness, k: kelvin }, duration);
|
|
88
|
+
}
|
|
89
|
+
/** Query full state */
|
|
90
|
+
getState() {
|
|
91
|
+
this.send(MessageType.Get);
|
|
92
|
+
}
|
|
93
|
+
/** Query power state */
|
|
94
|
+
getPower() {
|
|
95
|
+
this.send(MessageType.GetPower);
|
|
96
|
+
}
|
|
97
|
+
/** Set label */
|
|
98
|
+
setLabel(label) {
|
|
99
|
+
const msg = encodeMessage({
|
|
100
|
+
type: MessageType.SetLabel,
|
|
101
|
+
target: this.mac,
|
|
102
|
+
payload: encodeSetLabel(label),
|
|
103
|
+
ackRequired: true
|
|
104
|
+
});
|
|
105
|
+
this.socket.send(this.ip, this.port, msg);
|
|
106
|
+
}
|
|
107
|
+
/** Query label */
|
|
108
|
+
getLabel() {
|
|
109
|
+
this.send(MessageType.GetLabel);
|
|
110
|
+
}
|
|
111
|
+
/** Set group */
|
|
112
|
+
setGroup(id, label) {
|
|
113
|
+
const msg = encodeMessage({
|
|
114
|
+
type: MessageType.SetGroup,
|
|
115
|
+
target: this.mac,
|
|
116
|
+
payload: encodeSetGroup(id, label),
|
|
117
|
+
ackRequired: true
|
|
118
|
+
});
|
|
119
|
+
this.socket.send(this.ip, this.port, msg);
|
|
120
|
+
}
|
|
121
|
+
/** Query group */
|
|
122
|
+
getGroup() {
|
|
123
|
+
this.send(MessageType.GetGroup);
|
|
124
|
+
}
|
|
125
|
+
/** Set location */
|
|
126
|
+
setLocation(id, label) {
|
|
127
|
+
const msg = encodeMessage({
|
|
128
|
+
type: MessageType.SetLocation,
|
|
129
|
+
target: this.mac,
|
|
130
|
+
payload: encodeSetLocation(id, label),
|
|
131
|
+
ackRequired: true
|
|
132
|
+
});
|
|
133
|
+
this.socket.send(this.ip, this.port, msg);
|
|
134
|
+
}
|
|
135
|
+
/** Query location */
|
|
136
|
+
getLocation() {
|
|
137
|
+
this.send(MessageType.GetLocation);
|
|
138
|
+
}
|
|
139
|
+
/** Query version */
|
|
140
|
+
getVersion() {
|
|
141
|
+
this.send(MessageType.GetVersion);
|
|
142
|
+
}
|
|
143
|
+
/** Update last seen timestamp and online status */
|
|
144
|
+
markSeen() {
|
|
145
|
+
this.lastSeen = Date.now();
|
|
146
|
+
this.online = true;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=device.js.map
|
package/device.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"device.js","sourceRoot":"","sources":["device.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,UAAU,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAEhF,OAAO,EAAa,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,cAAc,EAAE,cAAc,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEjI;;;GAGG;AACH,MAAM,OAAO,QAAQ;IACjB,+CAA+C;IACtC,GAAG,CAAS;IACrB,yBAAyB;IACz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GAAG,GAAG,aAAa,CAAC;YACtB,IAAI,EAAE,WAAW,CAAC,WAAW;YAC7B,MAAM,EAAE,IAAI,CAAC,GAAG;YAChB,OAAO,EAAE,iBAAiB,CAAC,EAAE,EAAE,KAAK,CAAC;YACrC,WAAW,EAAE,IAAI;SACpB,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAC9C,CAAC;IAED,qBAAqB;IACrB,WAAW;QACP,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;IACvC,CAAC;IAED,oBAAoB;IACpB,UAAU;QACN,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;IACtC,CAAC;IAED,mDAAmD;IACnD,QAAQ;QACJ,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;IACvB,CAAC;CACJ"}
|
package/device.ts
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { HSBK, ColorInput, parseColor, hsbkTo16 } from '@bobfrankston/colorlib';
|
|
2
|
+
import { UdpSocket } from '@bobfrankston/lxudp';
|
|
3
|
+
import { GroupInfo, MessageType, Products, LIFX_PORT } from './types.js';
|
|
4
|
+
import { encodeMessage, encodeSetPower, encodeSetColor, encodeSetLabel, encodeSetGroup, encodeSetLocation } from './protocol.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Represents a LIFX device on the LAN.
|
|
8
|
+
* State is cached and updated via events from LxClient.
|
|
9
|
+
*/
|
|
10
|
+
export class LxDevice {
|
|
11
|
+
/** MAC address (lowercase, colon-separated) */
|
|
12
|
+
readonly mac: string;
|
|
13
|
+
/** Current IP address */
|
|
14
|
+
ip: string;
|
|
15
|
+
/** UDP port (default 56700) */
|
|
16
|
+
port: number = LIFX_PORT;
|
|
17
|
+
|
|
18
|
+
/** Power state (true = on) */
|
|
19
|
+
power: boolean = false;
|
|
20
|
+
/** Current color in HSBK format */
|
|
21
|
+
color: HSBK = { h: 0, s: 0, b: 0, k: 3500 };
|
|
22
|
+
/** Device label (user-assigned name) */
|
|
23
|
+
label: string = '';
|
|
24
|
+
/** Whether device is responding */
|
|
25
|
+
online: boolean = false;
|
|
26
|
+
/** Last message timestamp (Date.now()) */
|
|
27
|
+
lastSeen: number = 0;
|
|
28
|
+
|
|
29
|
+
/** Vendor ID (1 = LIFX) */
|
|
30
|
+
vendor: number = 0;
|
|
31
|
+
/** Product ID (see Products table) */
|
|
32
|
+
product: number = 0;
|
|
33
|
+
|
|
34
|
+
/** Group membership */
|
|
35
|
+
group: GroupInfo = { id: '', label: '', updatedAt: 0 };
|
|
36
|
+
/** Location membership */
|
|
37
|
+
location: GroupInfo = { id: '', label: '', updatedAt: 0 };
|
|
38
|
+
|
|
39
|
+
private socket: UdpSocket;
|
|
40
|
+
|
|
41
|
+
constructor(mac: string, ip: string, socket: UdpSocket) {
|
|
42
|
+
this.mac = mac.toLowerCase();
|
|
43
|
+
this.ip = ip;
|
|
44
|
+
this.socket = socket;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Get product name from product ID */
|
|
48
|
+
get productName(): string {
|
|
49
|
+
return Products[this.product] ?? `Unknown (${this.product})`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Send raw message to device */
|
|
53
|
+
send(type: number, payload?: Buffer): void {
|
|
54
|
+
const msg = encodeMessage({
|
|
55
|
+
type,
|
|
56
|
+
target: this.mac,
|
|
57
|
+
payload,
|
|
58
|
+
ackRequired: false,
|
|
59
|
+
resRequired: true
|
|
60
|
+
});
|
|
61
|
+
this.socket.send(this.ip, this.port, msg);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Set power on/off */
|
|
65
|
+
setPower(on: boolean): void {
|
|
66
|
+
const msg = encodeMessage({
|
|
67
|
+
type: MessageType.SetPower,
|
|
68
|
+
target: this.mac,
|
|
69
|
+
payload: encodeSetPower(on),
|
|
70
|
+
ackRequired: true
|
|
71
|
+
});
|
|
72
|
+
this.socket.send(this.ip, this.port, msg);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Set color - accepts flexible input formats
|
|
77
|
+
* @param color - Color as hex "#ff0000", RGB {r,g,b}, HSL {h,s,l}, HSB {h,s,b}, HSBK {h,s,b,k}, or Kelvin number
|
|
78
|
+
* @param duration - Transition time in milliseconds (default 0)
|
|
79
|
+
*/
|
|
80
|
+
setColor(color: ColorInput, duration: number = 0): void {
|
|
81
|
+
const hsbk = parseColor(color);
|
|
82
|
+
const hsbk16 = hsbkTo16(hsbk);
|
|
83
|
+
const msg = encodeMessage({
|
|
84
|
+
type: MessageType.SetColor,
|
|
85
|
+
target: this.mac,
|
|
86
|
+
payload: encodeSetColor(hsbk16, duration),
|
|
87
|
+
ackRequired: true
|
|
88
|
+
});
|
|
89
|
+
this.socket.send(this.ip, this.port, msg);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Set white color temperature
|
|
94
|
+
* @param kelvin - Color temperature (1500-9000, warm to cool)
|
|
95
|
+
* @param brightness - Brightness 0-100 (default 100)
|
|
96
|
+
* @param duration - Transition time in milliseconds (default 0)
|
|
97
|
+
*/
|
|
98
|
+
setWhite(kelvin: number, brightness: number = 100, duration: number = 0): void {
|
|
99
|
+
this.setColor({ h: 0, s: 0, b: brightness, k: kelvin }, duration);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Query full state */
|
|
103
|
+
getState(): void {
|
|
104
|
+
this.send(MessageType.Get);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Query power state */
|
|
108
|
+
getPower(): void {
|
|
109
|
+
this.send(MessageType.GetPower);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Set label */
|
|
113
|
+
setLabel(label: string): void {
|
|
114
|
+
const msg = encodeMessage({
|
|
115
|
+
type: MessageType.SetLabel,
|
|
116
|
+
target: this.mac,
|
|
117
|
+
payload: encodeSetLabel(label),
|
|
118
|
+
ackRequired: true
|
|
119
|
+
});
|
|
120
|
+
this.socket.send(this.ip, this.port, msg);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Query label */
|
|
124
|
+
getLabel(): void {
|
|
125
|
+
this.send(MessageType.GetLabel);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Set group */
|
|
129
|
+
setGroup(id: string, label: string): void {
|
|
130
|
+
const msg = encodeMessage({
|
|
131
|
+
type: MessageType.SetGroup,
|
|
132
|
+
target: this.mac,
|
|
133
|
+
payload: encodeSetGroup(id, label),
|
|
134
|
+
ackRequired: true
|
|
135
|
+
});
|
|
136
|
+
this.socket.send(this.ip, this.port, msg);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Query group */
|
|
140
|
+
getGroup(): void {
|
|
141
|
+
this.send(MessageType.GetGroup);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Set location */
|
|
145
|
+
setLocation(id: string, label: string): void {
|
|
146
|
+
const msg = encodeMessage({
|
|
147
|
+
type: MessageType.SetLocation,
|
|
148
|
+
target: this.mac,
|
|
149
|
+
payload: encodeSetLocation(id, label),
|
|
150
|
+
ackRequired: true
|
|
151
|
+
});
|
|
152
|
+
this.socket.send(this.ip, this.port, msg);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Query location */
|
|
156
|
+
getLocation(): void {
|
|
157
|
+
this.send(MessageType.GetLocation);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** Query version */
|
|
161
|
+
getVersion(): void {
|
|
162
|
+
this.send(MessageType.GetVersion);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** Update last seen timestamp and online status */
|
|
166
|
+
markSeen(): void {
|
|
167
|
+
this.lastSeen = Date.now();
|
|
168
|
+
this.online = true;
|
|
169
|
+
}
|
|
170
|
+
}
|
package/index.d.ts
ADDED
package/index.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC"}
|
package/index.js
ADDED
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAmB,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC"}
|
package/index.ts
ADDED