homebridge-myleviton 3.0.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 +202 -0
- package/README.md +112 -0
- package/config.schema.json +136 -0
- package/dist/api/cache.d.ts +108 -0
- package/dist/api/cache.d.ts.map +1 -0
- package/dist/api/cache.js +206 -0
- package/dist/api/cache.js.map +1 -0
- package/dist/api/circuit-breaker.d.ts +118 -0
- package/dist/api/circuit-breaker.d.ts.map +1 -0
- package/dist/api/circuit-breaker.js +223 -0
- package/dist/api/circuit-breaker.js.map +1 -0
- package/dist/api/client.d.ts +116 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +358 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/index.d.ts +23 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +47 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/persistence.d.ts +107 -0
- package/dist/api/persistence.d.ts.map +1 -0
- package/dist/api/persistence.js +285 -0
- package/dist/api/persistence.js.map +1 -0
- package/dist/api/rate-limiter.d.ts +102 -0
- package/dist/api/rate-limiter.d.ts.map +1 -0
- package/dist/api/rate-limiter.js +173 -0
- package/dist/api/rate-limiter.js.map +1 -0
- package/dist/api/request-queue.d.ts +104 -0
- package/dist/api/request-queue.d.ts.map +1 -0
- package/dist/api/request-queue.js +223 -0
- package/dist/api/request-queue.js.map +1 -0
- package/dist/api/websocket.d.ts +116 -0
- package/dist/api/websocket.d.ts.map +1 -0
- package/dist/api/websocket.js +319 -0
- package/dist/api/websocket.js.map +1 -0
- package/dist/errors/index.d.ts +182 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +273 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +42 -0
- package/dist/index.js.map +1 -0
- package/dist/platform.d.ts +139 -0
- package/dist/platform.d.ts.map +1 -0
- package/dist/platform.js +664 -0
- package/dist/platform.js.map +1 -0
- package/dist/types/index.d.ts +225 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +34 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/index.d.ts +15 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +52 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/logger.d.ts +103 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +184 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/retry.d.ts +56 -0
- package/dist/utils/retry.d.ts.map +1 -0
- package/dist/utils/retry.js +141 -0
- package/dist/utils/retry.js.map +1 -0
- package/dist/utils/sanitizers.d.ts +37 -0
- package/dist/utils/sanitizers.d.ts.map +1 -0
- package/dist/utils/sanitizers.js +128 -0
- package/dist/utils/sanitizers.js.map +1 -0
- package/dist/utils/validators.d.ts +51 -0
- package/dist/utils/validators.d.ts.map +1 -0
- package/dist/utils/validators.js +243 -0
- package/dist/utils/validators.js.map +1 -0
- package/package.json +69 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 tbaur
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0
|
|
5
|
+
* See LICENSE file for full license text
|
|
6
|
+
*
|
|
7
|
+
* @fileoverview Structured error hierarchy for better error handling
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Base error class for all Leviton plugin errors
|
|
11
|
+
*/
|
|
12
|
+
export declare abstract class LevitonError extends Error {
|
|
13
|
+
abstract code: string;
|
|
14
|
+
abstract readonly isRetryable: boolean;
|
|
15
|
+
readonly httpStatus?: number;
|
|
16
|
+
readonly timestamp: Date;
|
|
17
|
+
constructor(message: string, options?: {
|
|
18
|
+
cause?: Error;
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* Convert to JSON for logging
|
|
22
|
+
*/
|
|
23
|
+
toJSON(): Record<string, unknown>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Authentication/authorization errors (401, 403)
|
|
27
|
+
*/
|
|
28
|
+
export declare class AuthenticationError extends LevitonError {
|
|
29
|
+
code: string;
|
|
30
|
+
readonly isRetryable = true;
|
|
31
|
+
readonly httpStatus = 401;
|
|
32
|
+
constructor(message?: string, options?: {
|
|
33
|
+
cause?: Error;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Token expired error - specific case of auth error
|
|
38
|
+
*/
|
|
39
|
+
export declare class TokenExpiredError extends AuthenticationError {
|
|
40
|
+
constructor(message?: string, options?: {
|
|
41
|
+
cause?: Error;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Rate limiting errors (429)
|
|
46
|
+
*/
|
|
47
|
+
export declare class RateLimitError extends LevitonError {
|
|
48
|
+
readonly code = "RATE_LIMITED";
|
|
49
|
+
readonly isRetryable = true;
|
|
50
|
+
readonly httpStatus = 429;
|
|
51
|
+
readonly retryAfter: number;
|
|
52
|
+
constructor(message?: string, retryAfter?: number, options?: {
|
|
53
|
+
cause?: Error;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Device offline/unreachable errors
|
|
58
|
+
*/
|
|
59
|
+
export declare class DeviceOfflineError extends LevitonError {
|
|
60
|
+
readonly code = "DEVICE_OFFLINE";
|
|
61
|
+
readonly isRetryable = false;
|
|
62
|
+
readonly deviceId: string;
|
|
63
|
+
readonly deviceName?: string;
|
|
64
|
+
constructor(deviceId: string, deviceName?: string, options?: {
|
|
65
|
+
cause?: Error;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Device not found errors
|
|
70
|
+
*/
|
|
71
|
+
export declare class DeviceNotFoundError extends LevitonError {
|
|
72
|
+
readonly code = "DEVICE_NOT_FOUND";
|
|
73
|
+
readonly isRetryable = false;
|
|
74
|
+
readonly httpStatus = 404;
|
|
75
|
+
readonly deviceId: string;
|
|
76
|
+
constructor(deviceId: string, options?: {
|
|
77
|
+
cause?: Error;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Circuit breaker open errors
|
|
82
|
+
*/
|
|
83
|
+
export declare class CircuitBreakerError extends LevitonError {
|
|
84
|
+
readonly code = "CIRCUIT_OPEN";
|
|
85
|
+
readonly isRetryable = true;
|
|
86
|
+
readonly resetTime: Date;
|
|
87
|
+
constructor(resetTimeMs: number, options?: {
|
|
88
|
+
cause?: Error;
|
|
89
|
+
});
|
|
90
|
+
get retryAfterMs(): number;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Network/connectivity errors
|
|
94
|
+
*/
|
|
95
|
+
export declare class NetworkError extends LevitonError {
|
|
96
|
+
code: string;
|
|
97
|
+
readonly isRetryable = true;
|
|
98
|
+
readonly originalError?: Error;
|
|
99
|
+
constructor(message?: string, options?: {
|
|
100
|
+
cause?: Error;
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Request timeout errors
|
|
105
|
+
*/
|
|
106
|
+
export declare class TimeoutError extends NetworkError {
|
|
107
|
+
readonly timeoutMs: number;
|
|
108
|
+
constructor(timeoutMs: number, options?: {
|
|
109
|
+
cause?: Error;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* API response parsing errors
|
|
114
|
+
*/
|
|
115
|
+
export declare class ApiParseError extends LevitonError {
|
|
116
|
+
readonly code = "PARSE_ERROR";
|
|
117
|
+
readonly isRetryable = false;
|
|
118
|
+
readonly responsePreview?: string;
|
|
119
|
+
constructor(message: string, responsePreview?: string, options?: {
|
|
120
|
+
cause?: Error;
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Invalid API response errors
|
|
125
|
+
*/
|
|
126
|
+
export declare class ApiResponseError extends LevitonError {
|
|
127
|
+
readonly code = "API_ERROR";
|
|
128
|
+
readonly isRetryable: boolean;
|
|
129
|
+
readonly httpStatus: number;
|
|
130
|
+
readonly responseBody?: string;
|
|
131
|
+
constructor(httpStatus: number, statusText: string, responseBody?: string, options?: {
|
|
132
|
+
cause?: Error;
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Configuration validation errors
|
|
137
|
+
*/
|
|
138
|
+
export declare class ConfigurationError extends LevitonError {
|
|
139
|
+
readonly code = "CONFIG_ERROR";
|
|
140
|
+
readonly isRetryable = false;
|
|
141
|
+
readonly field?: string;
|
|
142
|
+
readonly details?: string[];
|
|
143
|
+
constructor(message: string, field?: string, details?: string[], options?: {
|
|
144
|
+
cause?: Error;
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Validation errors for input data
|
|
149
|
+
*/
|
|
150
|
+
export declare class ValidationError extends LevitonError {
|
|
151
|
+
readonly code = "VALIDATION_ERROR";
|
|
152
|
+
readonly isRetryable = false;
|
|
153
|
+
readonly field: string;
|
|
154
|
+
readonly value?: unknown;
|
|
155
|
+
constructor(field: string, message: string, value?: unknown, options?: {
|
|
156
|
+
cause?: Error;
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* WebSocket connection errors
|
|
161
|
+
*/
|
|
162
|
+
export declare class WebSocketError extends LevitonError {
|
|
163
|
+
readonly code = "WEBSOCKET_ERROR";
|
|
164
|
+
readonly isRetryable = true;
|
|
165
|
+
readonly closeCode?: number;
|
|
166
|
+
constructor(message: string, closeCode?: number, options?: {
|
|
167
|
+
cause?: Error;
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Error factory for creating appropriate error types from API responses
|
|
172
|
+
*/
|
|
173
|
+
export declare function createApiError(httpStatus: number, statusText: string, responseBody?: string): LevitonError;
|
|
174
|
+
/**
|
|
175
|
+
* Check if an error is retryable
|
|
176
|
+
*/
|
|
177
|
+
export declare function isRetryableError(error: unknown): boolean;
|
|
178
|
+
/**
|
|
179
|
+
* Get error code from any error
|
|
180
|
+
*/
|
|
181
|
+
export declare function getErrorCode(error: unknown): string;
|
|
182
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;GAEG;AACH,8BAAsB,YAAa,SAAQ,KAAK;IAC9C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAA;IACtC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAA;gBAEZ,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE;IAWxD;;OAEG;IACH,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAWlC;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,YAAY;IACnD,IAAI,SAAe;IACnB,QAAQ,CAAC,WAAW,QAAO;IAC3B,QAAQ,CAAC,UAAU,OAAM;gBAEb,OAAO,SAA0B,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE;CAG3E;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,mBAAmB;gBAC5C,OAAO,SAAqC,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE;CAItF;AAED;;GAEG;AACH,qBAAa,cAAe,SAAQ,YAAY;IAC9C,QAAQ,CAAC,IAAI,kBAAiB;IAC9B,QAAQ,CAAC,WAAW,QAAO;IAC3B,QAAQ,CAAC,UAAU,OAAM;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,C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KAAK,CAAC,EAAE,KAAK,CAAA;KAAE;CAK7F;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,YAAY;IAC/C,QAAQ,CAAC,IAAI,sBAAqB;IAClC,QAAQ,CAAC,WAAW,SAAQ;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAA;gBAEZ,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE;CAKzF;AAED;;GAEG;AACH,qBAAa,cAAe,SAAQ,YAAY;IAC9C,QAAQ,CAAC,IAAI,qBAAoB;IACjC,QAAQ,CAAC,WAAW,QAAO;IAC3B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;gBAEf,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE;CAI7E;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,YAAY,CAAC,EAAE,MAAM,GACpB,YAAY,CAad;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAkBxD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAQnD"}
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2026 tbaur
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0
|
|
6
|
+
* See LICENSE file for full license text
|
|
7
|
+
*
|
|
8
|
+
* @fileoverview Structured error hierarchy for better error handling
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.WebSocketError = exports.ValidationError = exports.ConfigurationError = exports.ApiResponseError = exports.ApiParseError = exports.TimeoutError = exports.NetworkError = exports.CircuitBreakerError = exports.DeviceNotFoundError = exports.DeviceOfflineError = exports.RateLimitError = exports.TokenExpiredError = exports.AuthenticationError = exports.LevitonError = void 0;
|
|
12
|
+
exports.createApiError = createApiError;
|
|
13
|
+
exports.isRetryableError = isRetryableError;
|
|
14
|
+
exports.getErrorCode = getErrorCode;
|
|
15
|
+
/**
|
|
16
|
+
* Base error class for all Leviton plugin errors
|
|
17
|
+
*/
|
|
18
|
+
class LevitonError extends Error {
|
|
19
|
+
httpStatus;
|
|
20
|
+
timestamp;
|
|
21
|
+
constructor(message, options) {
|
|
22
|
+
super(message, options);
|
|
23
|
+
this.name = this.constructor.name;
|
|
24
|
+
this.timestamp = new Date();
|
|
25
|
+
// Capture stack trace
|
|
26
|
+
if (Error.captureStackTrace) {
|
|
27
|
+
Error.captureStackTrace(this, this.constructor);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Convert to JSON for logging
|
|
32
|
+
*/
|
|
33
|
+
toJSON() {
|
|
34
|
+
return {
|
|
35
|
+
name: this.name,
|
|
36
|
+
code: this.code,
|
|
37
|
+
message: this.message,
|
|
38
|
+
isRetryable: this.isRetryable,
|
|
39
|
+
httpStatus: this.httpStatus,
|
|
40
|
+
timestamp: this.timestamp.toISOString(),
|
|
41
|
+
stack: this.stack,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.LevitonError = LevitonError;
|
|
46
|
+
/**
|
|
47
|
+
* Authentication/authorization errors (401, 403)
|
|
48
|
+
*/
|
|
49
|
+
class AuthenticationError extends LevitonError {
|
|
50
|
+
code = 'AUTH_ERROR';
|
|
51
|
+
isRetryable = true;
|
|
52
|
+
httpStatus = 401;
|
|
53
|
+
constructor(message = 'Authentication failed', options) {
|
|
54
|
+
super(message, options);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.AuthenticationError = AuthenticationError;
|
|
58
|
+
/**
|
|
59
|
+
* Token expired error - specific case of auth error
|
|
60
|
+
*/
|
|
61
|
+
class TokenExpiredError extends AuthenticationError {
|
|
62
|
+
constructor(message = 'Authentication token has expired', options) {
|
|
63
|
+
super(message, options);
|
|
64
|
+
this.code = 'TOKEN_EXPIRED';
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.TokenExpiredError = TokenExpiredError;
|
|
68
|
+
/**
|
|
69
|
+
* Rate limiting errors (429)
|
|
70
|
+
*/
|
|
71
|
+
class RateLimitError extends LevitonError {
|
|
72
|
+
code = 'RATE_LIMITED';
|
|
73
|
+
isRetryable = true;
|
|
74
|
+
httpStatus = 429;
|
|
75
|
+
retryAfter;
|
|
76
|
+
constructor(message = 'Rate limit exceeded', retryAfter = 60, options) {
|
|
77
|
+
super(message, options);
|
|
78
|
+
this.retryAfter = retryAfter;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.RateLimitError = RateLimitError;
|
|
82
|
+
/**
|
|
83
|
+
* Device offline/unreachable errors
|
|
84
|
+
*/
|
|
85
|
+
class DeviceOfflineError extends LevitonError {
|
|
86
|
+
code = 'DEVICE_OFFLINE';
|
|
87
|
+
isRetryable = false;
|
|
88
|
+
deviceId;
|
|
89
|
+
deviceName;
|
|
90
|
+
constructor(deviceId, deviceName, options) {
|
|
91
|
+
super(`Device ${deviceName || deviceId} is offline or unreachable`, options);
|
|
92
|
+
this.deviceId = deviceId;
|
|
93
|
+
this.deviceName = deviceName;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.DeviceOfflineError = DeviceOfflineError;
|
|
97
|
+
/**
|
|
98
|
+
* Device not found errors
|
|
99
|
+
*/
|
|
100
|
+
class DeviceNotFoundError extends LevitonError {
|
|
101
|
+
code = 'DEVICE_NOT_FOUND';
|
|
102
|
+
isRetryable = false;
|
|
103
|
+
httpStatus = 404;
|
|
104
|
+
deviceId;
|
|
105
|
+
constructor(deviceId, options) {
|
|
106
|
+
super(`Device ${deviceId} not found`, options);
|
|
107
|
+
this.deviceId = deviceId;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.DeviceNotFoundError = DeviceNotFoundError;
|
|
111
|
+
/**
|
|
112
|
+
* Circuit breaker open errors
|
|
113
|
+
*/
|
|
114
|
+
class CircuitBreakerError extends LevitonError {
|
|
115
|
+
code = 'CIRCUIT_OPEN';
|
|
116
|
+
isRetryable = true;
|
|
117
|
+
resetTime;
|
|
118
|
+
constructor(resetTimeMs, options) {
|
|
119
|
+
const resetTime = new Date(Date.now() + resetTimeMs);
|
|
120
|
+
super(`Circuit breaker is open. Service unavailable until ${resetTime.toISOString()}`, options);
|
|
121
|
+
this.resetTime = resetTime;
|
|
122
|
+
}
|
|
123
|
+
get retryAfterMs() {
|
|
124
|
+
return Math.max(0, this.resetTime.getTime() - Date.now());
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.CircuitBreakerError = CircuitBreakerError;
|
|
128
|
+
/**
|
|
129
|
+
* Network/connectivity errors
|
|
130
|
+
*/
|
|
131
|
+
class NetworkError extends LevitonError {
|
|
132
|
+
code = 'NETWORK_ERROR';
|
|
133
|
+
isRetryable = true;
|
|
134
|
+
originalError;
|
|
135
|
+
constructor(message = 'Network request failed', options) {
|
|
136
|
+
super(message, options);
|
|
137
|
+
this.originalError = options?.cause;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
exports.NetworkError = NetworkError;
|
|
141
|
+
/**
|
|
142
|
+
* Request timeout errors
|
|
143
|
+
*/
|
|
144
|
+
class TimeoutError extends NetworkError {
|
|
145
|
+
timeoutMs;
|
|
146
|
+
constructor(timeoutMs, options) {
|
|
147
|
+
super(`Request timed out after ${timeoutMs}ms`, options);
|
|
148
|
+
this.code = 'TIMEOUT';
|
|
149
|
+
this.timeoutMs = timeoutMs;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
exports.TimeoutError = TimeoutError;
|
|
153
|
+
/**
|
|
154
|
+
* API response parsing errors
|
|
155
|
+
*/
|
|
156
|
+
class ApiParseError extends LevitonError {
|
|
157
|
+
code = 'PARSE_ERROR';
|
|
158
|
+
isRetryable = false;
|
|
159
|
+
responsePreview;
|
|
160
|
+
constructor(message, responsePreview, options) {
|
|
161
|
+
super(message, options);
|
|
162
|
+
this.responsePreview = responsePreview?.substring(0, 200);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
exports.ApiParseError = ApiParseError;
|
|
166
|
+
/**
|
|
167
|
+
* Invalid API response errors
|
|
168
|
+
*/
|
|
169
|
+
class ApiResponseError extends LevitonError {
|
|
170
|
+
code = 'API_ERROR';
|
|
171
|
+
isRetryable;
|
|
172
|
+
httpStatus;
|
|
173
|
+
responseBody;
|
|
174
|
+
constructor(httpStatus, statusText, responseBody, options) {
|
|
175
|
+
super(`API request failed: ${httpStatus} ${statusText}`, options);
|
|
176
|
+
this.httpStatus = httpStatus;
|
|
177
|
+
this.responseBody = responseBody?.substring(0, 500);
|
|
178
|
+
// Server errors (5xx) are retryable, client errors (4xx) are not
|
|
179
|
+
this.isRetryable = httpStatus >= 500 && httpStatus < 600;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
exports.ApiResponseError = ApiResponseError;
|
|
183
|
+
/**
|
|
184
|
+
* Configuration validation errors
|
|
185
|
+
*/
|
|
186
|
+
class ConfigurationError extends LevitonError {
|
|
187
|
+
code = 'CONFIG_ERROR';
|
|
188
|
+
isRetryable = false;
|
|
189
|
+
field;
|
|
190
|
+
details;
|
|
191
|
+
constructor(message, field, details, options) {
|
|
192
|
+
super(message, options);
|
|
193
|
+
this.field = field;
|
|
194
|
+
this.details = details;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
exports.ConfigurationError = ConfigurationError;
|
|
198
|
+
/**
|
|
199
|
+
* Validation errors for input data
|
|
200
|
+
*/
|
|
201
|
+
class ValidationError extends LevitonError {
|
|
202
|
+
code = 'VALIDATION_ERROR';
|
|
203
|
+
isRetryable = false;
|
|
204
|
+
field;
|
|
205
|
+
value;
|
|
206
|
+
constructor(field, message, value, options) {
|
|
207
|
+
super(`Invalid ${field}: ${message}`, options);
|
|
208
|
+
this.field = field;
|
|
209
|
+
this.value = value;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
exports.ValidationError = ValidationError;
|
|
213
|
+
/**
|
|
214
|
+
* WebSocket connection errors
|
|
215
|
+
*/
|
|
216
|
+
class WebSocketError extends LevitonError {
|
|
217
|
+
code = 'WEBSOCKET_ERROR';
|
|
218
|
+
isRetryable = true;
|
|
219
|
+
closeCode;
|
|
220
|
+
constructor(message, closeCode, options) {
|
|
221
|
+
super(message, options);
|
|
222
|
+
this.closeCode = closeCode;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
exports.WebSocketError = WebSocketError;
|
|
226
|
+
/**
|
|
227
|
+
* Error factory for creating appropriate error types from API responses
|
|
228
|
+
*/
|
|
229
|
+
function createApiError(httpStatus, statusText, responseBody) {
|
|
230
|
+
switch (httpStatus) {
|
|
231
|
+
case 401:
|
|
232
|
+
return new AuthenticationError(`Unauthorized: ${statusText}`);
|
|
233
|
+
case 403:
|
|
234
|
+
return new AuthenticationError(`Forbidden: ${statusText}`);
|
|
235
|
+
case 404:
|
|
236
|
+
return new ApiResponseError(httpStatus, statusText, responseBody);
|
|
237
|
+
case 429:
|
|
238
|
+
return new RateLimitError(`Rate limited: ${statusText}`);
|
|
239
|
+
default:
|
|
240
|
+
return new ApiResponseError(httpStatus, statusText, responseBody);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Check if an error is retryable
|
|
245
|
+
*/
|
|
246
|
+
function isRetryableError(error) {
|
|
247
|
+
if (error instanceof LevitonError) {
|
|
248
|
+
return error.isRetryable;
|
|
249
|
+
}
|
|
250
|
+
// Network errors from fetch are generally retryable
|
|
251
|
+
if (error instanceof Error) {
|
|
252
|
+
const message = error.message.toLowerCase();
|
|
253
|
+
return (message.includes('network') ||
|
|
254
|
+
message.includes('timeout') ||
|
|
255
|
+
message.includes('econnreset') ||
|
|
256
|
+
message.includes('enotfound') ||
|
|
257
|
+
message.includes('socket hang up'));
|
|
258
|
+
}
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Get error code from any error
|
|
263
|
+
*/
|
|
264
|
+
function getErrorCode(error) {
|
|
265
|
+
if (error instanceof LevitonError) {
|
|
266
|
+
return error.code;
|
|
267
|
+
}
|
|
268
|
+
if (error instanceof Error) {
|
|
269
|
+
return error.name || 'UNKNOWN_ERROR';
|
|
270
|
+
}
|
|
271
|
+
return 'UNKNOWN_ERROR';
|
|
272
|
+
}
|
|
273
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AA+OH,wCAiBC;AAKD,4CAkBC;AAKD,oCAQC;AAlSD;;GAEG;AACH,MAAsB,YAAa,SAAQ,KAAK;IAGrC,UAAU,CAAS;IACnB,SAAS,CAAM;IAExB,YAAY,OAAe,EAAE,OAA2B;QACtD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAA;QACjC,IAAI,CAAC,SAAS,GAAG,IAAI,IAAI,EAAE,CAAA;QAE3B,sBAAsB;QACtB,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC5B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAA;QACjD,CAAC;IACH,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAA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A;AACxB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 tbaur
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0
|
|
5
|
+
* See LICENSE file for full license text
|
|
6
|
+
*
|
|
7
|
+
* @fileoverview Main entry point for homebridge-myleviton
|
|
8
|
+
*/
|
|
9
|
+
export * from './types';
|
|
10
|
+
export * from './errors';
|
|
11
|
+
export * from './api';
|
|
12
|
+
export * from './utils';
|
|
13
|
+
export { LevitonDecoraSmartPlatform } from './platform';
|
|
14
|
+
export { default } from './platform';
|
|
15
|
+
export declare const VERSION = "3.0.0";
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,OAAO,CAAA;AACrB,cAAc,SAAS,CAAA;AAGvB,OAAO,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAA;AAGvD,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAGpC,eAAO,MAAM,OAAO,UAAU,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2026 tbaur
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0
|
|
6
|
+
* See LICENSE file for full license text
|
|
7
|
+
*
|
|
8
|
+
* @fileoverview Main entry point for homebridge-myleviton
|
|
9
|
+
*/
|
|
10
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
13
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
14
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(o, k2, desc);
|
|
17
|
+
}) : (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
o[k2] = m[k];
|
|
20
|
+
}));
|
|
21
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
22
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
23
|
+
};
|
|
24
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
25
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
26
|
+
};
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.VERSION = exports.default = exports.LevitonDecoraSmartPlatform = void 0;
|
|
29
|
+
// Re-export everything
|
|
30
|
+
__exportStar(require("./types"), exports);
|
|
31
|
+
__exportStar(require("./errors"), exports);
|
|
32
|
+
__exportStar(require("./api"), exports);
|
|
33
|
+
__exportStar(require("./utils"), exports);
|
|
34
|
+
// Export platform
|
|
35
|
+
var platform_1 = require("./platform");
|
|
36
|
+
Object.defineProperty(exports, "LevitonDecoraSmartPlatform", { enumerable: true, get: function () { return platform_1.LevitonDecoraSmartPlatform; } });
|
|
37
|
+
// Default export for Homebridge plugin registration
|
|
38
|
+
var platform_2 = require("./platform");
|
|
39
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(platform_2).default; } });
|
|
40
|
+
// Export version
|
|
41
|
+
exports.VERSION = '3.0.0';
|
|
42
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;;;;;;;;;;;;;;;;;;AAEH,uBAAuB;AACvB,0CAAuB;AACvB,2CAAwB;AACxB,wCAAqB;AACrB,0CAAuB;AAEvB,kBAAkB;AAClB,uCAAuD;AAA9C,sHAAA,0BAA0B,OAAA;AAEnC,oDAAoD;AACpD,uCAAoC;AAA3B,oHAAA,OAAO,OAAA;AAEhB,iBAAiB;AACJ,QAAA,OAAO,GAAG,OAAO,CAAA"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 tbaur
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0
|
|
5
|
+
* See LICENSE file for full license text
|
|
6
|
+
*
|
|
7
|
+
* @fileoverview Homebridge platform plugin for My Leviton Decora Smart devices
|
|
8
|
+
*/
|
|
9
|
+
import type { LevitonConfig, DeviceInfo } from './types';
|
|
10
|
+
type HomebridgeAPI = any;
|
|
11
|
+
type PlatformAccessory = any;
|
|
12
|
+
/**
|
|
13
|
+
* Leviton Decora Smart Platform for Homebridge
|
|
14
|
+
*/
|
|
15
|
+
export declare class LevitonDecoraSmartPlatform {
|
|
16
|
+
private readonly config;
|
|
17
|
+
private readonly api;
|
|
18
|
+
private readonly accessories;
|
|
19
|
+
private readonly log;
|
|
20
|
+
private client;
|
|
21
|
+
private currentToken;
|
|
22
|
+
private tokenRefreshInProgress;
|
|
23
|
+
private webSocket;
|
|
24
|
+
private pollingInterval;
|
|
25
|
+
private residenceId;
|
|
26
|
+
private devicePersistence;
|
|
27
|
+
private cleanupInterval;
|
|
28
|
+
constructor(homebridgeLog: (msg: string) => void, config: LevitonConfig, api: HomebridgeAPI);
|
|
29
|
+
/**
|
|
30
|
+
* Validates plugin configuration
|
|
31
|
+
*/
|
|
32
|
+
private validateConfig;
|
|
33
|
+
/**
|
|
34
|
+
* Initializes the platform
|
|
35
|
+
*/
|
|
36
|
+
private initialize;
|
|
37
|
+
/**
|
|
38
|
+
* Discovers devices from Leviton API
|
|
39
|
+
*/
|
|
40
|
+
private discoverDevices;
|
|
41
|
+
/**
|
|
42
|
+
* Handles WebSocket update messages
|
|
43
|
+
*/
|
|
44
|
+
private handleWebSocketUpdate;
|
|
45
|
+
/**
|
|
46
|
+
* Checks if device should be excluded
|
|
47
|
+
*/
|
|
48
|
+
private isDeviceExcluded;
|
|
49
|
+
/**
|
|
50
|
+
* Checks if accessory already exists
|
|
51
|
+
*/
|
|
52
|
+
private accessoryExists;
|
|
53
|
+
/**
|
|
54
|
+
* Adds a new accessory
|
|
55
|
+
*/
|
|
56
|
+
addAccessory(device: DeviceInfo, token: string): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Configures a cached accessory
|
|
59
|
+
*/
|
|
60
|
+
configureAccessory(accessory: PlatformAccessory): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Sets up the appropriate service for a device
|
|
63
|
+
*/
|
|
64
|
+
private setupService;
|
|
65
|
+
/**
|
|
66
|
+
* Gets device status with error handling
|
|
67
|
+
*/
|
|
68
|
+
private getStatus;
|
|
69
|
+
/**
|
|
70
|
+
* Sets up a lightbulb service
|
|
71
|
+
*/
|
|
72
|
+
private setupLightbulbService;
|
|
73
|
+
/**
|
|
74
|
+
* Sets up a motion dimmer service
|
|
75
|
+
*/
|
|
76
|
+
private setupMotionDimmerService;
|
|
77
|
+
/**
|
|
78
|
+
* Sets up a fan service
|
|
79
|
+
*/
|
|
80
|
+
private setupFanService;
|
|
81
|
+
/**
|
|
82
|
+
* Sets up a basic switch/outlet service
|
|
83
|
+
*/
|
|
84
|
+
private setupBasicService;
|
|
85
|
+
/**
|
|
86
|
+
* Creates a power getter handler
|
|
87
|
+
*/
|
|
88
|
+
private createPowerGetter;
|
|
89
|
+
/**
|
|
90
|
+
* Creates a power setter handler
|
|
91
|
+
*/
|
|
92
|
+
private createPowerSetter;
|
|
93
|
+
/**
|
|
94
|
+
* Creates a brightness getter handler
|
|
95
|
+
*/
|
|
96
|
+
private createBrightnessGetter;
|
|
97
|
+
/**
|
|
98
|
+
* Creates a brightness setter handler
|
|
99
|
+
*/
|
|
100
|
+
private createBrightnessSetter;
|
|
101
|
+
/**
|
|
102
|
+
* Ensures a valid token is available
|
|
103
|
+
*/
|
|
104
|
+
private ensureValidToken;
|
|
105
|
+
/**
|
|
106
|
+
* Refreshes the authentication token
|
|
107
|
+
*/
|
|
108
|
+
private refreshToken;
|
|
109
|
+
/**
|
|
110
|
+
* Starts polling for device updates
|
|
111
|
+
*/
|
|
112
|
+
private startPolling;
|
|
113
|
+
/**
|
|
114
|
+
* Polls all devices for updates
|
|
115
|
+
*/
|
|
116
|
+
private pollDevices;
|
|
117
|
+
/**
|
|
118
|
+
* Saves device states to persistence
|
|
119
|
+
*/
|
|
120
|
+
private saveDeviceStates;
|
|
121
|
+
/**
|
|
122
|
+
* Starts periodic cleanup
|
|
123
|
+
*/
|
|
124
|
+
private startPeriodicCleanup;
|
|
125
|
+
/**
|
|
126
|
+
* Cleans up resources
|
|
127
|
+
*/
|
|
128
|
+
private cleanup;
|
|
129
|
+
/**
|
|
130
|
+
* Removes all accessories
|
|
131
|
+
*/
|
|
132
|
+
removeAccessories(): void;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Homebridge plugin registration
|
|
136
|
+
*/
|
|
137
|
+
export declare function registerPlatform(homebridge: HomebridgeAPI): void;
|
|
138
|
+
export default registerPlatform;
|
|
139
|
+
//# sourceMappingURL=platform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAQH,OAAO,KAAK,EACV,aAAa,EACb,UAAU,EAIX,MAAM,SAAS,CAAA;AAsBhB,KAAK,aAAa,GAAG,GAAG,CAAA;AAExB,KAAK,iBAAiB,GAAG,GAAG,CAAA;AAM5B;;GAEG;AACH,qBAAa,0BAA0B;IACrC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;IACtC,OAAO,CAAC,QAAQ,CAAC,GAAG,CA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