govee-toolkit 0.0.0 → 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/README.md +77 -8
- package/binding.cjs +795 -0
- package/binding.d.cts +387 -0
- package/dist/index.d.ts +38 -1
- package/dist/index.js +46 -11
- package/package.json +51 -5
package/binding.d.cts
ADDED
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
/* auto-generated by NAPI-RS */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Which binding artifact the generated loader actually loaded: `'native'` for
|
|
6
|
+
* a native addon, otherwise the `platformArchABI` of the WASI flavor. Every
|
|
7
|
+
* flavor napi-rs can build is listed, because `NAPI_RS_NATIVE_LIBRARY_PATH`
|
|
8
|
+
* can point the loader at a WASI artifact this package does not build itself.
|
|
9
|
+
*/
|
|
10
|
+
export declare const __napiBindingTarget: 'native' | 'wasm32-wasi' | 'wasm32-wasip1'
|
|
11
|
+
|
|
12
|
+
/** Every device the build knows. Reads no hardware. */
|
|
13
|
+
export declare class Catalog {
|
|
14
|
+
/** The catalog compiled into this build. */
|
|
15
|
+
static embedded(): Catalog
|
|
16
|
+
/** Every SKU that resolves, verified aliases included. */
|
|
17
|
+
skus(): Array<string>
|
|
18
|
+
/** Whether a SKU resolves. */
|
|
19
|
+
has(sku: string): boolean
|
|
20
|
+
/**
|
|
21
|
+
* One device file, with every `include:` and every override applied.
|
|
22
|
+
*
|
|
23
|
+
* Throws with the code `unknown_sku` when nothing declares it.
|
|
24
|
+
*/
|
|
25
|
+
device(sku: string): any
|
|
26
|
+
/** How many device files the build carries. */
|
|
27
|
+
get size(): number
|
|
28
|
+
toString(): string
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The configuration in force. Every field is read-only: the SDK reads the
|
|
33
|
+
* configuration once, at startup.
|
|
34
|
+
*/
|
|
35
|
+
export declare class Config {
|
|
36
|
+
/** The default configuration: `lan` alone, and no device entry. */
|
|
37
|
+
constructor()
|
|
38
|
+
/**
|
|
39
|
+
* Read `$XDG_CONFIG_HOME/govee-toolkit/config.yaml`.
|
|
40
|
+
*
|
|
41
|
+
* A missing file is the default configuration, not an error. A file that
|
|
42
|
+
* does not parse throws with the code `config`.
|
|
43
|
+
*/
|
|
44
|
+
static load(): Config
|
|
45
|
+
/** Read the configuration from one path. */
|
|
46
|
+
static loadFrom(path: string): Config
|
|
47
|
+
/** The modes enabled for a device with no entry of its own. */
|
|
48
|
+
get defaultModes(): Array<string>
|
|
49
|
+
/** The identity of every device the file names. */
|
|
50
|
+
get devices(): Array<string>
|
|
51
|
+
/** The rate a stream sends at when the device file measured none. */
|
|
52
|
+
get streamFallbackHz(): number
|
|
53
|
+
/**
|
|
54
|
+
* The whole configuration, as the core serializes it. It carries no
|
|
55
|
+
* credential: a key comes from the environment, never from the file.
|
|
56
|
+
*/
|
|
57
|
+
toJSON(): any
|
|
58
|
+
toString(): string
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** A device the SDK knows about. */
|
|
62
|
+
export declare class Device {
|
|
63
|
+
/** The MAC it reports, uppercased. */
|
|
64
|
+
get id(): string
|
|
65
|
+
/** The SKU it is encoded under. */
|
|
66
|
+
get sku(): string
|
|
67
|
+
/** The name the configuration gives it, if any. */
|
|
68
|
+
get name(): string | null
|
|
69
|
+
/** The enabled modes, in preference order. */
|
|
70
|
+
get modes(): Array<string>
|
|
71
|
+
/**
|
|
72
|
+
* Its health per enabled mode. A mode is absent when no transport has
|
|
73
|
+
* heard from it.
|
|
74
|
+
*/
|
|
75
|
+
get health(): Record<string, Health>
|
|
76
|
+
toString(): string
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* A handle on one identity. It holds no state of its own: every answer comes
|
|
81
|
+
* from the SDK it was made by.
|
|
82
|
+
*/
|
|
83
|
+
export declare class DeviceHandle {
|
|
84
|
+
/** The MAC the device reports, uppercased. */
|
|
85
|
+
get id(): string
|
|
86
|
+
/** The modes enabled for it, in preference order. */
|
|
87
|
+
get modes(): Array<string>
|
|
88
|
+
/**
|
|
89
|
+
* Its health in one mode. `null` when the transport that serves that
|
|
90
|
+
* mode has never heard from it.
|
|
91
|
+
*/
|
|
92
|
+
health(mode: string): Health | null
|
|
93
|
+
/**
|
|
94
|
+
* The mode a command sent now would go over. Read from recorded state,
|
|
95
|
+
* so the answer can change before the next call.
|
|
96
|
+
*/
|
|
97
|
+
servingMode(): string
|
|
98
|
+
/** What `devices/<SKU>.yaml` declares for it. Reads no hardware. */
|
|
99
|
+
spec(): any
|
|
100
|
+
/**
|
|
101
|
+
* What `devices/<SKU>.yaml` declares, as the record `govee describe`
|
|
102
|
+
* prints.
|
|
103
|
+
*/
|
|
104
|
+
describe(): any
|
|
105
|
+
/** The last status heard, without asking for a new one. */
|
|
106
|
+
lastStatus(): DeviceStatus | null
|
|
107
|
+
/**
|
|
108
|
+
* Watch its status as answers arrive, over the mode that would serve a
|
|
109
|
+
* command now. `null` when no enabled mode can, or when that transport
|
|
110
|
+
* has heard nothing.
|
|
111
|
+
*/
|
|
112
|
+
watchStatus(): StatusStream | null
|
|
113
|
+
/**
|
|
114
|
+
* Scan for the device if no mode knows it yet, then answer the mode a
|
|
115
|
+
* command would go over.
|
|
116
|
+
*/
|
|
117
|
+
ensureKnown(): Promise<string>
|
|
118
|
+
/**
|
|
119
|
+
* Send a command, named as the device file names it.
|
|
120
|
+
*
|
|
121
|
+
* Each value is read under the type the entry declares for it. A value
|
|
122
|
+
* outside the declared range throws with the code the codec gives it,
|
|
123
|
+
* and nothing is sent.
|
|
124
|
+
*/
|
|
125
|
+
send(command: string, args?: Record<string, boolean | number | string | Uint8Array | Array<number> | Array<[number, number, number]>>): Promise<Served>
|
|
126
|
+
/**
|
|
127
|
+
* Run a command's exchanges and return what its `reply:` layouts
|
|
128
|
+
* captured.
|
|
129
|
+
*/
|
|
130
|
+
read(command: string, args?: Record<string, boolean | number | string | Uint8Array | Array<number> | Array<[number, number, number]>>): Promise<Reply>
|
|
131
|
+
/** Ask the device for its state and wait for the answer. */
|
|
132
|
+
status(): Promise<DeviceStatus>
|
|
133
|
+
/** Turn the device on or off. */
|
|
134
|
+
power(on: boolean): Promise<Served>
|
|
135
|
+
/**
|
|
136
|
+
* Set the level, in the unit the device file declares. A level outside
|
|
137
|
+
* that range is an error, never a clamp.
|
|
138
|
+
*/
|
|
139
|
+
brightness(level: number): Promise<Served>
|
|
140
|
+
/** Set one color, as three channels or as three bytes. */
|
|
141
|
+
color(rgb: [number, number, number] | Uint8Array): Promise<Served>
|
|
142
|
+
/** Set the white temperature, in kelvin. It ends color mode. */
|
|
143
|
+
colorTemp(kelvin: number): Promise<Served>
|
|
144
|
+
/**
|
|
145
|
+
* Play an effect the device renders from its own microphone.
|
|
146
|
+
*
|
|
147
|
+
* The identifiers are the mode's own: one the entry accepts is not one
|
|
148
|
+
* the device renders. `color` imposes a color, and `null` leaves the
|
|
149
|
+
* colors to the firmware.
|
|
150
|
+
*
|
|
151
|
+
* `null` takes the core's default for `sensitivity` and for `soft`.
|
|
152
|
+
*/
|
|
153
|
+
music(effect: number, sensitivity?: number | undefined | null, soft?: boolean | undefined | null, color?: [number, number, number] | Uint8Array): Promise<Served>
|
|
154
|
+
/**
|
|
155
|
+
* Paint the segments once.
|
|
156
|
+
*
|
|
157
|
+
* One color fills every zone. An array of colors, or a `Uint8Array` of
|
|
158
|
+
* three bytes per zone, states them all. A zone list takes one color.
|
|
159
|
+
* `resolution` takes `"app"` when it is `null`.
|
|
160
|
+
*/
|
|
161
|
+
segment(colors: [number, number, number] | Array<[number, number, number]> | Uint8Array, zones?: Array<number> | undefined | null, resolution?: number | 'app' | 'native', gradient?: boolean | undefined | null): Promise<Served>
|
|
162
|
+
/**
|
|
163
|
+
* Ask the firmware to interpolate between zones, and to wrap from the
|
|
164
|
+
* last zone back to the first.
|
|
165
|
+
*/
|
|
166
|
+
gradient(on: boolean): Promise<Served>
|
|
167
|
+
/**
|
|
168
|
+
* Put the device on a Wi-Fi network over `ble`.
|
|
169
|
+
*
|
|
170
|
+
* The device must be in Bluetooth range and closed in the phone
|
|
171
|
+
* controller. The password travels in plaintext: anything in Bluetooth
|
|
172
|
+
* range during the transfer reads it. The network must be 2.4 GHz.
|
|
173
|
+
*
|
|
174
|
+
* Answers `"accepted"` where the device acknowledged the transfer, and
|
|
175
|
+
* `"sent"` where its device file declares no acknowledgement.
|
|
176
|
+
*/
|
|
177
|
+
provisionWifi(network: string, password: string, utcOffsetHours?: number | undefined | null, utcOffsetMinutes?: number | undefined | null): Promise<string>
|
|
178
|
+
/**
|
|
179
|
+
* Open the raw segment channel and paint it frame by frame.
|
|
180
|
+
*
|
|
181
|
+
* Power the device on first: arming a dark strip paints nothing. The
|
|
182
|
+
* channel holds the colors only while it is armed, and the device goes
|
|
183
|
+
* back to the color it showed before once the stream closes.
|
|
184
|
+
*
|
|
185
|
+
* `resolution` takes `"app"` when it is `null`, and `rate` takes
|
|
186
|
+
* `"measured"`.
|
|
187
|
+
*/
|
|
188
|
+
openStream(resolution?: number | 'app' | 'native', rate?: number | 'measured', gradient?: boolean | undefined | null): Promise<SegmentStream>
|
|
189
|
+
toString(): string
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** What a device reported about itself. No firmware fills every field. */
|
|
193
|
+
export declare class DeviceStatus {
|
|
194
|
+
/** Which device answered. */
|
|
195
|
+
get id(): string
|
|
196
|
+
/** Whether it is on. */
|
|
197
|
+
get on(): boolean | null
|
|
198
|
+
/**
|
|
199
|
+
* The level it reports. A percentage on every unit seen so far, and not
|
|
200
|
+
* normalized here.
|
|
201
|
+
*/
|
|
202
|
+
get brightness(): number | null
|
|
203
|
+
/** The color, as three channels. Reset to `[0, 0, 0]` in white mode. */
|
|
204
|
+
get color(): [number, number, number] | null
|
|
205
|
+
/** The white temperature. `0` means the device is in color mode. */
|
|
206
|
+
get colorTempKelvin(): number | null
|
|
207
|
+
/** The whole reply, with every field the SDK does not model. */
|
|
208
|
+
get raw(): any
|
|
209
|
+
/** Whether the device is in white mode. Mutually exclusive with color. */
|
|
210
|
+
get isWhite(): boolean
|
|
211
|
+
toString(): string
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* The events of one SDK. Iterate it with `for await`.
|
|
216
|
+
*
|
|
217
|
+
* Every event is a plain object, and `event` says which one it is. The
|
|
218
|
+
* records are the core's own, so `govee watch --json` prints the same ones.
|
|
219
|
+
* A subscription that falls behind reports `{ event: "lagged", missed: n }`
|
|
220
|
+
* rather than hide the gap.
|
|
221
|
+
*/
|
|
222
|
+
export declare class EventStream {
|
|
223
|
+
/** The next event, or `null` once the SDK that reported them is gone. */
|
|
224
|
+
next(): Promise<any | undefined | null>
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* The SDK. Start one and keep it: it holds the catalog, the configuration
|
|
229
|
+
* and one transport per mode.
|
|
230
|
+
*/
|
|
231
|
+
export declare class Govee {
|
|
232
|
+
/**
|
|
233
|
+
* Start the SDK. Without a configuration, it reads the file. Without a
|
|
234
|
+
* catalog, it reads the one the package carries.
|
|
235
|
+
*/
|
|
236
|
+
static start(config?: Config | undefined | null, catalog?: Catalog | undefined | null): Promise<Govee>
|
|
237
|
+
/**
|
|
238
|
+
* Run a discovery scan on every mode and return what answered.
|
|
239
|
+
*
|
|
240
|
+
* The scans run at the same time, so the call takes the longest window
|
|
241
|
+
* and not their sum. Nothing on the send path calls this.
|
|
242
|
+
*/
|
|
243
|
+
scan(): Promise<Array<Device>>
|
|
244
|
+
/**
|
|
245
|
+
* Run a discovery scan on the modes named.
|
|
246
|
+
*
|
|
247
|
+
* A mode this build carries no transport for contributes nothing and is
|
|
248
|
+
* not an error.
|
|
249
|
+
*/
|
|
250
|
+
scanOn(modes: Array<string>): Promise<Array<Device>>
|
|
251
|
+
/**
|
|
252
|
+
* Every device known, across every mode. One reachable over two modes
|
|
253
|
+
* appears once.
|
|
254
|
+
*/
|
|
255
|
+
devices(): Array<Device>
|
|
256
|
+
/**
|
|
257
|
+
* The modes this build carries a transport for. Not a preference order:
|
|
258
|
+
* that is each device's own configuration.
|
|
259
|
+
*/
|
|
260
|
+
modes(): Array<string>
|
|
261
|
+
/** Everything wrong with the configuration, as one sentence each. */
|
|
262
|
+
problems(): Array<string>
|
|
263
|
+
/** The configuration in force. */
|
|
264
|
+
get config(): Config
|
|
265
|
+
/** The device catalog in force. */
|
|
266
|
+
get catalog(): Catalog
|
|
267
|
+
/** A handle for one device, by the MAC it reports. */
|
|
268
|
+
device(id: string): DeviceHandle
|
|
269
|
+
/** Subscribe to what the SDK reports. Iterate it with `for await`. */
|
|
270
|
+
events(): EventStream
|
|
271
|
+
/**
|
|
272
|
+
* Release what every transport holds. Call it before the program ends,
|
|
273
|
+
* or `ble` loses the last frame it wrote.
|
|
274
|
+
*/
|
|
275
|
+
close(): Promise<undefined>
|
|
276
|
+
toString(): string
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/** A device's health in one mode. */
|
|
280
|
+
export declare class Health {
|
|
281
|
+
/** `"ok"`, `"degraded"` or `"down"`. */
|
|
282
|
+
get state(): string
|
|
283
|
+
/** Consecutive unanswered verifications. */
|
|
284
|
+
get failures(): number
|
|
285
|
+
/** Whether a command would be sent right now. */
|
|
286
|
+
get available(): boolean
|
|
287
|
+
toString(): string
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** What one command's `reply:` layouts captured. */
|
|
291
|
+
export declare class Reply {
|
|
292
|
+
/** Which device answered. */
|
|
293
|
+
get id(): string
|
|
294
|
+
/**
|
|
295
|
+
* Every field the exchanges captured, by the name the device file gives
|
|
296
|
+
* it.
|
|
297
|
+
*/
|
|
298
|
+
get fields(): any
|
|
299
|
+
toString(): string
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* An open segment channel. The writers never block: each one replaces what
|
|
304
|
+
* the next frame carries.
|
|
305
|
+
*
|
|
306
|
+
* Close it, or leave it with `await using`. A stream that is collected
|
|
307
|
+
* disarms the channel as well, and reports no failure.
|
|
308
|
+
*/
|
|
309
|
+
export declare class SegmentStream {
|
|
310
|
+
/**
|
|
311
|
+
* How many zones the frames carry. The firmware reads the count off the
|
|
312
|
+
* frame, so it never changes while the stream is open.
|
|
313
|
+
*/
|
|
314
|
+
get zones(): number
|
|
315
|
+
/** How fast frames go out, in hertz. */
|
|
316
|
+
get rateHz(): number
|
|
317
|
+
/** How many frames reached the wire. */
|
|
318
|
+
get framesSent(): number
|
|
319
|
+
/** How many frames a later write replaced before they left. */
|
|
320
|
+
get framesSuperseded(): number
|
|
321
|
+
/**
|
|
322
|
+
* What the emitting task failed with, if it failed. The stream stops
|
|
323
|
+
* sending, and the writers keep answering.
|
|
324
|
+
*/
|
|
325
|
+
get error(): string | null
|
|
326
|
+
/**
|
|
327
|
+
* State every zone. The count must be the stream's own.
|
|
328
|
+
*
|
|
329
|
+
* A `Uint8Array` of three bytes for every zone crosses the binding once.
|
|
330
|
+
* An array of colors crosses it ten times per zone, which a frame loop
|
|
331
|
+
* pays on every frame.
|
|
332
|
+
*/
|
|
333
|
+
setAll(colors: Array<[number, number, number]> | Uint8Array): void
|
|
334
|
+
/** State one zone, by its zero-based index. */
|
|
335
|
+
setZone(index: number, color: [number, number, number] | Uint8Array): void
|
|
336
|
+
/** Put one color in every zone. */
|
|
337
|
+
fill(color: [number, number, number] | Uint8Array): void
|
|
338
|
+
/** Put black in every zone. The channel stays armed. */
|
|
339
|
+
clear(): void
|
|
340
|
+
/**
|
|
341
|
+
* What the next frame carries, in the run `setAll` takes back. It is a
|
|
342
|
+
* copy: a write to it paints nothing.
|
|
343
|
+
*/
|
|
344
|
+
buffer(): Uint8Array
|
|
345
|
+
/** Disarm the channel and wait for the last frame to leave. */
|
|
346
|
+
close(): Promise<undefined>
|
|
347
|
+
toString(): string
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/** A command that was served. */
|
|
351
|
+
export declare class Served {
|
|
352
|
+
/** The device it went to. */
|
|
353
|
+
get id(): string
|
|
354
|
+
/** The mode that served it. */
|
|
355
|
+
get mode(): string
|
|
356
|
+
/** The device file entry that was sent. */
|
|
357
|
+
get command(): string
|
|
358
|
+
/** The name the wire carries, where it carries one. */
|
|
359
|
+
get cmd(): string
|
|
360
|
+
toString(): string
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* One device's status, as answers arrive. Iterate it with `for await`.
|
|
365
|
+
*
|
|
366
|
+
* It requests nothing: it reports the answers a status request or a
|
|
367
|
+
* verification already brought back.
|
|
368
|
+
*/
|
|
369
|
+
export declare class StatusStream {
|
|
370
|
+
/**
|
|
371
|
+
* The next status, or `null` once the transport that heard this device
|
|
372
|
+
* is gone.
|
|
373
|
+
*/
|
|
374
|
+
next(): Promise<DeviceStatus | undefined | null>
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/** The version of the core this binding was built from. */
|
|
378
|
+
export declare const CORE_VERSION: string
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Every mode name the core knows. A build carries a transport for those its
|
|
382
|
+
* features name — `Govee.modes()` answers which.
|
|
383
|
+
*/
|
|
384
|
+
export declare function modes(): Array<string>
|
|
385
|
+
|
|
386
|
+
/** The version of this binding. */
|
|
387
|
+
export declare const VERSION: string
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,38 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Control Govee devices from your own network.
|
|
3
|
+
*
|
|
4
|
+
* Every behavior is in the addon this module re-exports, which binds the
|
|
5
|
+
* `govee-toolkit` core. What is added here is what an addon cannot declare:
|
|
6
|
+
* the asynchronous iterators, and the disposer a segment stream closes on.
|
|
7
|
+
*/
|
|
8
|
+
import { Catalog, Config, CORE_VERSION, Device, DeviceHandle, DeviceStatus, EventStream, Govee, Health, Reply, SegmentStream, Served, StatusStream, VERSION } from "../binding.cjs";
|
|
9
|
+
export { Catalog, Config, CORE_VERSION, Device, DeviceHandle, DeviceStatus, EventStream, Govee, Health, Reply, SegmentStream, Served, StatusStream, VERSION, };
|
|
10
|
+
/** One RGB triple, each channel 0-255. */
|
|
11
|
+
export type Color = [number, number, number];
|
|
12
|
+
/** A value a device file's command takes as an argument. */
|
|
13
|
+
export type Arg = boolean | number | string | Uint8Array | number[] | Color[];
|
|
14
|
+
/** A segment count, or the name of one the device file declares. */
|
|
15
|
+
export type Resolution = number | "app" | "native";
|
|
16
|
+
/** Frames per second, or the name of a rate the device file declares. */
|
|
17
|
+
export type Rate = number | "measured";
|
|
18
|
+
/**
|
|
19
|
+
* One record the SDK reports. `event` says which one it is; the rest is the
|
|
20
|
+
* record's own, as `govee watch --json` prints it.
|
|
21
|
+
*/
|
|
22
|
+
export type GoveeEvent = {
|
|
23
|
+
event: string;
|
|
24
|
+
[field: string]: unknown;
|
|
25
|
+
};
|
|
26
|
+
/** Every mode name the core knows, in the order the core lists them. */
|
|
27
|
+
export declare const MODES: readonly string[];
|
|
28
|
+
declare module "../binding.cjs" {
|
|
29
|
+
interface EventStream {
|
|
30
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<GoveeEvent>;
|
|
31
|
+
}
|
|
32
|
+
interface StatusStream {
|
|
33
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<DeviceStatus>;
|
|
34
|
+
}
|
|
35
|
+
interface SegmentStream {
|
|
36
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export
|
|
1
|
+
/**
|
|
2
|
+
* Control Govee devices from your own network.
|
|
3
|
+
*
|
|
4
|
+
* Every behavior is in the addon this module re-exports, which binds the
|
|
5
|
+
* `govee-toolkit` core. What is added here is what an addon cannot declare:
|
|
6
|
+
* the asynchronous iterators, and the disposer a segment stream closes on.
|
|
7
|
+
*/
|
|
8
|
+
import { Catalog, Config, CORE_VERSION, Device, DeviceHandle, DeviceStatus, EventStream, Govee, Health, modes, Reply, SegmentStream, Served, StatusStream, VERSION, } from "../binding.cjs";
|
|
9
|
+
export { Catalog, Config, CORE_VERSION, Device, DeviceHandle, DeviceStatus, EventStream, Govee, Health, Reply, SegmentStream, Served, StatusStream, VERSION, };
|
|
10
|
+
/** Every mode name the core knows, in the order the core lists them. */
|
|
11
|
+
export const MODES = Object.freeze(modes());
|
|
12
|
+
/**
|
|
13
|
+
* `Symbol.asyncDispose` reached Node after the floor this package supports,
|
|
14
|
+
* so the well-known symbol is taken where the runtime declares it and made
|
|
15
|
+
* where it does not. `await using` reads the same key either way.
|
|
16
|
+
*/
|
|
17
|
+
const asyncDispose = Symbol.asyncDispose ?? Symbol.for("Symbol.asyncDispose");
|
|
18
|
+
/** `null` from the source is where it ends. */
|
|
19
|
+
function iterate(source) {
|
|
20
|
+
return {
|
|
21
|
+
[Symbol.asyncIterator]() {
|
|
22
|
+
return this;
|
|
23
|
+
},
|
|
24
|
+
async next() {
|
|
25
|
+
const value = await source.next();
|
|
26
|
+
return value === null || value === undefined
|
|
27
|
+
? { value: undefined, done: true }
|
|
28
|
+
: { value, done: false };
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
Object.defineProperty(EventStream.prototype, Symbol.asyncIterator, {
|
|
33
|
+
value() {
|
|
34
|
+
return iterate(this);
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(StatusStream.prototype, Symbol.asyncIterator, {
|
|
38
|
+
value() {
|
|
39
|
+
return iterate(this);
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(SegmentStream.prototype, asyncDispose, {
|
|
43
|
+
value() {
|
|
44
|
+
return this.close();
|
|
45
|
+
},
|
|
46
|
+
});
|
package/package.json
CHANGED
|
@@ -1,15 +1,61 @@
|
|
|
1
1
|
{
|
|
2
|
-
"comment": "TODO: fill in once the napi-rs binding is written.",
|
|
3
2
|
"name": "govee-toolkit",
|
|
4
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.0",
|
|
5
4
|
"description": "Control Govee devices from your own network: undocumented LAN features, with BLE and Cloud modes when you need them.",
|
|
6
5
|
"license": "MIT",
|
|
6
|
+
"author": "damient",
|
|
7
|
+
"homepage": "https://gvetk.com",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/damient/govee-toolkit.git",
|
|
11
|
+
"directory": "packages/node"
|
|
12
|
+
},
|
|
13
|
+
"bugs": "https://github.com/damient/govee-toolkit/issues",
|
|
14
|
+
"keywords": [
|
|
15
|
+
"govee",
|
|
16
|
+
"led",
|
|
17
|
+
"smart-home",
|
|
18
|
+
"iot",
|
|
19
|
+
"sdk"
|
|
20
|
+
],
|
|
7
21
|
"type": "module",
|
|
8
22
|
"main": "dist/index.js",
|
|
9
23
|
"types": "dist/index.d.ts",
|
|
10
|
-
"files": [
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"binding.cjs",
|
|
27
|
+
"binding.d.cts"
|
|
28
|
+
],
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=20"
|
|
31
|
+
},
|
|
32
|
+
"napi": {
|
|
33
|
+
"binaryName": "govee-toolkit",
|
|
34
|
+
"targets": [
|
|
35
|
+
"x86_64-unknown-linux-gnu",
|
|
36
|
+
"aarch64-unknown-linux-gnu",
|
|
37
|
+
"aarch64-apple-darwin",
|
|
38
|
+
"x86_64-pc-windows-msvc",
|
|
39
|
+
"aarch64-pc-windows-msvc"
|
|
40
|
+
]
|
|
41
|
+
},
|
|
11
42
|
"scripts": {
|
|
12
|
-
"build": "tsc -p tsconfig.json",
|
|
13
|
-
"
|
|
43
|
+
"build": "napi build --platform --release --js binding.cjs --dts binding.d.cts && tsc -p tsconfig.json",
|
|
44
|
+
"build:debug": "napi build --platform --js binding.cjs --dts binding.d.cts && tsc -p tsconfig.json",
|
|
45
|
+
"build:ts": "tsc -p tsconfig.json",
|
|
46
|
+
"artifacts": "napi artifacts --output-dir ./artifacts",
|
|
47
|
+
"prepublishOnly": "napi prepublish -t npm --no-gh-release",
|
|
48
|
+
"test": "node --test"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@napi-rs/cli": "^3.10.3",
|
|
52
|
+
"typescript": "^7.0.2"
|
|
53
|
+
},
|
|
54
|
+
"optionalDependencies": {
|
|
55
|
+
"govee-toolkit-linux-x64-gnu": "0.1.0",
|
|
56
|
+
"govee-toolkit-linux-arm64-gnu": "0.1.0",
|
|
57
|
+
"govee-toolkit-darwin-arm64": "0.1.0",
|
|
58
|
+
"govee-toolkit-win32-x64-msvc": "0.1.0",
|
|
59
|
+
"govee-toolkit-win32-arm64-msvc": "0.1.0"
|
|
14
60
|
}
|
|
15
61
|
}
|