@sdeck/govee 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +22 -2
- package/dist/cloud.d.ts +165 -0
- package/dist/cloud.d.ts.map +1 -0
- package/dist/colors.d.ts +39 -0
- package/dist/colors.d.ts.map +1 -0
- package/dist/constants.d.ts +15 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/controller.d.ts +60 -0
- package/dist/controller.d.ts.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +809 -0
- package/dist/index.js.map +16 -0
- package/dist/protocol.d.ts +47 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/transport.d.ts +19 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transports/noble.d.ts +32 -0
- package/dist/transports/noble.d.ts.map +1 -0
- package/package.json +43 -4
- package/src/cloud.ts +371 -0
- package/src/colors.ts +70 -0
- package/src/constants.ts +19 -0
- package/src/controller.ts +308 -0
- package/src/index.ts +37 -0
- package/src/protocol.ts +116 -0
- package/src/transport.ts +18 -0
- package/src/transports/noble.ts +210 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Xample
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @sdeck/govee
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Controls Govee lights from TypeScript. It drives Bluetooth strips (H613B, H613C, …) through
|
|
4
|
+
[`@stoprocent/noble`](https://github.com/stoprocent/noble), and Wi-Fi devices through Govee's
|
|
5
|
+
official cloud API. The Govee plugin (`@sdeck/plugin-govee`) is built on it.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { GoveeCloud, GoveeController } from "@sdeck/govee";
|
|
9
|
+
|
|
10
|
+
const strip = await new GoveeController("A4:C1:38:35:97:24").connect();
|
|
11
|
+
await strip.setColor([255, 120, 0]);
|
|
12
|
+
await strip.disconnect();
|
|
13
|
+
|
|
14
|
+
const closet = await new GoveeCloud(apiKey).getDevice("Closet");
|
|
15
|
+
await closet.setBrightness(60);
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
`bun test` runs its tests without a light. Bluetooth needs no setup on Windows; noble is loaded
|
|
19
|
+
only when a Bluetooth light is used.
|
|
20
|
+
|
|
21
|
+
Based on [govee_H613_BTcontroller](https://github.com/Xample33/govee_H613_BTcontroller), which
|
|
22
|
+
builds on [Govee-Reverse-Engineering](https://github.com/egold555/Govee-Reverse-Engineering) and
|
|
23
|
+
[govee-btled-H613B](https://github.com/gilcu3/govee-btled-H613B). MIT.
|
package/dist/cloud.d.ts
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import type { RGB } from "./colors.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Client for Govee's official cloud API (https://developer.govee.com), which reaches every
|
|
4
|
+
* Wi-Fi device on your account from anywhere. Get a key in the Govee Home app:
|
|
5
|
+
* Profile → Settings → Apply for API Key.
|
|
6
|
+
*/
|
|
7
|
+
export declare const CLOUD_BASE_URL = "https://openapi.api.govee.com";
|
|
8
|
+
export interface Capability {
|
|
9
|
+
type: string;
|
|
10
|
+
instance: string;
|
|
11
|
+
parameters?: CapabilityParameters;
|
|
12
|
+
}
|
|
13
|
+
export interface CapabilityParameters {
|
|
14
|
+
dataType?: "ENUM" | "INTEGER" | "STRUCT" | string;
|
|
15
|
+
unit?: string;
|
|
16
|
+
options?: {
|
|
17
|
+
name: string;
|
|
18
|
+
value: unknown;
|
|
19
|
+
}[];
|
|
20
|
+
range?: {
|
|
21
|
+
min: number;
|
|
22
|
+
max: number;
|
|
23
|
+
precision?: number;
|
|
24
|
+
};
|
|
25
|
+
fields?: {
|
|
26
|
+
fieldName: string;
|
|
27
|
+
dataType: string;
|
|
28
|
+
required?: boolean;
|
|
29
|
+
[key: string]: unknown;
|
|
30
|
+
}[];
|
|
31
|
+
}
|
|
32
|
+
export interface CloudDeviceInfo {
|
|
33
|
+
sku: string;
|
|
34
|
+
/** Device id, e.g. `64:09:C5:32:37:36:2D:13`. */
|
|
35
|
+
device: string;
|
|
36
|
+
deviceName?: string;
|
|
37
|
+
type?: string;
|
|
38
|
+
capabilities: Capability[];
|
|
39
|
+
}
|
|
40
|
+
export interface CapabilityState {
|
|
41
|
+
type: string;
|
|
42
|
+
instance: string;
|
|
43
|
+
state: {
|
|
44
|
+
value: unknown;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export interface CloudDeviceState {
|
|
48
|
+
/** If false, the other values are the last known state. */
|
|
49
|
+
online: boolean | undefined;
|
|
50
|
+
power: boolean | undefined;
|
|
51
|
+
/** 1-100. */
|
|
52
|
+
brightness: number | undefined;
|
|
53
|
+
rgb: RGB | undefined;
|
|
54
|
+
colorTemperature: number | undefined;
|
|
55
|
+
/** Every capability as returned by the API, including ones without a typed field above. */
|
|
56
|
+
capabilities: CapabilityState[];
|
|
57
|
+
}
|
|
58
|
+
/** A scene that can be passed to `setScene`. */
|
|
59
|
+
export interface Scene {
|
|
60
|
+
name: string;
|
|
61
|
+
type: string;
|
|
62
|
+
instance: string;
|
|
63
|
+
value: unknown;
|
|
64
|
+
}
|
|
65
|
+
export declare class GoveeApiError extends Error {
|
|
66
|
+
/** HTTP status, or the `code` field of the response body. */
|
|
67
|
+
readonly status: number;
|
|
68
|
+
readonly body?: unknown;
|
|
69
|
+
constructor(message: string,
|
|
70
|
+
/** HTTP status, or the `code` field of the response body. */
|
|
71
|
+
status: number, body?: unknown);
|
|
72
|
+
}
|
|
73
|
+
export interface GoveeCloudOptions {
|
|
74
|
+
baseUrl?: string;
|
|
75
|
+
/** Custom fetch, e.g. for proxies or tests. */
|
|
76
|
+
fetch?: typeof fetch;
|
|
77
|
+
}
|
|
78
|
+
export declare const Capabilities: {
|
|
79
|
+
readonly power: {
|
|
80
|
+
readonly type: "devices.capabilities.on_off";
|
|
81
|
+
readonly instance: "powerSwitch";
|
|
82
|
+
};
|
|
83
|
+
readonly brightness: {
|
|
84
|
+
readonly type: "devices.capabilities.range";
|
|
85
|
+
readonly instance: "brightness";
|
|
86
|
+
};
|
|
87
|
+
readonly colorRgb: {
|
|
88
|
+
readonly type: "devices.capabilities.color_setting";
|
|
89
|
+
readonly instance: "colorRgb";
|
|
90
|
+
};
|
|
91
|
+
readonly colorTemperature: {
|
|
92
|
+
readonly type: "devices.capabilities.color_setting";
|
|
93
|
+
readonly instance: "colorTemperatureK";
|
|
94
|
+
};
|
|
95
|
+
readonly segmentColor: {
|
|
96
|
+
readonly type: "devices.capabilities.segment_color_setting";
|
|
97
|
+
readonly instance: "segmentedColorRgb";
|
|
98
|
+
};
|
|
99
|
+
readonly segmentBrightness: {
|
|
100
|
+
readonly type: "devices.capabilities.segment_color_setting";
|
|
101
|
+
readonly instance: "segmentedBrightness";
|
|
102
|
+
};
|
|
103
|
+
readonly online: {
|
|
104
|
+
readonly type: "devices.capabilities.online";
|
|
105
|
+
readonly instance: "online";
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
export declare const rgbToInt: ([r, g, b]: RGB) => number;
|
|
109
|
+
export declare const intToRgb: (value: number) => RGB;
|
|
110
|
+
export declare class GoveeCloud {
|
|
111
|
+
#private;
|
|
112
|
+
constructor(apiKey: string, options?: GoveeCloudOptions);
|
|
113
|
+
/** Lists every device on the account, with what each one supports. */
|
|
114
|
+
listDevices(): Promise<CloudDevice[]>;
|
|
115
|
+
/** Finds a device by id or (case-insensitive) name. */
|
|
116
|
+
getDevice(idOrName: string): Promise<CloudDevice>;
|
|
117
|
+
getState(sku: string, device: string): Promise<CloudDeviceState>;
|
|
118
|
+
control(sku: string, device: string, capability: {
|
|
119
|
+
type: string;
|
|
120
|
+
instance: string;
|
|
121
|
+
value: unknown;
|
|
122
|
+
}): Promise<void>;
|
|
123
|
+
/** Built-in dynamic scenes ("Sunrise", "Aurora", ...). */
|
|
124
|
+
getScenes(sku: string, device: string): Promise<Scene[]>;
|
|
125
|
+
/** DIY scenes created in the Govee Home app. */
|
|
126
|
+
getDiyScenes(sku: string, device: string): Promise<Scene[]>;
|
|
127
|
+
}
|
|
128
|
+
/** A device on the account, with helpers for the common capabilities. */
|
|
129
|
+
export declare class CloudDevice {
|
|
130
|
+
#private;
|
|
131
|
+
readonly sku: string;
|
|
132
|
+
readonly id: string;
|
|
133
|
+
readonly name: string;
|
|
134
|
+
readonly type: string | undefined;
|
|
135
|
+
readonly capabilities: readonly Capability[];
|
|
136
|
+
constructor(cloud: GoveeCloud, info: CloudDeviceInfo);
|
|
137
|
+
/** The capability definition for an instance, e.g. `"brightness"`, if the device has it. */
|
|
138
|
+
capability(instance: string): Capability | undefined;
|
|
139
|
+
supports(instance: string): boolean;
|
|
140
|
+
/** Groups made in the Govee app (sku `BaseGroup`, `SameModeGroup`, ...) only support power. */
|
|
141
|
+
get isGroup(): boolean;
|
|
142
|
+
getState(): Promise<CloudDeviceState>;
|
|
143
|
+
/** Sends any capability, for features without a dedicated helper. */
|
|
144
|
+
control(type: string, instance: string, value: unknown): Promise<void>;
|
|
145
|
+
setPower(on: boolean): Promise<void>;
|
|
146
|
+
turnOn(): Promise<void>;
|
|
147
|
+
turnOff(): Promise<void>;
|
|
148
|
+
/** Brightness in percent, 1-100. */
|
|
149
|
+
setBrightness(percent: number): Promise<void>;
|
|
150
|
+
setColor(rgb: RGB): Promise<void>;
|
|
151
|
+
/** Color temperature in Kelvin; the valid range depends on the device (often 2000-9000). */
|
|
152
|
+
setColorTemperature(kelvin: number): Promise<void>;
|
|
153
|
+
/** Colors individual segments of an RGBIC strip. Segment indexes start at 0. */
|
|
154
|
+
setSegmentColor(segments: number[], rgb: RGB): Promise<void>;
|
|
155
|
+
setSegmentBrightness(segments: number[], percent: number): Promise<void>;
|
|
156
|
+
/** Built-in scenes; empty if the device has none (the API would answer 400). */
|
|
157
|
+
getScenes(): Promise<Scene[]>;
|
|
158
|
+
/** DIY scenes made in the Govee Home app; empty if the device doesn't support them. */
|
|
159
|
+
getDiyScenes(): Promise<Scene[]>;
|
|
160
|
+
/** Built-in and DIY scenes together. */
|
|
161
|
+
getAllScenes(): Promise<Scene[]>;
|
|
162
|
+
/** Applies a scene from `getScenes()` / `getDiyScenes()`. */
|
|
163
|
+
setScene(scene: Scene): Promise<void>;
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=cloud.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloud.d.ts","sourceRoot":"","sources":["../src/cloud.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE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wC;IAClC,YAAY,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC,CAGrC;IAED,6DAA6D;IAC7D,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAEpC;CAaF"}
|
package/dist/colors.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export type RGB = readonly [r: number, g: number, b: number];
|
|
2
|
+
export declare const COLORS: {
|
|
3
|
+
readonly white: readonly [255, 255, 255];
|
|
4
|
+
readonly warm_white: readonly [255, 166, 87];
|
|
5
|
+
readonly cool_white: readonly [255, 254, 250];
|
|
6
|
+
readonly black: readonly [0, 0, 0];
|
|
7
|
+
readonly red: readonly [255, 0, 0];
|
|
8
|
+
readonly dark_red: readonly [139, 0, 0];
|
|
9
|
+
readonly light_red: readonly [255, 69, 69];
|
|
10
|
+
readonly green: readonly [0, 255, 0];
|
|
11
|
+
readonly dark_green: readonly [0, 100, 0];
|
|
12
|
+
readonly light_green: readonly [144, 238, 144];
|
|
13
|
+
readonly blue: readonly [0, 0, 255];
|
|
14
|
+
readonly dark_blue: readonly [0, 0, 139];
|
|
15
|
+
readonly light_blue: readonly [173, 216, 230];
|
|
16
|
+
readonly yellow: readonly [255, 255, 0];
|
|
17
|
+
readonly dark_yellow: readonly [184, 134, 11];
|
|
18
|
+
readonly light_yellow: readonly [255, 255, 153];
|
|
19
|
+
readonly orange: readonly [255, 165, 0];
|
|
20
|
+
readonly dark_orange: readonly [255, 140, 0];
|
|
21
|
+
readonly light_orange: readonly [255, 179, 71];
|
|
22
|
+
readonly purple: readonly [128, 0, 128];
|
|
23
|
+
readonly dark_purple: readonly [75, 0, 130];
|
|
24
|
+
readonly light_purple: readonly [218, 112, 214];
|
|
25
|
+
readonly pink: readonly [255, 182, 193];
|
|
26
|
+
readonly dark_pink: readonly [255, 20, 147];
|
|
27
|
+
readonly light_pink: readonly [255, 182, 193];
|
|
28
|
+
readonly brown: readonly [165, 42, 42];
|
|
29
|
+
readonly dark_brown: readonly [139, 69, 19];
|
|
30
|
+
readonly light_brown: readonly [205, 133, 63];
|
|
31
|
+
};
|
|
32
|
+
export type ColorName = keyof typeof COLORS;
|
|
33
|
+
export declare const COLOR_NAMES: ColorName[];
|
|
34
|
+
export declare function isColorName(name: string): name is ColorName;
|
|
35
|
+
/** Looks up a named color (case-insensitive). Returns `undefined` for unknown names. */
|
|
36
|
+
export declare function colorNameToRgb(name: string): RGB | undefined;
|
|
37
|
+
/** Returns the named color closest (by euclidean distance) to the given RGB value. */
|
|
38
|
+
export declare function rgbToColorName(rgb: RGB): ColorName;
|
|
39
|
+
//# sourceMappingURL=colors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colors.d.ts","sourceRoot":"","sources":["../src/colors.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,GAAG,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC;AAE7D,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsCqB,CAAC;AAEzC,MAAM,MAAM,SAAS,GAAG,MAAM,OAAO,MAAM,CAAC;AAE5C,eAAO,MAAM,WAAW,EAA0B,SAAS,EAAE,CAAC;AAE9D,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,SAAS,CAE3D;AAED,wFAAwF;AACxF,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS,CAG5D;AAED,sFAAsF;AACtF,wBAAgB,cAAc,CAAC,GAAG,EAAE,GAAG,GAAG,SAAS,CAYlD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Bluetooth connection/scan timeout in milliseconds. */
|
|
2
|
+
export declare const BT_TIMEOUT = 15000;
|
|
3
|
+
/** Delay after each command so the device can keep up, in milliseconds. */
|
|
4
|
+
export declare const COMMAND_DELAY = 300;
|
|
5
|
+
export declare const BRIGHTNESS_MIN = 0;
|
|
6
|
+
export declare const BRIGHTNESS_MAX = 255;
|
|
7
|
+
/** Standard GAP "Device Name" characteristic. */
|
|
8
|
+
export declare const DEVICE_NAME_UUID = "00002a00-0000-1000-8000-00805f9b34fb";
|
|
9
|
+
/** Govee control service. */
|
|
10
|
+
export declare const SERVICE_UUID = "00010203-0405-0607-0809-0a0b0c0d1910";
|
|
11
|
+
export declare const WRITE_CHARACTERISTIC_UUID = "00010203-0405-0607-0809-0a0b0c0d2b11";
|
|
12
|
+
export declare const READ_CHARACTERISTIC_UUID = "00010203-0405-0607-0809-0a0b0c0d2b10";
|
|
13
|
+
/** Every Govee packet is exactly 20 bytes: 19 bytes of payload plus an XOR checksum. */
|
|
14
|
+
export declare const PACKET_LENGTH = 20;
|
|
15
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,eAAO,MAAM,UAAU,QAAS,CAAC;AAEjC,2EAA2E;AAC3E,eAAO,MAAM,aAAa,MAAM,CAAC;AAEjC,eAAO,MAAM,cAAc,IAAI,CAAC;AAChC,eAAO,MAAM,cAAc,MAAM,CAAC;AAElC,iDAAiD;AACjD,eAAO,MAAM,gBAAgB,yCAAyC,CAAC;AAEvE,6BAA6B;AAC7B,eAAO,MAAM,YAAY,yCAAyC,CAAC;AACnE,eAAO,MAAM,yBAAyB,yCAAyC,CAAC;AAChF,eAAO,MAAM,wBAAwB,yCAAyC,CAAC;AAE/E,wFAAwF;AACxF,eAAO,MAAM,aAAa,KAAK,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type ColorName, type RGB } from "./colors.ts";
|
|
2
|
+
import { type ColorMode } from "./protocol.ts";
|
|
3
|
+
import type { GoveeTransport } from "./transport.ts";
|
|
4
|
+
export type Color = ColorName | RGB | {
|
|
5
|
+
r: number;
|
|
6
|
+
g: number;
|
|
7
|
+
b: number;
|
|
8
|
+
};
|
|
9
|
+
export interface GoveeControllerOptions {
|
|
10
|
+
/** Custom BLE transport. Defaults to `NobleTransport` (requires `@stoprocent/noble`). */
|
|
11
|
+
transport?: GoveeTransport;
|
|
12
|
+
/** Connection/scan timeout in ms, used by the default transport. Default 15000. */
|
|
13
|
+
timeout?: number;
|
|
14
|
+
/** Delay after each command in ms. Default 300. */
|
|
15
|
+
commandDelay?: number;
|
|
16
|
+
/** How long to wait for a status response in ms. Default 3000. */
|
|
17
|
+
responseTimeout?: number;
|
|
18
|
+
/**
|
|
19
|
+
* How this model encodes color commands, see `ColorMode`. Detected automatically by
|
|
20
|
+
* default: from known model names, then from the device's color status, else `"legacy"`.
|
|
21
|
+
*/
|
|
22
|
+
colorMode?: ColorMode;
|
|
23
|
+
/** Receives debug messages. */
|
|
24
|
+
logger?: (message: string) => void;
|
|
25
|
+
}
|
|
26
|
+
export interface SmoothOptions {
|
|
27
|
+
/** Ramp the brightness instead of switching instantly. */
|
|
28
|
+
smooth?: boolean;
|
|
29
|
+
}
|
|
30
|
+
export declare class GoveeController {
|
|
31
|
+
#private;
|
|
32
|
+
readonly address: string;
|
|
33
|
+
name: string | undefined;
|
|
34
|
+
/** Last known state, updated by status queries and successful commands. */
|
|
35
|
+
power: boolean | undefined;
|
|
36
|
+
brightness: number | undefined;
|
|
37
|
+
rgb: RGB | undefined;
|
|
38
|
+
colorName: ColorName | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* @param address MAC address of the device (or the noble peripheral id on macOS).
|
|
41
|
+
*/
|
|
42
|
+
constructor(address: string, options?: GoveeControllerOptions);
|
|
43
|
+
get connected(): boolean;
|
|
44
|
+
/** The color command format in use, or `undefined` until it has been detected. */
|
|
45
|
+
get colorMode(): ColorMode | undefined;
|
|
46
|
+
connect(): Promise<this>;
|
|
47
|
+
disconnect(): Promise<void>;
|
|
48
|
+
/** Enables `await using device = await new GoveeController(...).connect()`. */
|
|
49
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
50
|
+
getPower(): Promise<boolean>;
|
|
51
|
+
getBrightness(): Promise<number>;
|
|
52
|
+
getRgb(): Promise<RGB>;
|
|
53
|
+
turnOn({ smooth }?: SmoothOptions): Promise<void>;
|
|
54
|
+
turnOff({ smooth }?: SmoothOptions): Promise<void>;
|
|
55
|
+
/** Sets brightness, 0-255. */
|
|
56
|
+
setBrightness(brightness: number): Promise<void>;
|
|
57
|
+
/** Sets the color from a name (see `COLOR_NAMES`), an `[r, g, b]` tuple or an `{ r, g, b }` object. */
|
|
58
|
+
setColor(color: Color): Promise<void>;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../src/controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,SAAS,EAAkB,KAAK,GAAG,EAAkB,MAAM,aAAa,CAAC;AAEpG,OAAO,EACL,KAAK,SAAS,EAOf,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD,MAAM,MAAM,KAAK,GAAG,SAAS,GAAG,GAAG,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1E,MAAM,WAAW,sBAAsB;IACrC,yFAAyF;IACzF,SAAS,CAAC,EAAE,cAAc,CAAC;IAC3B,mFAAmF;IACnF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mDAAmD;IACnD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kEAAkE;IAClE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,+BAA+B;IAC/B,MAAM,CAAC,EAAE,CAAC,O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AK,GAAG,OAAO,CAAC,IAAI,CAAC,CAO1C;CA8GF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type { Capability, CapabilityParameters, CapabilityState, CloudDeviceInfo, CloudDeviceState, GoveeCloudOptions, Scene, } from "./cloud.ts";
|
|
2
|
+
export { Capabilities, CLOUD_BASE_URL, CloudDevice, GoveeApiError, GoveeCloud, intToRgb, rgbToInt, } from "./cloud.ts";
|
|
3
|
+
export type { ColorName, RGB } from "./colors.ts";
|
|
4
|
+
export { COLOR_NAMES, COLORS, colorNameToRgb, isColorName, rgbToColorName } from "./colors.ts";
|
|
5
|
+
export * as Constants from "./constants.ts";
|
|
6
|
+
export type { Color, GoveeControllerOptions, SmoothOptions } from "./controller.ts";
|
|
7
|
+
export { GoveeController } from "./controller.ts";
|
|
8
|
+
export type { ColorMode, StatusResponse } from "./protocol.ts";
|
|
9
|
+
export { buildPacket, COLOR_MODES, Commands, checksum, KNOWN_MODEL_COLOR_MODES, modelFromName, parseResponse, toHex, } from "./protocol.ts";
|
|
10
|
+
export type { GoveeTransport } from "./transport.ts";
|
|
11
|
+
export type { DiscoveredLight, NobleTransportOptions } from "./transports/noble.ts";
|
|
12
|
+
export { discoverLights, NobleTransport } from "./transports/noble.ts";
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,UAAU,EACV,oBAAoB,EACpB,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,KAAK,GACN,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,YAAY,EACZ,cAAc,EACd,WAAW,EACX,aAAa,EACb,UAAU,EACV,QAAQ,EACR,QAAQ,GACT,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,cAAc,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC/F,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAC5C,YAAY,EAAE,KAAK,EAAE,sBAAsB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACpF,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,YAAY,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EACL,WAAW,EACX,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,uBAAuB,EACvB,aAAa,EACb,aAAa,EACb,KAAK,GACN,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,YAAY,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AACpF,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC"}
|