mysa-js-sdk 1.3.3 → 2.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/README.md +2 -1
- package/dist/index.cjs +183 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +128 -54
- package/dist/index.d.ts +128 -54
- package/dist/index.js +182 -35
- package/dist/index.js.map +1 -1
- package/package.json +14 -14
package/dist/index.d.ts
CHANGED
|
@@ -20,6 +20,19 @@ declare class MysaApiError extends Error {
|
|
|
20
20
|
*/
|
|
21
21
|
constructor(apiResponse: Response);
|
|
22
22
|
}
|
|
23
|
+
/** Error thrown when an MQTT publish ultimately fails after retry attempts. */
|
|
24
|
+
declare class MqttPublishError extends Error {
|
|
25
|
+
attempts: number;
|
|
26
|
+
original?: unknown | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Creates a new MqttPublishError instance.
|
|
29
|
+
*
|
|
30
|
+
* @param message - A human-readable description of the publish failure.
|
|
31
|
+
* @param attempts - The number of attempts that were made before giving up.
|
|
32
|
+
* @param original - The original error object thrown by the underlying MQTT library (optional).
|
|
33
|
+
*/
|
|
34
|
+
constructor(message: string, attempts: number, original?: unknown | undefined);
|
|
35
|
+
}
|
|
23
36
|
|
|
24
37
|
/**
|
|
25
38
|
* Interface representing a temperature setpoint change event for a Mysa device.
|
|
@@ -43,7 +56,13 @@ interface SetPointChange {
|
|
|
43
56
|
* Defines the possible operational states that a Mysa thermostat or heating device can be set to. These modes control
|
|
44
57
|
* the device's heating behavior and power consumption.
|
|
45
58
|
*/
|
|
46
|
-
type MysaDeviceMode = 'off' | 'heat';
|
|
59
|
+
type MysaDeviceMode = 'off' | 'heat' | 'cool' | 'dry' | 'fan_only' | 'auto';
|
|
60
|
+
/**
|
|
61
|
+
* Union type representing the available fan speed modes for Mysa devices.
|
|
62
|
+
*
|
|
63
|
+
* Defines the possible fan speed states that a Mysa thermostat device can be set to.
|
|
64
|
+
*/
|
|
65
|
+
type MysaFanSpeedMode = 'auto' | 'low' | 'medium' | 'high' | 'max';
|
|
47
66
|
|
|
48
67
|
/**
|
|
49
68
|
* Interface representing a device state change event for a Mysa device.
|
|
@@ -59,6 +78,8 @@ interface StateChange {
|
|
|
59
78
|
mode?: MysaDeviceMode;
|
|
60
79
|
/** Current temperature setpoint after the state change */
|
|
61
80
|
setPoint: number;
|
|
81
|
+
/** Optional fan speed (1 = auto, 3 = low, 5 = medium, 7 = high, 8 = max). AC only */
|
|
82
|
+
fanSpeed?: MysaFanSpeedMode;
|
|
62
83
|
}
|
|
63
84
|
|
|
64
85
|
/**
|
|
@@ -155,9 +176,9 @@ interface BrandInfo {
|
|
|
155
176
|
/** Unique identifier for the brand */
|
|
156
177
|
Id: number;
|
|
157
178
|
/** Remote control model number for the AC device */
|
|
158
|
-
remoteModelNumber
|
|
179
|
+
remoteModelNumber?: string;
|
|
159
180
|
/** Original Equipment Manufacturer brand name */
|
|
160
|
-
OEMBrand
|
|
181
|
+
OEMBrand?: string;
|
|
161
182
|
}
|
|
162
183
|
/**
|
|
163
184
|
* Supported capabilities and features for air conditioning devices.
|
|
@@ -198,55 +219,55 @@ interface ModeObj {
|
|
|
198
219
|
*/
|
|
199
220
|
interface DeviceBase {
|
|
200
221
|
/** Button digital input configuration value */
|
|
201
|
-
ButtonDI
|
|
222
|
+
ButtonDI?: number;
|
|
202
223
|
/** Maximum current rating as a string value */
|
|
203
|
-
MaxCurrent
|
|
224
|
+
MaxCurrent?: string;
|
|
204
225
|
/** Device model identifier string */
|
|
205
226
|
Model: string;
|
|
206
227
|
/** Button average value configuration */
|
|
207
|
-
ButtonAVE
|
|
228
|
+
ButtonAVE?: number;
|
|
208
229
|
/** Operating voltage of the device */
|
|
209
|
-
Voltage
|
|
230
|
+
Voltage?: number;
|
|
210
231
|
/** Button polling interval configuration */
|
|
211
|
-
ButtonPolling
|
|
232
|
+
ButtonPolling?: number;
|
|
212
233
|
/** Minimum brightness level (0-100) */
|
|
213
|
-
MinBrightness
|
|
234
|
+
MinBrightness?: number;
|
|
214
235
|
/** User-assigned device name */
|
|
215
|
-
Name
|
|
236
|
+
Name?: string;
|
|
216
237
|
/** Button low power mode configuration */
|
|
217
|
-
ButtonLowPower
|
|
238
|
+
ButtonLowPower?: number;
|
|
218
239
|
/** Type of heater controlled by the device */
|
|
219
|
-
HeaterType
|
|
240
|
+
HeaterType?: string;
|
|
220
241
|
/** Button repeat delay configuration in milliseconds */
|
|
221
|
-
ButtonRepeatDelay
|
|
242
|
+
ButtonRepeatDelay?: number;
|
|
222
243
|
/** Button repeat start delay configuration in milliseconds */
|
|
223
|
-
ButtonRepeatStart
|
|
244
|
+
ButtonRepeatStart?: number;
|
|
224
245
|
/** Display animation style setting */
|
|
225
|
-
Animation
|
|
246
|
+
Animation?: string;
|
|
226
247
|
/** Maximum brightness level (0-100) */
|
|
227
|
-
MaxBrightness
|
|
248
|
+
MaxBrightness?: number;
|
|
228
249
|
/** Array of user IDs allowed to control this device */
|
|
229
|
-
AllowedUsers
|
|
250
|
+
AllowedUsers?: string[];
|
|
230
251
|
/** Current button state indicator */
|
|
231
|
-
ButtonState
|
|
252
|
+
ButtonState?: string;
|
|
232
253
|
/** Home identifier that this device belongs to */
|
|
233
|
-
Home
|
|
254
|
+
Home?: string;
|
|
234
255
|
/** Button sensitivity threshold configuration */
|
|
235
|
-
ButtonThreshold
|
|
256
|
+
ButtonThreshold?: number;
|
|
236
257
|
/** Data format version used by the device */
|
|
237
|
-
Format
|
|
258
|
+
Format?: string;
|
|
238
259
|
/** Time zone setting for the device */
|
|
239
|
-
TimeZone
|
|
260
|
+
TimeZone?: string;
|
|
240
261
|
/** Unix timestamp of when device was last paired */
|
|
241
|
-
LastPaired
|
|
262
|
+
LastPaired?: number;
|
|
242
263
|
/** Minimum temperature setpoint allowed */
|
|
243
|
-
MinSetpoint
|
|
264
|
+
MinSetpoint?: number;
|
|
244
265
|
/** Current operating mode of the device */
|
|
245
|
-
Mode
|
|
266
|
+
Mode?: ModeObj;
|
|
246
267
|
/** User ID of the device owner */
|
|
247
|
-
Owner
|
|
268
|
+
Owner?: string;
|
|
248
269
|
/** Maximum temperature setpoint allowed */
|
|
249
|
-
MaxSetpoint
|
|
270
|
+
MaxSetpoint?: number;
|
|
250
271
|
/** Unique device identifier */
|
|
251
272
|
Id: string;
|
|
252
273
|
/** Optional zone assignment for the device */
|
|
@@ -320,43 +341,45 @@ interface DeviceState {
|
|
|
320
341
|
/** Overall timestamp for the device state */
|
|
321
342
|
Timestamp: number;
|
|
322
343
|
/** Time the device has been on */
|
|
323
|
-
OnTime
|
|
344
|
+
OnTime?: TimestampedValue<number>;
|
|
324
345
|
/** Temperature set point */
|
|
325
|
-
SetPoint
|
|
346
|
+
SetPoint?: TimestampedValue<number>;
|
|
326
347
|
/** Display brightness level */
|
|
327
|
-
Brightness
|
|
348
|
+
Brightness?: TimestampedValue<number>;
|
|
328
349
|
/** Schedule mode setting */
|
|
329
|
-
ScheduleMode
|
|
350
|
+
ScheduleMode?: TimestampedValue<number>;
|
|
330
351
|
/** Hold time setting */
|
|
331
|
-
HoldTime
|
|
352
|
+
HoldTime?: TimestampedValue<number>;
|
|
332
353
|
/** Wi-Fi signal strength */
|
|
333
|
-
Rssi
|
|
354
|
+
Rssi?: TimestampedValue<number>;
|
|
334
355
|
/** Thermostat mode */
|
|
335
|
-
TstatMode
|
|
356
|
+
TstatMode?: TimestampedValue<number>;
|
|
336
357
|
/** Available heap memory */
|
|
337
|
-
FreeHeap
|
|
358
|
+
FreeHeap?: TimestampedValue<number>;
|
|
338
359
|
/** Sensor temperature reading */
|
|
339
|
-
SensorTemp
|
|
360
|
+
SensorTemp?: TimestampedValue<number>;
|
|
340
361
|
/** Current mode */
|
|
341
|
-
Mode
|
|
362
|
+
Mode?: TimestampedValue<number>;
|
|
342
363
|
/** Voltage measurement */
|
|
343
|
-
Voltage
|
|
364
|
+
Voltage?: TimestampedValue<number>;
|
|
344
365
|
/** Temperature corrected for calibration */
|
|
345
|
-
CorrectedTemp
|
|
366
|
+
CorrectedTemp?: TimestampedValue<number>;
|
|
346
367
|
/** Duty cycle percentage */
|
|
347
|
-
Duty
|
|
368
|
+
Duty?: TimestampedValue<number>;
|
|
348
369
|
/** Heat sink temperature */
|
|
349
|
-
HeatSink
|
|
370
|
+
HeatSink?: TimestampedValue<number>;
|
|
350
371
|
/** Time the device has been off */
|
|
351
|
-
OffTime
|
|
372
|
+
OffTime?: TimestampedValue<number>;
|
|
352
373
|
/** Connection status */
|
|
353
|
-
Connected
|
|
374
|
+
Connected?: TimestampedValue<boolean>;
|
|
354
375
|
/** Current consumption */
|
|
355
|
-
Current
|
|
376
|
+
Current?: TimestampedValue<number>;
|
|
356
377
|
/** Humidity reading */
|
|
357
|
-
Humidity
|
|
378
|
+
Humidity?: TimestampedValue<number>;
|
|
358
379
|
/** Lock status */
|
|
359
|
-
Lock
|
|
380
|
+
Lock?: TimestampedValue<number>;
|
|
381
|
+
/** Fan speed */
|
|
382
|
+
FanSpeed?: TimestampedValue<number>;
|
|
360
383
|
}
|
|
361
384
|
/**
|
|
362
385
|
* Collection of device states indexed by device ID
|
|
@@ -446,10 +469,12 @@ interface DeviceStateChange extends MsgPayload<OutMessageType.DEVICE_STATE_CHANG
|
|
|
446
469
|
ho: number;
|
|
447
470
|
/** Unknown */
|
|
448
471
|
lk: number;
|
|
449
|
-
/** Device mode (1 = OFF, 3 = HEAT) */
|
|
472
|
+
/** Device mode (1 = OFF, 2 = AUTO, 3 = HEAT, 4 = COOL, 5 = FAN_ONLY, 6 = DRY) */
|
|
450
473
|
md: number;
|
|
451
474
|
/** Temperature setpoint */
|
|
452
475
|
sp: number;
|
|
476
|
+
/** Optional fan speed (1 = auto, 3 = low, 5 = medium, 7 = high, 8 = max). AC only */
|
|
477
|
+
fn?: number;
|
|
453
478
|
};
|
|
454
479
|
/** Success indicator for the state change operation (1 = success, 0 = failure) */
|
|
455
480
|
success: number;
|
|
@@ -670,6 +695,13 @@ interface MysaApiClientOptions {
|
|
|
670
695
|
fetcher?: typeof fetch;
|
|
671
696
|
}
|
|
672
697
|
|
|
698
|
+
/** Options for MQTT publish operations. */
|
|
699
|
+
interface MqttPublishOptions {
|
|
700
|
+
/** Maximum number of publish attempts before failing (default: 5). */
|
|
701
|
+
maxAttempts?: number;
|
|
702
|
+
/** Base delay in milliseconds used for exponential backoff calculation (default: 500). */
|
|
703
|
+
baseDelayMs?: number;
|
|
704
|
+
}
|
|
673
705
|
/**
|
|
674
706
|
* Main client for interacting with the Mysa API and real-time device communication.
|
|
675
707
|
*
|
|
@@ -831,15 +863,20 @@ declare class MysaApiClient {
|
|
|
831
863
|
*
|
|
832
864
|
* // Set temperature and mode
|
|
833
865
|
* await client.setDeviceState('device123', 20, 'heat');
|
|
866
|
+
*
|
|
867
|
+
* // Set fan speed
|
|
868
|
+
* await client.setDeviceState('device123', undefined, undefined, 'auto');
|
|
834
869
|
* ```
|
|
835
870
|
*
|
|
836
871
|
* @param deviceId - The ID of the device to control.
|
|
837
872
|
* @param setPoint - The target temperature set point (optional).
|
|
838
|
-
* @param mode - The operating mode to set (
|
|
873
|
+
* @param mode - The operating mode to set (one of MysaDeviceMode values, or undefined to leave unchanged).
|
|
874
|
+
* @param fanSpeed - The fan speed mode to set ('low', 'medium', 'high', 'max', 'auto', or undefined to leave
|
|
875
|
+
* unchanged).
|
|
839
876
|
* @throws {@link UnauthenticatedError} When the user is not authenticated.
|
|
840
877
|
* @throws {@link Error} When MQTT connection or command sending fails.
|
|
841
878
|
*/
|
|
842
|
-
setDeviceState(deviceId: string, setPoint?: number, mode?: MysaDeviceMode): Promise<void>;
|
|
879
|
+
setDeviceState(deviceId: string, setPoint?: number, mode?: MysaDeviceMode, fanSpeed?: MysaFanSpeedMode): Promise<void>;
|
|
843
880
|
/**
|
|
844
881
|
* Starts receiving real-time updates for the specified device.
|
|
845
882
|
*
|
|
@@ -881,7 +918,7 @@ declare class MysaApiClient {
|
|
|
881
918
|
* @returns A promise that resolves to a valid CognitoUserSession.
|
|
882
919
|
* @throws {@link UnauthenticatedError} When no session exists or refresh fails.
|
|
883
920
|
*/
|
|
884
|
-
private
|
|
921
|
+
private _getFreshSession;
|
|
885
922
|
/**
|
|
886
923
|
* Establishes and returns an MQTT connection for real-time communication.
|
|
887
924
|
*
|
|
@@ -891,14 +928,49 @@ declare class MysaApiClient {
|
|
|
891
928
|
* @returns A promise that resolves to an active MQTT connection.
|
|
892
929
|
* @throws {@link Error} When connection establishment fails.
|
|
893
930
|
*/
|
|
894
|
-
private
|
|
931
|
+
private _getMqttConnection;
|
|
932
|
+
/**
|
|
933
|
+
* Determines whether an MQTT-related error is considered transient and worth retrying.
|
|
934
|
+
*
|
|
935
|
+
* Transient errors include timeouts, cancelled operations due to clean sessions, temporary connectivity loss, and
|
|
936
|
+
* other recoverable network issues. Fatal errors (auth, permission, configuration) should not be retried at this
|
|
937
|
+
* layer.
|
|
938
|
+
*
|
|
939
|
+
* @param err - The error object thrown by the underlying MQTT operation.
|
|
940
|
+
* @returns True if the error appears transient and a retry should be attempted; false otherwise.
|
|
941
|
+
*/
|
|
942
|
+
private _isTransientMqttError;
|
|
943
|
+
/**
|
|
944
|
+
* Publishes an MQTT message with exponential backoff retries for transient failures.
|
|
945
|
+
*
|
|
946
|
+
* Retries occur for errors classified by `_isTransientMqttError`. Between attempts the delay grows exponentially with
|
|
947
|
+
* jitter to avoid thundering herds after broker recovery. If the connection is not currently marked as connected, a
|
|
948
|
+
* reconnect is attempted; if that fails, the connection is rebuilt (fresh credentials) before the next retry.
|
|
949
|
+
*
|
|
950
|
+
* On final failure (after maxAttempts) a {@link MqttPublishError} is thrown including the number of attempts and
|
|
951
|
+
* original error for higher-level handling.
|
|
952
|
+
*
|
|
953
|
+
* @remarks
|
|
954
|
+
* Retry options fields:
|
|
955
|
+
*
|
|
956
|
+
* - MaxAttempts: Maximum number of publish attempts before failing (default: 5).
|
|
957
|
+
* - BaseDelayMs: Base delay in milliseconds used for exponential backoff calculation (default: 500).
|
|
958
|
+
*
|
|
959
|
+
* @param connection - The active MQTT client connection used to send the publish.
|
|
960
|
+
* @param topic - The MQTT topic to publish to.
|
|
961
|
+
* @param payload - The serialized payload (binary buffer or Uint8Array).
|
|
962
|
+
* @param qos - The desired MQTT QoS level for the publish.
|
|
963
|
+
* @param opts - Retry options (defaults: maxAttempts=5, baseDelayMs=500).
|
|
964
|
+
* @returns A promise that resolves when the publish succeeds, or rejects with {@link MqttPublishError}.
|
|
965
|
+
*/
|
|
966
|
+
private _publishWithRetry;
|
|
895
967
|
/**
|
|
896
968
|
* Creates a new MQTT connection using AWS IoT WebSocket connections with Cognito credentials.
|
|
897
969
|
*
|
|
898
970
|
* @returns A promise that resolves to an active MQTT connection.
|
|
899
971
|
* @throws {@link Error} When connection establishment fails.
|
|
900
972
|
*/
|
|
901
|
-
private
|
|
973
|
+
private _createMqttConnection;
|
|
902
974
|
/**
|
|
903
975
|
* Processes incoming MQTT messages and emits appropriate events.
|
|
904
976
|
*
|
|
@@ -908,7 +980,7 @@ declare class MysaApiClient {
|
|
|
908
980
|
*
|
|
909
981
|
* @param payload - The raw MQTT message payload to process.
|
|
910
982
|
*/
|
|
911
|
-
private
|
|
983
|
+
private _processMqttMessage;
|
|
912
984
|
}
|
|
913
985
|
|
|
914
986
|
/**
|
|
@@ -961,6 +1033,8 @@ interface ChangeDeviceState extends MsgPayload<InMessageType.CHANGE_DEVICE_STATE
|
|
|
961
1033
|
md?: number;
|
|
962
1034
|
/** Unknown, should always be -1 */
|
|
963
1035
|
tm: number;
|
|
1036
|
+
/** Optional fan speed (1 = auto, 3 = low, 5 = medium, 7 = high, 8 = max). AC only */
|
|
1037
|
+
fn?: number;
|
|
964
1038
|
}
|
|
965
1039
|
];
|
|
966
1040
|
/**
|
|
@@ -1019,4 +1093,4 @@ type MsgTypeInPayload = CheckDeviceSettings | StartPublishingDeviceStatus;
|
|
|
1019
1093
|
*/
|
|
1020
1094
|
type InPayload = MsgTypeInPayload | MsgInPayload;
|
|
1021
1095
|
|
|
1022
|
-
export { type BrandInfo, type ChangeDeviceState, type CheckDeviceSettings, type DeviceBase, type DeviceLog, type DevicePostBoot, type DeviceSetpointChange, type DeviceState, type DeviceStateChange, type DeviceStates, type DeviceStatesObj, type DeviceV1Status, type DeviceV2Status, type Devices, type DevicesObj, type FirmwareDevice, type Firmwares, InMessageType, type InPayload, type Logger, type ModeObj, type MsgBasePayload, type MsgInPayload, type MsgOutPayload, type MsgPayload, type MsgTypeBasePayload, type MsgTypeInPayload, type MsgTypeOutPayload, type MsgTypePayload, MysaApiClient, type MysaApiClientEventTypes, type MysaApiClientOptions, MysaApiError, type MysaDeviceMode, type MysaSession, OutMessageType, type OutPayload, type SetPointChange, type StartPublishingDeviceStatus, type StateChange, type Status, type SupportedCaps, type TimestampedValue, UnauthenticatedError, VoidLogger };
|
|
1096
|
+
export { type BrandInfo, type ChangeDeviceState, type CheckDeviceSettings, type DeviceBase, type DeviceLog, type DevicePostBoot, type DeviceSetpointChange, type DeviceState, type DeviceStateChange, type DeviceStates, type DeviceStatesObj, type DeviceV1Status, type DeviceV2Status, type Devices, type DevicesObj, type FirmwareDevice, type Firmwares, InMessageType, type InPayload, type Logger, type ModeObj, MqttPublishError, type MqttPublishOptions, type MsgBasePayload, type MsgInPayload, type MsgOutPayload, type MsgPayload, type MsgTypeBasePayload, type MsgTypeInPayload, type MsgTypeOutPayload, type MsgTypePayload, MysaApiClient, type MysaApiClientEventTypes, type MysaApiClientOptions, MysaApiError, type MysaDeviceMode, type MysaFanSpeedMode, type MysaSession, OutMessageType, type OutPayload, type SetPointChange, type StartPublishingDeviceStatus, type StateChange, type Status, type SupportedCaps, type TimestampedValue, UnauthenticatedError, VoidLogger };
|