@felixgeelhaar/govee-api-client 1.0.0-beta.8
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 +274 -0
- package/dist/GoveeClient.d.ts +35 -0
- package/dist/GoveeClient.d.ts.map +1 -0
- package/dist/GoveeClient.js +97 -0
- package/dist/GoveeClient.js.map +1 -0
- package/dist/domain/entities/Command.d.ts +78 -0
- package/dist/domain/entities/Command.d.ts.map +1 -0
- package/dist/domain/entities/Command.js +119 -0
- package/dist/domain/entities/Command.js.map +1 -0
- package/dist/domain/entities/DeviceState.d.ts +52 -0
- package/dist/domain/entities/DeviceState.d.ts.map +1 -0
- package/dist/domain/entities/DeviceState.js +106 -0
- package/dist/domain/entities/DeviceState.js.map +1 -0
- package/dist/domain/entities/GoveeDevice.d.ts +41 -0
- package/dist/domain/entities/GoveeDevice.d.ts.map +1 -0
- package/dist/domain/entities/GoveeDevice.js +87 -0
- package/dist/domain/entities/GoveeDevice.js.map +1 -0
- package/dist/domain/entities/index.d.ts +4 -0
- package/dist/domain/entities/index.d.ts.map +1 -0
- package/dist/domain/entities/index.js +4 -0
- package/dist/domain/entities/index.js.map +1 -0
- package/dist/domain/repositories/IGoveeDeviceRepository.d.ts +18 -0
- package/dist/domain/repositories/IGoveeDeviceRepository.d.ts.map +1 -0
- package/dist/domain/repositories/IGoveeDeviceRepository.js +2 -0
- package/dist/domain/repositories/IGoveeDeviceRepository.js.map +1 -0
- package/dist/domain/repositories/index.d.ts +2 -0
- package/dist/domain/repositories/index.d.ts.map +1 -0
- package/dist/domain/repositories/index.js +2 -0
- package/dist/domain/repositories/index.js.map +1 -0
- package/dist/domain/value-objects/Brightness.d.ts +27 -0
- package/dist/domain/value-objects/Brightness.d.ts.map +1 -0
- package/dist/domain/value-objects/Brightness.js +69 -0
- package/dist/domain/value-objects/Brightness.js.map +1 -0
- package/dist/domain/value-objects/ColorRgb.d.ts +25 -0
- package/dist/domain/value-objects/ColorRgb.d.ts.map +1 -0
- package/dist/domain/value-objects/ColorRgb.js +55 -0
- package/dist/domain/value-objects/ColorRgb.js.map +1 -0
- package/dist/domain/value-objects/ColorTemperature.d.ts +21 -0
- package/dist/domain/value-objects/ColorTemperature.d.ts.map +1 -0
- package/dist/domain/value-objects/ColorTemperature.js +48 -0
- package/dist/domain/value-objects/ColorTemperature.js.map +1 -0
- package/dist/domain/value-objects/index.d.ts +4 -0
- package/dist/domain/value-objects/index.d.ts.map +1 -0
- package/dist/domain/value-objects/index.js +4 -0
- package/dist/domain/value-objects/index.js.map +1 -0
- package/dist/errors/GoveeApiClientError.d.ts +16 -0
- package/dist/errors/GoveeApiClientError.d.ts.map +1 -0
- package/dist/errors/GoveeApiClientError.js +28 -0
- package/dist/errors/GoveeApiClientError.js.map +1 -0
- package/dist/errors/GoveeApiError.d.ts +26 -0
- package/dist/errors/GoveeApiError.d.ts.map +1 -0
- package/dist/errors/GoveeApiError.js +45 -0
- package/dist/errors/GoveeApiError.js.map +1 -0
- package/dist/errors/InvalidApiKeyError.d.ts +19 -0
- package/dist/errors/InvalidApiKeyError.d.ts.map +1 -0
- package/dist/errors/InvalidApiKeyError.js +22 -0
- package/dist/errors/InvalidApiKeyError.js.map +1 -0
- package/dist/errors/NetworkError.d.ts +20 -0
- package/dist/errors/NetworkError.d.ts.map +1 -0
- package/dist/errors/NetworkError.js +49 -0
- package/dist/errors/NetworkError.js.map +1 -0
- package/dist/errors/RateLimitError.d.ts +27 -0
- package/dist/errors/RateLimitError.d.ts.map +1 -0
- package/dist/errors/RateLimitError.js +68 -0
- package/dist/errors/RateLimitError.js.map +1 -0
- package/dist/errors/index.d.ts +6 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +6 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/infrastructure/GoveeDeviceRepository.d.ts +27 -0
- package/dist/infrastructure/GoveeDeviceRepository.d.ts.map +1 -0
- package/dist/infrastructure/GoveeDeviceRepository.js +168 -0
- package/dist/infrastructure/GoveeDeviceRepository.js.map +1 -0
- package/dist/infrastructure/index.d.ts +2 -0
- package/dist/infrastructure/index.d.ts.map +1 -0
- package/dist/infrastructure/index.js +2 -0
- package/dist/infrastructure/index.js.map +1 -0
- package/dist/services/GoveeControlService.d.ts +88 -0
- package/dist/services/GoveeControlService.d.ts.map +1 -0
- package/dist/services/GoveeControlService.js +175 -0
- package/dist/services/GoveeControlService.js.map +1 -0
- package/dist/services/index.d.ts +2 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +2 -0
- package/dist/services/index.js.map +1 -0
- package/package.json +78 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Felix Geelhaar
|
|
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
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
# Govee API TypeScript Client
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/js/%40felixgeelhaar%2Fgovee-api-client)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://github.com/felixgeelhaar/govee-api-client/actions)
|
|
6
|
+
[](https://codecov.io/gh/felixgeelhaar/govee-api-client)
|
|
7
|
+
|
|
8
|
+
An enterprise-grade TypeScript client library for the Govee Developer REST API. Built with Domain-Driven Design (DDD) principles and comprehensive error handling.
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- 🎯 **Type-Safe**: Full TypeScript support with comprehensive type definitions
|
|
13
|
+
- 🏗️ **Domain-Driven Design**: Clean architecture following DDD principles
|
|
14
|
+
- ⚡ **Rate Limiting**: Built-in rate limiting to prevent API throttling
|
|
15
|
+
- 🛡️ **Error Handling**: Comprehensive error hierarchy with specific error types
|
|
16
|
+
- 📝 **Logging**: Configurable logging with Pino integration
|
|
17
|
+
- 🧪 **Well Tested**: >95% test coverage with unit and integration tests
|
|
18
|
+
- 🚀 **Production Ready**: Enterprise-grade reliability and performance
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @felixgeelhaar/govee-api-client
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import {
|
|
30
|
+
GoveeClient,
|
|
31
|
+
Brightness,
|
|
32
|
+
ColorRgb,
|
|
33
|
+
ColorTemperature,
|
|
34
|
+
} from '@felixgeelhaar/govee-api-client';
|
|
35
|
+
|
|
36
|
+
// Initialize the client
|
|
37
|
+
const client = new GoveeClient({
|
|
38
|
+
apiKey: 'your-govee-api-key',
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// Get all devices
|
|
42
|
+
const devices = await client.getDevices();
|
|
43
|
+
console.log(`Found ${devices.length} devices`);
|
|
44
|
+
|
|
45
|
+
// Find a specific device
|
|
46
|
+
const livingRoomLight = await client.findDeviceByName('Living Room');
|
|
47
|
+
|
|
48
|
+
if (livingRoomLight) {
|
|
49
|
+
// Turn on the light with warm white and 75% brightness
|
|
50
|
+
await client.turnOnWithColorTemperature(
|
|
51
|
+
livingRoomLight.deviceId,
|
|
52
|
+
livingRoomLight.model,
|
|
53
|
+
ColorTemperature.warmWhite(),
|
|
54
|
+
new Brightness(75)
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Configuration
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import pino from 'pino';
|
|
63
|
+
|
|
64
|
+
const client = new GoveeClient({
|
|
65
|
+
apiKey: 'your-govee-api-key',
|
|
66
|
+
timeout: 30000, // Request timeout in milliseconds (default: 30000)
|
|
67
|
+
rateLimit: 100, // Requests per minute (default: 100)
|
|
68
|
+
logger: pino({ level: 'info' }), // Optional logger (silent by default)
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## API Reference
|
|
73
|
+
|
|
74
|
+
### Device Management
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
// Get all devices
|
|
78
|
+
const devices = await client.getDevices();
|
|
79
|
+
|
|
80
|
+
// Get only controllable devices
|
|
81
|
+
const controllableDevices = await client.getControllableDevices();
|
|
82
|
+
|
|
83
|
+
// Find device by name (case-insensitive)
|
|
84
|
+
const device = await client.findDeviceByName('bedroom');
|
|
85
|
+
|
|
86
|
+
// Find devices by model
|
|
87
|
+
const devices = await client.findDevicesByModel('H6159');
|
|
88
|
+
|
|
89
|
+
// Get device state
|
|
90
|
+
const state = await client.getDeviceState(deviceId, model);
|
|
91
|
+
console.log(`Power: ${state.getPowerState()}`);
|
|
92
|
+
console.log(`Online: ${state.isOnline()}`);
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Device Control
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
// Basic controls
|
|
99
|
+
await client.turnOn(deviceId, model);
|
|
100
|
+
await client.turnOff(deviceId, model);
|
|
101
|
+
await client.setBrightness(deviceId, model, new Brightness(75));
|
|
102
|
+
|
|
103
|
+
// Color control
|
|
104
|
+
const red = new ColorRgb(255, 0, 0);
|
|
105
|
+
await client.setColor(deviceId, model, red);
|
|
106
|
+
|
|
107
|
+
const coolWhite = new ColorTemperature(6500);
|
|
108
|
+
await client.setColorTemperature(deviceId, model, coolWhite);
|
|
109
|
+
|
|
110
|
+
// Convenience methods
|
|
111
|
+
await client.turnOnWithBrightness(deviceId, model, new Brightness(50));
|
|
112
|
+
await client.turnOnWithColor(deviceId, model, red, new Brightness(75));
|
|
113
|
+
await client.turnOnWithColorTemperature(deviceId, model, coolWhite, new Brightness(100));
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Value Objects
|
|
117
|
+
|
|
118
|
+
#### ColorRgb
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
// Create RGB colors
|
|
122
|
+
const red = new ColorRgb(255, 0, 0);
|
|
123
|
+
const blue = ColorRgb.fromHex('#0000FF');
|
|
124
|
+
const green = ColorRgb.fromObject({ r: 0, g: 255, b: 0 });
|
|
125
|
+
|
|
126
|
+
console.log(red.toHex()); // "#ff0000"
|
|
127
|
+
console.log(blue.toString()); // "rgb(0, 0, 255)"
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
#### ColorTemperature
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
// Create color temperatures
|
|
134
|
+
const warm = ColorTemperature.warmWhite(); // 2700K
|
|
135
|
+
const cool = ColorTemperature.coolWhite(); // 6500K
|
|
136
|
+
const daylight = ColorTemperature.daylight(); // 5600K
|
|
137
|
+
const custom = new ColorTemperature(4000);
|
|
138
|
+
|
|
139
|
+
console.log(warm.isWarm()); // true
|
|
140
|
+
console.log(cool.isCool()); // true
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
#### Brightness
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
// Create brightness levels
|
|
147
|
+
const dim = Brightness.dim(); // 25%
|
|
148
|
+
const medium = Brightness.medium(); // 50%
|
|
149
|
+
const bright = Brightness.bright(); // 75%
|
|
150
|
+
const custom = new Brightness(85);
|
|
151
|
+
|
|
152
|
+
console.log(bright.asPercent()); // 0.75
|
|
153
|
+
console.log(custom.isDim()); // false
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Error Handling
|
|
157
|
+
|
|
158
|
+
The library provides a comprehensive error hierarchy for different types of failures:
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
import {
|
|
162
|
+
GoveeApiError,
|
|
163
|
+
InvalidApiKeyError,
|
|
164
|
+
RateLimitError,
|
|
165
|
+
NetworkError,
|
|
166
|
+
} from '@felixgeelhaar/govee-api-client';
|
|
167
|
+
|
|
168
|
+
try {
|
|
169
|
+
await client.getDevices();
|
|
170
|
+
} catch (error) {
|
|
171
|
+
if (error instanceof InvalidApiKeyError) {
|
|
172
|
+
console.log('API key is invalid or expired');
|
|
173
|
+
console.log(error.getRecommendation());
|
|
174
|
+
} else if (error instanceof RateLimitError) {
|
|
175
|
+
console.log(`Rate limited. Retry after: ${error.getRetryAfterMs()}ms`);
|
|
176
|
+
} else if (error instanceof GoveeApiError) {
|
|
177
|
+
console.log(`API Error: ${error.message}`);
|
|
178
|
+
if (error.isDeviceOffline()) {
|
|
179
|
+
console.log('Device is currently offline');
|
|
180
|
+
}
|
|
181
|
+
} else if (error instanceof NetworkError) {
|
|
182
|
+
console.log(`Network error: ${error.errorType}`);
|
|
183
|
+
if (error.isRetryable()) {
|
|
184
|
+
console.log('This error can be retried');
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Rate Limiting
|
|
191
|
+
|
|
192
|
+
The client automatically handles rate limiting according to Govee's API limits (100 requests per minute by default). All requests are queued and throttled appropriately.
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
// Customize rate limiting
|
|
196
|
+
const client = new GoveeClient({
|
|
197
|
+
apiKey: 'your-api-key',
|
|
198
|
+
rateLimit: 60, // 60 requests per minute
|
|
199
|
+
});
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## Domain-Driven Design
|
|
203
|
+
|
|
204
|
+
The library follows DDD principles with clear separation of concerns:
|
|
205
|
+
|
|
206
|
+
- **Entities**: `GoveeDevice`, `DeviceState`, `Command`
|
|
207
|
+
- **Value Objects**: `ColorRgb`, `ColorTemperature`, `Brightness`
|
|
208
|
+
- **Repositories**: `IGoveeDeviceRepository`, `GoveeDeviceRepository`
|
|
209
|
+
- **Services**: `GoveeControlService`
|
|
210
|
+
- **Errors**: Comprehensive error hierarchy
|
|
211
|
+
|
|
212
|
+
## Advanced Usage
|
|
213
|
+
|
|
214
|
+
### Custom Repository
|
|
215
|
+
|
|
216
|
+
```typescript
|
|
217
|
+
import { GoveeControlService } from '@felixgeelhaar/govee-api-client';
|
|
218
|
+
|
|
219
|
+
// Use your own repository implementation
|
|
220
|
+
const service = new GoveeControlService({
|
|
221
|
+
repository: new CustomGoveeRepository(),
|
|
222
|
+
rateLimit: 120,
|
|
223
|
+
});
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### Command Pattern
|
|
227
|
+
|
|
228
|
+
```typescript
|
|
229
|
+
import { CommandFactory } from '@felixgeelhaar/govee-api-client';
|
|
230
|
+
|
|
231
|
+
// Create commands manually
|
|
232
|
+
const powerOn = CommandFactory.powerOn();
|
|
233
|
+
const setBrightness = CommandFactory.brightness(new Brightness(75));
|
|
234
|
+
|
|
235
|
+
// Send custom commands
|
|
236
|
+
await client.sendCommand(deviceId, model, powerOn);
|
|
237
|
+
await client.sendCommand(deviceId, model, setBrightness);
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
## Requirements
|
|
241
|
+
|
|
242
|
+
- Node.js 18.0.0 or higher
|
|
243
|
+
- Valid Govee Developer API key
|
|
244
|
+
|
|
245
|
+
## Development
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
# Install dependencies
|
|
249
|
+
npm install
|
|
250
|
+
|
|
251
|
+
# Build the library
|
|
252
|
+
npm run build
|
|
253
|
+
|
|
254
|
+
# Run tests
|
|
255
|
+
npm test
|
|
256
|
+
|
|
257
|
+
# Run tests with coverage
|
|
258
|
+
npm run test:coverage
|
|
259
|
+
|
|
260
|
+
# Type checking
|
|
261
|
+
npm run lint
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
## License
|
|
265
|
+
|
|
266
|
+
MIT © [Felix Geelhaar]
|
|
267
|
+
|
|
268
|
+
## Contributing
|
|
269
|
+
|
|
270
|
+
Contributions are welcome! Please ensure all tests pass and maintain the existing code style.
|
|
271
|
+
|
|
272
|
+
## API Documentation
|
|
273
|
+
|
|
274
|
+
For more information about the Govee Developer API, visit: https://govee-public.s3.amazonaws.com/developer-docs/GoveeDeveloperAPIReference.pdf
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Logger } from 'pino';
|
|
2
|
+
import { GoveeDevice } from './domain/entities/GoveeDevice';
|
|
3
|
+
import { DeviceState } from './domain/entities/DeviceState';
|
|
4
|
+
import { Command } from './domain/entities/Command';
|
|
5
|
+
import { ColorRgb, ColorTemperature, Brightness } from './domain/value-objects';
|
|
6
|
+
export interface GoveeClientConfig {
|
|
7
|
+
apiKey: string;
|
|
8
|
+
timeout?: number;
|
|
9
|
+
rateLimit?: number;
|
|
10
|
+
logger?: Logger;
|
|
11
|
+
}
|
|
12
|
+
export declare class GoveeClient {
|
|
13
|
+
private readonly controlService;
|
|
14
|
+
private readonly logger;
|
|
15
|
+
constructor(config: GoveeClientConfig);
|
|
16
|
+
private validateConfig;
|
|
17
|
+
getDevices(): Promise<GoveeDevice[]>;
|
|
18
|
+
getDeviceState(deviceId: string, model: string): Promise<DeviceState>;
|
|
19
|
+
getControllableDevices(): Promise<GoveeDevice[]>;
|
|
20
|
+
getRetrievableDevices(): Promise<GoveeDevice[]>;
|
|
21
|
+
findDeviceByName(deviceName: string): Promise<GoveeDevice | undefined>;
|
|
22
|
+
findDevicesByModel(model: string): Promise<GoveeDevice[]>;
|
|
23
|
+
sendCommand(deviceId: string, model: string, command: Command): Promise<void>;
|
|
24
|
+
turnOn(deviceId: string, model: string): Promise<void>;
|
|
25
|
+
turnOff(deviceId: string, model: string): Promise<void>;
|
|
26
|
+
setBrightness(deviceId: string, model: string, brightness: Brightness): Promise<void>;
|
|
27
|
+
setColor(deviceId: string, model: string, color: ColorRgb): Promise<void>;
|
|
28
|
+
setColorTemperature(deviceId: string, model: string, colorTemperature: ColorTemperature): Promise<void>;
|
|
29
|
+
turnOnWithBrightness(deviceId: string, model: string, brightness: Brightness): Promise<void>;
|
|
30
|
+
turnOnWithColor(deviceId: string, model: string, color: ColorRgb, brightness?: Brightness): Promise<void>;
|
|
31
|
+
turnOnWithColorTemperature(deviceId: string, model: string, colorTemperature: ColorTemperature, brightness?: Brightness): Promise<void>;
|
|
32
|
+
isDeviceOnline(deviceId: string, model: string): Promise<boolean>;
|
|
33
|
+
isDevicePoweredOn(deviceId: string, model: string): Promise<boolean>;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=GoveeClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GoveeClient.d.ts","sourceRoot":"","sources":["../src/GoveeClient.ts"],"names":[],"mappings":"AAAA,OAAa,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAGpC,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,+BA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,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAIrF,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzE,mBAAmB,CACvB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,gBAAgB,EAAE,gBAAgB,GACjC,OAAO,CAAC,IAAI,CAAC;IAKV,oBAAoB,CACxB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,IAAI,CAAC;IAIV,eAAe,CACnB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,QAAQ,EACf,UAAU,CAAC,EAAE,UAAU,GACtB,OAAO,CAAC,IAAI,CAAC;IAIV,0BAA0B,CAC9B,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,gBAAgB,EAAE,gBAAgB,EAClC,UAAU,CAAC,EAAE,UAAU,GACtB,OAAO,CAAC,IAAI,CAAC;IASV,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIjE,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAG3E"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import pino from 'pino';
|
|
2
|
+
import { GoveeDeviceRepository } from './infrastructure/GoveeDeviceRepository';
|
|
3
|
+
import { GoveeControlService } from './services/GoveeControlService';
|
|
4
|
+
export class GoveeClient {
|
|
5
|
+
constructor(config) {
|
|
6
|
+
this.validateConfig(config);
|
|
7
|
+
// Initialize logger (silent by default)
|
|
8
|
+
this.logger = config.logger ?? pino({ level: 'silent' });
|
|
9
|
+
// Initialize repository
|
|
10
|
+
const repositoryConfig = {
|
|
11
|
+
apiKey: config.apiKey,
|
|
12
|
+
logger: this.logger,
|
|
13
|
+
};
|
|
14
|
+
if (config.timeout !== undefined) {
|
|
15
|
+
repositoryConfig.timeout = config.timeout;
|
|
16
|
+
}
|
|
17
|
+
const repository = new GoveeDeviceRepository(repositoryConfig);
|
|
18
|
+
// Initialize control service
|
|
19
|
+
const serviceConfig = {
|
|
20
|
+
repository,
|
|
21
|
+
logger: this.logger,
|
|
22
|
+
};
|
|
23
|
+
if (config.rateLimit !== undefined) {
|
|
24
|
+
serviceConfig.rateLimit = config.rateLimit;
|
|
25
|
+
}
|
|
26
|
+
this.controlService = new GoveeControlService(serviceConfig);
|
|
27
|
+
this.logger.info('GoveeClient initialized successfully');
|
|
28
|
+
}
|
|
29
|
+
validateConfig(config) {
|
|
30
|
+
if (!config.apiKey || typeof config.apiKey !== 'string' || config.apiKey.trim().length === 0) {
|
|
31
|
+
throw new Error('API key is required and must be a non-empty string');
|
|
32
|
+
}
|
|
33
|
+
if (config.timeout !== undefined &&
|
|
34
|
+
(!Number.isInteger(config.timeout) || config.timeout <= 0)) {
|
|
35
|
+
throw new Error('Timeout must be a positive integer');
|
|
36
|
+
}
|
|
37
|
+
if (config.rateLimit !== undefined &&
|
|
38
|
+
(!Number.isInteger(config.rateLimit) || config.rateLimit <= 0)) {
|
|
39
|
+
throw new Error('Rate limit must be a positive integer');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// Device management methods
|
|
43
|
+
async getDevices() {
|
|
44
|
+
return this.controlService.getDevices();
|
|
45
|
+
}
|
|
46
|
+
async getDeviceState(deviceId, model) {
|
|
47
|
+
return this.controlService.getDeviceState(deviceId, model);
|
|
48
|
+
}
|
|
49
|
+
async getControllableDevices() {
|
|
50
|
+
return this.controlService.getControllableDevices();
|
|
51
|
+
}
|
|
52
|
+
async getRetrievableDevices() {
|
|
53
|
+
return this.controlService.getRetrievableDevices();
|
|
54
|
+
}
|
|
55
|
+
async findDeviceByName(deviceName) {
|
|
56
|
+
return this.controlService.findDeviceByName(deviceName);
|
|
57
|
+
}
|
|
58
|
+
async findDevicesByModel(model) {
|
|
59
|
+
return this.controlService.findDevicesByModel(model);
|
|
60
|
+
}
|
|
61
|
+
// Device control methods
|
|
62
|
+
async sendCommand(deviceId, model, command) {
|
|
63
|
+
return this.controlService.sendCommand(deviceId, model, command);
|
|
64
|
+
}
|
|
65
|
+
async turnOn(deviceId, model) {
|
|
66
|
+
return this.controlService.turnOn(deviceId, model);
|
|
67
|
+
}
|
|
68
|
+
async turnOff(deviceId, model) {
|
|
69
|
+
return this.controlService.turnOff(deviceId, model);
|
|
70
|
+
}
|
|
71
|
+
async setBrightness(deviceId, model, brightness) {
|
|
72
|
+
return this.controlService.setBrightness(deviceId, model, brightness);
|
|
73
|
+
}
|
|
74
|
+
async setColor(deviceId, model, color) {
|
|
75
|
+
return this.controlService.setColor(deviceId, model, color);
|
|
76
|
+
}
|
|
77
|
+
async setColorTemperature(deviceId, model, colorTemperature) {
|
|
78
|
+
return this.controlService.setColorTemperature(deviceId, model, colorTemperature);
|
|
79
|
+
}
|
|
80
|
+
// Convenience methods
|
|
81
|
+
async turnOnWithBrightness(deviceId, model, brightness) {
|
|
82
|
+
return this.controlService.turnOnWithBrightness(deviceId, model, brightness);
|
|
83
|
+
}
|
|
84
|
+
async turnOnWithColor(deviceId, model, color, brightness) {
|
|
85
|
+
return this.controlService.turnOnWithColor(deviceId, model, color, brightness);
|
|
86
|
+
}
|
|
87
|
+
async turnOnWithColorTemperature(deviceId, model, colorTemperature, brightness) {
|
|
88
|
+
return this.controlService.turnOnWithColorTemperature(deviceId, model, colorTemperature, brightness);
|
|
89
|
+
}
|
|
90
|
+
async isDeviceOnline(deviceId, model) {
|
|
91
|
+
return this.controlService.isDeviceOnline(deviceId, model);
|
|
92
|
+
}
|
|
93
|
+
async isDevicePoweredOn(deviceId, model) {
|
|
94
|
+
return this.controlService.isDevicePoweredOn(deviceId, model);
|
|
95
|
+
}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,EAAE,UAAU,CAAC,CAAC;IAC/E,CAAC;IAED,KAAK,CAAC,eAAe,CACnB,QAAgB,EAChB,KAAa,EACb,KAAe,EACf,UAAuB;QAEvB,OAAO,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;IACjF,CAAC;IAED,KAAK,CAAC,0BAA0B,CAC9B,QAAgB,EAChB,KAAa,EACb,gBAAkC,EAClC,UAAuB;QAEvB,OAAO,IAAI,CAAC,cAAc,CAAC,0BAA0B,CACnD,QAAQ,EACR,KAAK,EACL,gBAAgB,EAChB,UAAU,CACX,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,QAAgB,EAAE,KAAa;QAClD,OAAO,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAC7D,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,QAAgB,EAAE,KAAa;QACrD,OAAO,IAAI,CAAC,cAAc,CAAC,iBAAiB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAChE,CAAC;CACF"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { ColorRgb, ColorTemperature, Brightness } from '../value-objects';
|
|
2
|
+
export declare abstract class Command {
|
|
3
|
+
abstract readonly name: string;
|
|
4
|
+
abstract readonly value: unknown;
|
|
5
|
+
abstract toObject(): {
|
|
6
|
+
name: string;
|
|
7
|
+
value: unknown;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export declare class PowerOnCommand extends Command {
|
|
11
|
+
readonly name = "turn";
|
|
12
|
+
readonly value = "on";
|
|
13
|
+
toObject(): {
|
|
14
|
+
name: string;
|
|
15
|
+
value: string;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export declare class PowerOffCommand extends Command {
|
|
19
|
+
readonly name = "turn";
|
|
20
|
+
readonly value = "off";
|
|
21
|
+
toObject(): {
|
|
22
|
+
name: string;
|
|
23
|
+
value: string;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export declare class BrightnessCommand extends Command {
|
|
27
|
+
readonly name = "brightness";
|
|
28
|
+
private readonly _brightness;
|
|
29
|
+
constructor(brightness: Brightness);
|
|
30
|
+
get value(): number;
|
|
31
|
+
get brightness(): Brightness;
|
|
32
|
+
toObject(): {
|
|
33
|
+
name: string;
|
|
34
|
+
value: number;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export declare class ColorCommand extends Command {
|
|
38
|
+
readonly name = "color";
|
|
39
|
+
private readonly _color;
|
|
40
|
+
constructor(color: ColorRgb);
|
|
41
|
+
get value(): {
|
|
42
|
+
r: number;
|
|
43
|
+
g: number;
|
|
44
|
+
b: number;
|
|
45
|
+
};
|
|
46
|
+
get color(): ColorRgb;
|
|
47
|
+
toObject(): {
|
|
48
|
+
name: string;
|
|
49
|
+
value: {
|
|
50
|
+
r: number;
|
|
51
|
+
g: number;
|
|
52
|
+
b: number;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export declare class ColorTemperatureCommand extends Command {
|
|
57
|
+
readonly name = "colorTem";
|
|
58
|
+
private readonly _colorTemperature;
|
|
59
|
+
constructor(colorTemperature: ColorTemperature);
|
|
60
|
+
get value(): number;
|
|
61
|
+
get colorTemperature(): ColorTemperature;
|
|
62
|
+
toObject(): {
|
|
63
|
+
name: string;
|
|
64
|
+
value: number;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export declare class CommandFactory {
|
|
68
|
+
static powerOn(): PowerOnCommand;
|
|
69
|
+
static powerOff(): PowerOffCommand;
|
|
70
|
+
static brightness(brightness: Brightness): BrightnessCommand;
|
|
71
|
+
static color(color: ColorRgb): ColorCommand;
|
|
72
|
+
static colorTemperature(colorTemperature: ColorTemperature): ColorTemperatureCommand;
|
|
73
|
+
static fromObject(obj: {
|
|
74
|
+
name: string;
|
|
75
|
+
value: unknown;
|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from '../value-objects';
|
|
2
|
+
export class Command {
|
|
3
|
+
}
|
|
4
|
+
export class PowerOnCommand extends Command {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
|
+
this.name = 'turn';
|
|
8
|
+
this.value = 'on';
|
|
9
|
+
}
|
|
10
|
+
toObject() {
|
|
11
|
+
return { name: this.name, value: this.value };
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export class PowerOffCommand extends Command {
|
|
15
|
+
constructor() {
|
|
16
|
+
super(...arguments);
|
|
17
|
+
this.name = 'turn';
|
|
18
|
+
this.value = 'off';
|
|
19
|
+
}
|
|
20
|
+
toObject() {
|
|
21
|
+
return { name: this.name, value: this.value };
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export class BrightnessCommand extends Command {
|
|
25
|
+
constructor(brightness) {
|
|
26
|
+
super();
|
|
27
|
+
this.name = 'brightness';
|
|
28
|
+
this._brightness = brightness;
|
|
29
|
+
}
|
|
30
|
+
get value() {
|
|
31
|
+
return this._brightness.level;
|
|
32
|
+
}
|
|
33
|
+
get brightness() {
|
|
34
|
+
return this._brightness;
|
|
35
|
+
}
|
|
36
|
+
toObject() {
|
|
37
|
+
return { name: this.name, value: this.value };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export class ColorCommand extends Command {
|
|
41
|
+
constructor(color) {
|
|
42
|
+
super();
|
|
43
|
+
this.name = 'color';
|
|
44
|
+
this._color = color;
|
|
45
|
+
}
|
|
46
|
+
get value() {
|
|
47
|
+
return this._color.toObject();
|
|
48
|
+
}
|
|
49
|
+
get color() {
|
|
50
|
+
return this._color;
|
|
51
|
+
}
|
|
52
|
+
toObject() {
|
|
53
|
+
return { name: this.name, value: this.value };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export class ColorTemperatureCommand extends Command {
|
|
57
|
+
constructor(colorTemperature) {
|
|
58
|
+
super();
|
|
59
|
+
this.name = 'colorTem';
|
|
60
|
+
this._colorTemperature = colorTemperature;
|
|
61
|
+
}
|
|
62
|
+
get value() {
|
|
63
|
+
return this._colorTemperature.kelvin;
|
|
64
|
+
}
|
|
65
|
+
get colorTemperature() {
|
|
66
|
+
return this._colorTemperature;
|
|
67
|
+
}
|
|
68
|
+
toObject() {
|
|
69
|
+
return { name: this.name, value: this.value };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export class CommandFactory {
|
|
73
|
+
static powerOn() {
|
|
74
|
+
return new PowerOnCommand();
|
|
75
|
+
}
|
|
76
|
+
static powerOff() {
|
|
77
|
+
return new PowerOffCommand();
|
|
78
|
+
}
|
|
79
|
+
static brightness(brightness) {
|
|
80
|
+
return new BrightnessCommand(brightness);
|
|
81
|
+
}
|
|
82
|
+
static color(color) {
|
|
83
|
+
return new ColorCommand(color);
|
|
84
|
+
}
|
|
85
|
+
static colorTemperature(colorTemperature) {
|
|
86
|
+
return new ColorTemperatureCommand(colorTemperature);
|
|
87
|
+
}
|
|
88
|
+
static fromObject(obj) {
|
|
89
|
+
switch (obj.name) {
|
|
90
|
+
case 'turn':
|
|
91
|
+
if (obj.value === 'on') {
|
|
92
|
+
return new PowerOnCommand();
|
|
93
|
+
}
|
|
94
|
+
else if (obj.value === 'off') {
|
|
95
|
+
return new PowerOffCommand();
|
|
96
|
+
}
|
|
97
|
+
throw new Error(`Invalid power command value: ${obj.value}`);
|
|
98
|
+
case 'brightness':
|
|
99
|
+
if (typeof obj.value === 'number') {
|
|
100
|
+
return new BrightnessCommand(new Brightness(obj.value));
|
|
101
|
+
}
|
|
102
|
+
throw new Error(`Invalid brightness command value: ${obj.value}`);
|
|
103
|
+
case 'color':
|
|
104
|
+
if (typeof obj.value === 'object' && obj.value !== null) {
|
|
105
|
+
const colorValue = obj.value;
|
|
106
|
+
return new ColorCommand(ColorRgb.fromObject(colorValue));
|
|
107
|
+
}
|
|
108
|
+
throw new Error(`Invalid color command value: ${obj.value}`);
|
|
109
|
+
case 'colorTem':
|
|
110
|
+
if (typeof obj.value === 'number') {
|
|
111
|
+
return new ColorTemperatureCommand(new ColorTemperature(obj.value));
|
|
112
|
+
}
|
|
113
|
+
throw new Error(`Invalid color temperature command value: ${obj.value}`);
|
|
114
|
+
default:
|
|
115
|
+
throw new Error(`Unknown command name: ${obj.name}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=Command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Command.js","sourceRoot":"","sources":["../../../src/domain/entities/Command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE1E,MAAM,OAAgB,OAAO;CAK5B;AAED,MAAM,OAAO,cAAe,SAAQ,OAAO;IAA3C;;QACW,SAAI,GAAG,MAAM,CAAC;QACd,UAAK,GAAG,IAAI,CAAC;IAKxB,CAAC;IAHC,QAAQ;QACN,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;IAChD,CAAC;CACF;AAED,MAAM,OAAO,eAAgB,SAAQ,OAAO;IAA5C;;QACW,SAAI,GAAG,MAAM,CAAC;QACd,UAAK,GAAG,KAAK,CAAC;IAKzB,CAAC;IAHC,QAAQ;QACN,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;IAChD,CAAC;CACF;AAED,MAAM,OAAO,iBAAkB,SAAQ,OAAO;IAI5C,YAAY,UAAsB;QAChC,KAAK,EAAE,CAAC;QAJD,SAAI,GAAG,YAAY,CAAC;QAK3B,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;IAChC,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC;IAChC,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,IAAI,CA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