@felixgeelhaar/govee-api-client 1.1.0 → 2.0.1

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.
Files changed (68) hide show
  1. package/README.md +160 -7
  2. package/dist/GoveeClient.d.ts +31 -0
  3. package/dist/GoveeClient.d.ts.map +1 -1
  4. package/dist/GoveeClient.js +33 -0
  5. package/dist/GoveeClient.js.map +1 -1
  6. package/dist/errors/GoveeApiError.d.ts +1 -1
  7. package/dist/errors/GoveeApiError.d.ts.map +1 -1
  8. package/dist/errors/GoveeApiError.js +9 -2
  9. package/dist/errors/GoveeApiError.js.map +1 -1
  10. package/dist/errors/ValidationError.d.ts +28 -0
  11. package/dist/errors/ValidationError.d.ts.map +1 -0
  12. package/dist/errors/ValidationError.js +44 -0
  13. package/dist/errors/ValidationError.js.map +1 -0
  14. package/dist/errors/index.d.ts +1 -0
  15. package/dist/errors/index.d.ts.map +1 -1
  16. package/dist/errors/index.js +1 -0
  17. package/dist/errors/index.js.map +1 -1
  18. package/dist/index.d.ts +1 -0
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +2 -0
  21. package/dist/index.js.map +1 -1
  22. package/dist/infrastructure/GoveeDeviceRepository.d.ts.map +1 -1
  23. package/dist/infrastructure/GoveeDeviceRepository.js +26 -3
  24. package/dist/infrastructure/GoveeDeviceRepository.js.map +1 -1
  25. package/dist/infrastructure/SlidingWindowRateLimiter.d.ts +83 -0
  26. package/dist/infrastructure/SlidingWindowRateLimiter.d.ts.map +1 -0
  27. package/dist/infrastructure/SlidingWindowRateLimiter.js +218 -0
  28. package/dist/infrastructure/SlidingWindowRateLimiter.js.map +1 -0
  29. package/dist/infrastructure/index.d.ts +2 -0
  30. package/dist/infrastructure/index.d.ts.map +1 -1
  31. package/dist/infrastructure/index.js +2 -0
  32. package/dist/infrastructure/index.js.map +1 -1
  33. package/dist/infrastructure/response-schemas.d.ts +82 -0
  34. package/dist/infrastructure/response-schemas.d.ts.map +1 -0
  35. package/dist/infrastructure/response-schemas.js +59 -0
  36. package/dist/infrastructure/response-schemas.js.map +1 -0
  37. package/dist/infrastructure/retry/IntegrationGuide.d.ts +133 -0
  38. package/dist/infrastructure/retry/IntegrationGuide.d.ts.map +1 -0
  39. package/dist/infrastructure/retry/IntegrationGuide.js +295 -0
  40. package/dist/infrastructure/retry/IntegrationGuide.js.map +1 -0
  41. package/dist/infrastructure/retry/RetryConfigPresets.d.ts +114 -0
  42. package/dist/infrastructure/retry/RetryConfigPresets.d.ts.map +1 -0
  43. package/dist/infrastructure/retry/RetryConfigPresets.js +406 -0
  44. package/dist/infrastructure/retry/RetryConfigPresets.js.map +1 -0
  45. package/dist/infrastructure/retry/RetryPolicy.d.ts +148 -0
  46. package/dist/infrastructure/retry/RetryPolicy.d.ts.map +1 -0
  47. package/dist/infrastructure/retry/RetryPolicy.js +373 -0
  48. package/dist/infrastructure/retry/RetryPolicy.js.map +1 -0
  49. package/dist/infrastructure/retry/RetryableRepository.d.ts +75 -0
  50. package/dist/infrastructure/retry/RetryableRepository.d.ts.map +1 -0
  51. package/dist/infrastructure/retry/RetryableRepository.js +142 -0
  52. package/dist/infrastructure/retry/RetryableRepository.js.map +1 -0
  53. package/dist/infrastructure/retry/RetryableRequest.d.ts +132 -0
  54. package/dist/infrastructure/retry/RetryableRequest.d.ts.map +1 -0
  55. package/dist/infrastructure/retry/RetryableRequest.js +248 -0
  56. package/dist/infrastructure/retry/RetryableRequest.js.map +1 -0
  57. package/dist/infrastructure/retry/index.d.ts +35 -0
  58. package/dist/infrastructure/retry/index.d.ts.map +1 -0
  59. package/dist/infrastructure/retry/index.js +36 -0
  60. package/dist/infrastructure/retry/index.js.map +1 -0
  61. package/dist/services/GoveeControlService.d.ts +53 -0
  62. package/dist/services/GoveeControlService.d.ts.map +1 -1
  63. package/dist/services/GoveeControlService.js +138 -12
  64. package/dist/services/GoveeControlService.js.map +1 -1
  65. package/docs/EXAMPLES.md +799 -0
  66. package/docs/LLM_API_REFERENCE.md +425 -0
  67. package/docs/TYPE_DEFINITIONS.md +803 -0
  68. package/package.json +25 -16
@@ -0,0 +1,803 @@
1
+ # Govee API Client - Type Definitions
2
+
3
+ This document provides comprehensive type definitions for the Govee API Client library. All types are fully documented with TypeScript definitions.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Configuration Types](#configuration-types)
8
+ - [Domain Entity Types](#domain-entity-types)
9
+ - [Value Object Types](#value-object-types)
10
+ - [Command Types](#command-types)
11
+ - [State Types](#state-types)
12
+ - [Error Types](#error-types)
13
+ - [Retry & Rate Limiting Types](#retry--rate-limiting-types)
14
+ - [Utility Types](#utility-types)
15
+
16
+ ## Configuration Types
17
+
18
+ ### GoveeClientConfig
19
+
20
+ Main configuration interface for initializing the GoveeClient.
21
+
22
+ ```typescript
23
+ interface GoveeClientConfig {
24
+ apiKey: string; // Required: Govee API key
25
+ timeout?: number; // Optional: Request timeout in milliseconds (default: 30000)
26
+ rateLimit?: number; // Optional: Max requests per minute (default: 95)
27
+ logger?: Logger; // Optional: Pino logger instance
28
+ enableRetries?: boolean; // Optional: Enable retry logic (default: false)
29
+ retryPolicy?: RetryPolicyType; // Optional: Retry policy configuration
30
+ }
31
+
32
+ type RetryPolicyType = 'development' | 'testing' | 'production' | 'custom' | RetryPolicy;
33
+ ```
34
+
35
+ ### GoveeControlServiceConfig
36
+
37
+ Configuration for the internal control service.
38
+
39
+ ```typescript
40
+ interface GoveeControlServiceConfig {
41
+ repository: IGoveeDeviceRepository;
42
+ logger?: Logger;
43
+ rateLimit?: number;
44
+ enableRetries?: boolean;
45
+ retryPolicy?: RetryPolicyType;
46
+ }
47
+ ```
48
+
49
+ ### GoveeDeviceRepositoryConfig
50
+
51
+ Configuration for the device repository.
52
+
53
+ ```typescript
54
+ interface GoveeDeviceRepositoryConfig {
55
+ apiKey: string;
56
+ timeout?: number;
57
+ logger?: Logger;
58
+ }
59
+ ```
60
+
61
+ ## Domain Entity Types
62
+
63
+ ### GoveeDevice
64
+
65
+ Represents a Govee smart device.
66
+
67
+ ```typescript
68
+ class GoveeDevice {
69
+ readonly deviceId: string;
70
+ readonly model: string; // Alias for sku (backward compatibility)
71
+ readonly sku: string;
72
+ readonly deviceName: string;
73
+ readonly controllable: boolean;
74
+ readonly retrievable: boolean;
75
+ readonly supportedCmds: readonly string[];
76
+ readonly capabilities: readonly GoveeCapability[];
77
+
78
+ equals(other: GoveeDevice): boolean;
79
+ supportsCommand(command: string): boolean;
80
+ canControl(): boolean;
81
+ canRetrieve(): boolean;
82
+ toString(): string;
83
+ toObject(): DeviceObject;
84
+ static fromObject(obj: DeviceObject): GoveeDevice;
85
+ }
86
+
87
+ interface DeviceObject {
88
+ deviceId: string;
89
+ model: string;
90
+ deviceName: string;
91
+ controllable: boolean;
92
+ retrievable: boolean;
93
+ supportedCmds: string[];
94
+ }
95
+
96
+ interface GoveeCapability {
97
+ type: string;
98
+ instance: string;
99
+ parameters?: {
100
+ dataType: string;
101
+ options?: Array<{
102
+ name: string;
103
+ value: unknown;
104
+ }>;
105
+ };
106
+ }
107
+ ```
108
+
109
+ ### DeviceState
110
+
111
+ Represents the current state of a device.
112
+
113
+ ```typescript
114
+ class DeviceState {
115
+ readonly deviceId: string;
116
+ readonly model: string;
117
+ readonly properties: readonly StateProperty[];
118
+
119
+ getPowerState(): PowerState | undefined;
120
+ getBrightness(): number | undefined; // 0-100
121
+ getColor(): ColorState | undefined;
122
+ getColorTemperature(): number | undefined; // Kelvin
123
+ isOnline(): boolean;
124
+ hasProperty(type: string, instance: string): boolean;
125
+ getProperty(type: string, instance: string): StateProperty | undefined;
126
+ }
127
+
128
+ interface StateProperty {
129
+ type: string;
130
+ instance: string;
131
+ value: unknown;
132
+ }
133
+
134
+ type PowerState = 'on' | 'off';
135
+ type ColorState = { r: number; g: number; b: number };
136
+ type ColorTemperatureState = number; // Kelvin
137
+ type BrightnessState = number; // 0-100
138
+ ```
139
+
140
+ ### Command Types
141
+
142
+ Base command class and specific command implementations.
143
+
144
+ ```typescript
145
+ abstract class Command {
146
+ abstract readonly name: string;
147
+ abstract readonly value: unknown;
148
+ abstract toApiFormat(): { name: string; value: unknown };
149
+ }
150
+
151
+ class PowerOnCommand extends Command {
152
+ readonly name = 'turn';
153
+ readonly value = 1;
154
+ toApiFormat(): { name: string; value: number };
155
+ }
156
+
157
+ class PowerOffCommand extends Command {
158
+ readonly name = 'turn';
159
+ readonly value = 0;
160
+ toApiFormat(): { name: string; value: number };
161
+ }
162
+
163
+ class BrightnessCommand extends Command {
164
+ readonly name = 'brightness';
165
+ readonly value: number;
166
+ constructor(brightness: Brightness);
167
+ toApiFormat(): { name: string; value: number };
168
+ }
169
+
170
+ class ColorCommand extends Command {
171
+ readonly name = 'color';
172
+ readonly value: { r: number; g: number; b: number };
173
+ constructor(color: ColorRgb);
174
+ toApiFormat(): { name: string; value: { r: number; g: number; b: number } };
175
+ }
176
+
177
+ class ColorTemperatureCommand extends Command {
178
+ readonly name = 'colorTem';
179
+ readonly value: number;
180
+ constructor(colorTemperature: ColorTemperature);
181
+ toApiFormat(): { name: string; value: number };
182
+ }
183
+ ```
184
+
185
+ ### CommandFactory
186
+
187
+ Static factory for creating commands.
188
+
189
+ ```typescript
190
+ class CommandFactory {
191
+ static powerOn(): PowerOnCommand;
192
+ static powerOff(): PowerOffCommand;
193
+ static brightness(brightness: Brightness): BrightnessCommand;
194
+ static color(color: ColorRgb): ColorCommand;
195
+ static colorTemperature(temp: ColorTemperature): ColorTemperatureCommand;
196
+ }
197
+ ```
198
+
199
+ ## Value Object Types
200
+
201
+ ### ColorRgb
202
+
203
+ Represents RGB color values (0-255 per component).
204
+
205
+ ```typescript
206
+ class ColorRgb {
207
+ readonly r: number; // 0-255
208
+ readonly g: number; // 0-255
209
+ readonly b: number; // 0-255
210
+
211
+ constructor(r: number, g: number, b: number);
212
+ equals(other: ColorRgb): boolean;
213
+ toString(): string; // "rgb(r, g, b)"
214
+ toHex(): string; // "#rrggbb"
215
+ toObject(): ColorRgbObject;
216
+
217
+ static fromHex(hex: string): ColorRgb;
218
+ static fromObject(obj: ColorRgbObject): ColorRgb;
219
+ }
220
+
221
+ interface ColorRgbObject {
222
+ r: number;
223
+ g: number;
224
+ b: number;
225
+ }
226
+ ```
227
+
228
+ ### ColorTemperature
229
+
230
+ Represents color temperature in Kelvin (2000-9000K).
231
+
232
+ ```typescript
233
+ class ColorTemperature {
234
+ readonly kelvin: number; // 2000-9000
235
+
236
+ constructor(kelvin: number);
237
+ equals(other: ColorTemperature): boolean;
238
+ toString(): string;
239
+ isWarm(): boolean; // < 4000K
240
+ isCool(): boolean; // > 5000K
241
+ toObject(): ColorTemperatureObject;
242
+
243
+ static warmWhite(): ColorTemperature; // 2700K
244
+ static coolWhite(): ColorTemperature; // 6500K
245
+ static daylight(): ColorTemperature; // 5600K
246
+ static fromObject(obj: ColorTemperatureObject): ColorTemperature;
247
+ }
248
+
249
+ interface ColorTemperatureObject {
250
+ kelvin: number;
251
+ }
252
+ ```
253
+
254
+ ### Brightness
255
+
256
+ Represents brightness level (0-100).
257
+
258
+ ```typescript
259
+ class Brightness {
260
+ readonly level: number; // 0-100
261
+
262
+ constructor(level: number);
263
+ equals(other: Brightness): boolean;
264
+ toString(): string;
265
+ asPercent(): number; // 0.0-1.0
266
+ isDim(): boolean; // < 30
267
+ isBright(): boolean; // > 70
268
+ toObject(): BrightnessObject;
269
+
270
+ static dim(): Brightness; // 25
271
+ static medium(): Brightness; // 50
272
+ static bright(): Brightness; // 75
273
+ static fromObject(obj: BrightnessObject): Brightness;
274
+ }
275
+
276
+ interface BrightnessObject {
277
+ level: number;
278
+ }
279
+ ```
280
+
281
+ ## Error Types
282
+
283
+ ### Error Hierarchy
284
+
285
+ Complete error class hierarchy with TypeScript types.
286
+
287
+ ```typescript
288
+ abstract class GoveeApiClientError extends Error {
289
+ abstract readonly errorType: string;
290
+ abstract isRetryable(): boolean;
291
+
292
+ constructor(message: string);
293
+ }
294
+
295
+ class GoveeApiError extends GoveeApiClientError {
296
+ readonly errorType = 'GoveeApiError';
297
+ readonly statusCode?: number;
298
+ readonly response?: unknown;
299
+
300
+ constructor(message: string, statusCode?: number, response?: unknown);
301
+ isRetryable(): boolean;
302
+ isDeviceOffline(): boolean;
303
+ getRecommendation(): string;
304
+ }
305
+
306
+ class InvalidApiKeyError extends GoveeApiClientError {
307
+ readonly errorType = 'InvalidApiKeyError';
308
+
309
+ constructor(message: string);
310
+ isRetryable(): false;
311
+ getRecommendation(): string;
312
+ }
313
+
314
+ class RateLimitError extends GoveeApiClientError {
315
+ readonly errorType = 'RateLimitError';
316
+ readonly retryAfterMs?: number;
317
+
318
+ constructor(message: string, retryAfterMs?: number);
319
+ isRetryable(): true;
320
+ getRetryAfterMs(): number;
321
+ }
322
+
323
+ class NetworkError extends GoveeApiClientError {
324
+ readonly errorType = 'NetworkError';
325
+ readonly cause?: Error;
326
+
327
+ constructor(message: string, cause?: Error);
328
+ isRetryable(): boolean;
329
+ }
330
+
331
+ class ValidationError extends GoveeApiClientError {
332
+ readonly errorType = 'ValidationError';
333
+ readonly field?: string;
334
+ readonly value?: unknown;
335
+
336
+ constructor(message: string, field?: string, value?: unknown);
337
+ isRetryable(): false;
338
+ }
339
+ ```
340
+
341
+ ### Error Type Guards
342
+
343
+ TypeScript type guards for error handling.
344
+
345
+ ```typescript
346
+ function isGoveeApiError(error: unknown): error is GoveeApiError;
347
+ function isInvalidApiKeyError(error: unknown): error is InvalidApiKeyError;
348
+ function isRateLimitError(error: unknown): error is RateLimitError;
349
+ function isNetworkError(error: unknown): error is NetworkError;
350
+ function isValidationError(error: unknown): error is ValidationError;
351
+ ```
352
+
353
+ ## Retry & Rate Limiting Types
354
+
355
+ ### RetryPolicy
356
+
357
+ Configuration for retry behavior.
358
+
359
+ ```typescript
360
+ class RetryPolicy {
361
+ constructor(config: RetryPolicyConfig);
362
+ }
363
+
364
+ interface RetryPolicyConfig {
365
+ backoff: BackoffStrategy;
366
+ jitter: JitterConfig;
367
+ condition: RetryCondition;
368
+ circuitBreaker: CircuitBreakerConfig;
369
+ enableMetrics: boolean;
370
+ }
371
+
372
+ interface BackoffStrategy {
373
+ type: 'exponential' | 'linear' | 'constant';
374
+ initialDelayMs: number;
375
+ maxDelayMs: number;
376
+ multiplier?: number; // For exponential backoff
377
+ increment?: number; // For linear backoff
378
+ }
379
+
380
+ interface JitterConfig {
381
+ type: 'none' | 'full' | 'equal' | 'decorrelated';
382
+ factor?: number; // 0.0-1.0, randomization factor
383
+ }
384
+
385
+ interface RetryCondition {
386
+ maxAttempts: number;
387
+ maxTotalTimeMs: number;
388
+ retryableStatusCodes: number[];
389
+ retryableErrorTypes: (new (...args: any[]) => Error)[];
390
+ }
391
+
392
+ interface CircuitBreakerConfig {
393
+ enabled: boolean;
394
+ failureThreshold: number; // Failures before opening
395
+ recoveryTimeoutMs: number; // Time before trying half-open
396
+ halfOpenSuccessThreshold: number; // Successes needed to close
397
+ }
398
+ ```
399
+
400
+ ### RetryMetrics
401
+
402
+ Metrics for monitoring retry behavior.
403
+
404
+ ```typescript
405
+ interface RetryMetrics {
406
+ totalAttempts: number;
407
+ successfulRetries: number;
408
+ failedRetries: number;
409
+ totalRetryTimeMs: number;
410
+ averageRetryDelayMs: number;
411
+ circuitBreakerState: CircuitBreakerState;
412
+ lastError?: Error;
413
+ lastRetryTimestamp?: Date;
414
+ }
415
+
416
+ type CircuitBreakerState = 'closed' | 'open' | 'half-open';
417
+ ```
418
+
419
+ ### Rate Limiter Types
420
+
421
+ Types for rate limiting functionality.
422
+
423
+ ```typescript
424
+ interface RateLimiterStats {
425
+ currentRequests: number;
426
+ maxRequests: number;
427
+ utilizationPercent: number;
428
+ queueSize: number;
429
+ canExecuteImmediately: boolean;
430
+ nextAvailableSlot: Date | null;
431
+ }
432
+
433
+ interface ServiceStats {
434
+ rateLimiter: RateLimiterStats;
435
+ retries?: RetryMetrics;
436
+ configuration: ServiceConfiguration;
437
+ }
438
+
439
+ interface ServiceConfiguration {
440
+ rateLimit: number;
441
+ timeout: number;
442
+ retriesEnabled: boolean;
443
+ retryPolicy?: string;
444
+ }
445
+ ```
446
+
447
+ ## Repository Types
448
+
449
+ ### IGoveeDeviceRepository
450
+
451
+ Interface for device repository implementations.
452
+
453
+ ```typescript
454
+ interface IGoveeDeviceRepository {
455
+ findAll(): Promise<GoveeDevice[]>;
456
+ findState(deviceId: string, model: string): Promise<DeviceState>;
457
+ sendCommand(deviceId: string, model: string, command: Command): Promise<void>;
458
+ }
459
+ ```
460
+
461
+ ### API Response Types
462
+
463
+ Internal types for API responses (used by repository).
464
+
465
+ ```typescript
466
+ interface DevicesResponse {
467
+ code: number;
468
+ message: string;
469
+ data: {
470
+ devices: DeviceData[];
471
+ };
472
+ }
473
+
474
+ interface DeviceData {
475
+ device: string; // deviceId
476
+ sku: string; // model
477
+ deviceName: string;
478
+ capabilities: GoveeCapability[];
479
+ }
480
+
481
+ interface StateResponse {
482
+ code: number;
483
+ message: string;
484
+ data: {
485
+ device: string;
486
+ sku: string;
487
+ capabilities: StateCapability[];
488
+ };
489
+ }
490
+
491
+ interface StateCapability {
492
+ type: string;
493
+ instance: string;
494
+ state: {
495
+ value: unknown;
496
+ };
497
+ }
498
+
499
+ interface CommandResponse {
500
+ code: number;
501
+ message: string;
502
+ data: Record<string, unknown>;
503
+ }
504
+
505
+ interface ApiErrorResponse {
506
+ code: number;
507
+ message: string;
508
+ data?: unknown;
509
+ }
510
+ ```
511
+
512
+ ## Utility Types
513
+
514
+ ### Generic Utility Types
515
+
516
+ Helpful TypeScript utility types.
517
+
518
+ ```typescript
519
+ // Extract device ID type
520
+ type DeviceId = GoveeDevice['deviceId'];
521
+
522
+ // Extract model type
523
+ type DeviceModel = GoveeDevice['model'];
524
+
525
+ // Extract supported command types
526
+ type SupportedCommand = GoveeDevice['supportedCmds'][number];
527
+
528
+ // Extract power state union
529
+ type PowerState = ReturnType<DeviceState['getPowerState']>;
530
+
531
+ // Extract color object type
532
+ type ColorObject = NonNullable<ReturnType<DeviceState['getColor']>>;
533
+
534
+ // Configuration with required API key
535
+ type RequiredApiKeyConfig = Required<Pick<GoveeClientConfig, 'apiKey'>> &
536
+ Partial<Omit<GoveeClientConfig, 'apiKey'>>;
537
+
538
+ // Partial device for updates
539
+ type PartialDevice = Partial<Pick<GoveeDevice, 'deviceName' | 'controllable' | 'retrievable'>>;
540
+
541
+ // Command name union type
542
+ type CommandName = Command['name'];
543
+
544
+ // Command value type
545
+ type CommandValue = Command['value'];
546
+ ```
547
+
548
+ ### Async Return Types
549
+
550
+ Types for async method return values.
551
+
552
+ ```typescript
553
+ // Device list operations
554
+ type DeviceListResult = Promise<GoveeDevice[]>;
555
+ type DeviceSearchResult = Promise<GoveeDevice | undefined>;
556
+ type DeviceFilterResult = Promise<GoveeDevice[]>;
557
+
558
+ // Device control operations
559
+ type ControlResult = Promise<void>;
560
+ type StateResult = Promise<DeviceState>;
561
+ type StatusResult = Promise<boolean>;
562
+
563
+ // Monitoring operations
564
+ type StatsResult = RateLimiterStats;
565
+ type MetricsResult = RetryMetrics | undefined;
566
+ type ServiceStatsResult = ServiceStats;
567
+ ```
568
+
569
+ ### Event Types
570
+
571
+ Types for potential event handling (future extension).
572
+
573
+ ```typescript
574
+ interface DeviceEvent {
575
+ type: 'state-changed' | 'offline' | 'online' | 'error';
576
+ deviceId: string;
577
+ model: string;
578
+ timestamp: Date;
579
+ data?: unknown;
580
+ }
581
+
582
+ interface RateLimitEvent {
583
+ type: 'limit-reached' | 'limit-warning' | 'queue-full';
584
+ timestamp: Date;
585
+ stats: RateLimiterStats;
586
+ }
587
+
588
+ interface RetryEvent {
589
+ type: 'retry-attempt' | 'retry-success' | 'retry-failure' | 'circuit-breaker';
590
+ timestamp: Date;
591
+ attempt: number;
592
+ delay: number;
593
+ error?: Error;
594
+ }
595
+ ```
596
+
597
+ ### Type Predicates
598
+
599
+ Type guard functions for runtime type checking.
600
+
601
+ ```typescript
602
+ // Device type guards
603
+ function isGoveeDevice(obj: unknown): obj is GoveeDevice;
604
+ function isDeviceState(obj: unknown): obj is DeviceState;
605
+ function isCommand(obj: unknown): obj is Command;
606
+
607
+ // Value object type guards
608
+ function isColorRgb(obj: unknown): obj is ColorRgb;
609
+ function isColorTemperature(obj: unknown): obj is ColorTemperature;
610
+ function isBrightness(obj: unknown): obj is Brightness;
611
+
612
+ // Configuration type guards
613
+ function isValidClientConfig(obj: unknown): obj is GoveeClientConfig;
614
+ function isValidRetryPolicy(obj: unknown): obj is RetryPolicy;
615
+
616
+ // State property type guards
617
+ function isPowerProperty(prop: StateProperty): prop is StateProperty & { value: 0 | 1 };
618
+ function isBrightnessProperty(prop: StateProperty): prop is StateProperty & { value: number };
619
+ function isColorProperty(prop: StateProperty): prop is StateProperty & { value: ColorState };
620
+ ```
621
+
622
+ ### Branded Types
623
+
624
+ Branded types for additional type safety.
625
+
626
+ ```typescript
627
+ // Branded string types for IDs
628
+ type DeviceId = string & { readonly __brand: 'DeviceId' };
629
+ type ModelId = string & { readonly __brand: 'ModelId' };
630
+ type ApiKey = string & { readonly __brand: 'ApiKey' };
631
+
632
+ // Branded number types for values
633
+ type KelvinValue = number & { readonly __brand: 'Kelvin' };
634
+ type BrightnessValue = number & { readonly __brand: 'Brightness' };
635
+ type RgbValue = number & { readonly __brand: 'RgbComponent' };
636
+
637
+ // Type constructors
638
+ function createDeviceId(id: string): DeviceId;
639
+ function createModelId(model: string): ModelId;
640
+ function createApiKey(key: string): ApiKey;
641
+ function createKelvinValue(kelvin: number): KelvinValue;
642
+ function createBrightnessValue(brightness: number): BrightnessValue;
643
+ function createRgbValue(rgb: number): RgbValue;
644
+ ```
645
+
646
+ ### Template Literal Types
647
+
648
+ Template literal types for command names and property types.
649
+
650
+ ```typescript
651
+ // Command name templates
652
+ type PowerCommand = `turn_${string}`;
653
+ type ColorCommand = `color_${string}`;
654
+ type BrightnessCommand = `brightness_${string}`;
655
+
656
+ // Property type templates
657
+ type OnOffProperty = `devices.capabilities.on_off.${string}`;
658
+ type RangeProperty = `devices.capabilities.range.${string}`;
659
+ type ColorProperty = `devices.capabilities.color_setting.${string}`;
660
+
661
+ // Instance name templates
662
+ type PowerInstance = 'powerSwitch';
663
+ type BrightnessInstance = 'brightness';
664
+ type ColorRgbInstance = 'colorRgb';
665
+ type ColorTemperatureInstance = 'colorTemperatureK';
666
+ ```
667
+
668
+ ### Conditional Types
669
+
670
+ Conditional types for advanced type manipulation.
671
+
672
+ ```typescript
673
+ // Extract command type based on name
674
+ type CommandByName<T extends string> = T extends 'turn'
675
+ ? PowerOnCommand | PowerOffCommand
676
+ : T extends 'brightness'
677
+ ? BrightnessCommand
678
+ : T extends 'color'
679
+ ? ColorCommand
680
+ : T extends 'colorTem'
681
+ ? ColorTemperatureCommand
682
+ : never;
683
+
684
+ // Extract value type based on command
685
+ type ValueByCommand<T extends Command> = T extends PowerOnCommand | PowerOffCommand
686
+ ? number
687
+ : T extends BrightnessCommand
688
+ ? number
689
+ : T extends ColorCommand
690
+ ? ColorState
691
+ : T extends ColorTemperatureCommand
692
+ ? number
693
+ : never;
694
+
695
+ // Device with specific capabilities
696
+ type DeviceWithCapability<T extends string> = GoveeDevice & {
697
+ supportedCmds: readonly T[];
698
+ };
699
+
700
+ // Controllable device
701
+ type ControllableDevice = DeviceWithCapability<'turn'>;
702
+
703
+ // Color-capable device
704
+ type ColorDevice = DeviceWithCapability<'color'>;
705
+ ```
706
+
707
+ ### Mapped Types
708
+
709
+ Mapped types for transforming interfaces.
710
+
711
+ ```typescript
712
+ // Optional device properties
713
+ type OptionalDevice = {
714
+ [K in keyof GoveeDevice]?: GoveeDevice[K];
715
+ };
716
+
717
+ // Required configuration
718
+ type RequiredConfig = {
719
+ [K in keyof GoveeClientConfig]-?: GoveeClientConfig[K];
720
+ };
721
+
722
+ // Serializable versions (without methods)
723
+ type SerializableDevice = Pick<
724
+ GoveeDevice,
725
+ 'deviceId' | 'model' | 'deviceName' | 'controllable' | 'retrievable' | 'supportedCmds'
726
+ >;
727
+
728
+ type SerializableState = Pick<DeviceState, 'deviceId' | 'model'> & {
729
+ properties: StateProperty[];
730
+ powerState?: PowerState;
731
+ brightness?: number;
732
+ color?: ColorState;
733
+ colorTemperature?: number;
734
+ online: boolean;
735
+ };
736
+ ```
737
+
738
+ ## Type Validation
739
+
740
+ ### Runtime Type Validation with Zod
741
+
742
+ Schema definitions for runtime validation.
743
+
744
+ ```typescript
745
+ import { z } from 'zod';
746
+
747
+ // Configuration schemas
748
+ const GoveeClientConfigSchema = z.object({
749
+ apiKey: z.string().min(1),
750
+ timeout: z.number().int().positive().optional(),
751
+ rateLimit: z.number().int().positive().optional(),
752
+ logger: z.any().optional(),
753
+ enableRetries: z.boolean().optional(),
754
+ retryPolicy: z
755
+ .union([
756
+ z.literal('development'),
757
+ z.literal('testing'),
758
+ z.literal('production'),
759
+ z.literal('custom'),
760
+ z.any(), // RetryPolicy instance
761
+ ])
762
+ .optional(),
763
+ });
764
+
765
+ // Value object schemas
766
+ const ColorRgbSchema = z.object({
767
+ r: z.number().int().min(0).max(255),
768
+ g: z.number().int().min(0).max(255),
769
+ b: z.number().int().min(0).max(255),
770
+ });
771
+
772
+ const ColorTemperatureSchema = z.object({
773
+ kelvin: z.number().int().min(2000).max(9000),
774
+ });
775
+
776
+ const BrightnessSchema = z.object({
777
+ level: z.number().int().min(0).max(100),
778
+ });
779
+
780
+ // Device schemas
781
+ const GoveeDeviceSchema = z.object({
782
+ deviceId: z.string().min(1),
783
+ model: z.string().min(1),
784
+ deviceName: z.string().min(1),
785
+ controllable: z.boolean(),
786
+ retrievable: z.boolean(),
787
+ supportedCmds: z.array(z.string()),
788
+ });
789
+
790
+ // API response schemas
791
+ const ApiErrorSchema = z.object({
792
+ code: z.number(),
793
+ message: z.string(),
794
+ data: z.unknown().optional(),
795
+ });
796
+
797
+ // Type extraction from schemas
798
+ type ValidatedClientConfig = z.infer<typeof GoveeClientConfigSchema>;
799
+ type ValidatedColorRgb = z.infer<typeof ColorRgbSchema>;
800
+ type ValidatedDevice = z.infer<typeof GoveeDeviceSchema>;
801
+ ```
802
+
803
+ This comprehensive type reference provides LLMs with complete type information for generating accurate, type-safe code when working with the Govee API Client library.