mirror of
https://github.com/bourquep/mysa-js-sdk.git
synced 2026-02-04 09:41:07 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6b4e41828a | ||
|
|
be940daf91 | ||
|
|
847b9abf5e | ||
|
|
17d7e9b7b0 | ||
|
|
9df5030228 | ||
|
|
5ae54dd05d | ||
|
|
4039f5f165 | ||
|
|
45ae56f0f9 |
@@ -92,4 +92,6 @@ async function main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
main().catch(rootLogger.error);
|
main().catch((error) => {
|
||||||
|
rootLogger.error(error, 'Error in main');
|
||||||
|
});
|
||||||
|
|||||||
1099
package-lock.json
generated
1099
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
14
package.json
14
package.json
@@ -46,21 +46,21 @@
|
|||||||
"build:docs": "typedoc"
|
"build:docs": "typedoc"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@aws-sdk/credential-providers": "3.817.0",
|
"@aws-sdk/credential-providers": "3.821.0",
|
||||||
"amazon-cognito-identity-js": "6.3.15",
|
"amazon-cognito-identity-js": "6.3.15",
|
||||||
"aws-iot-device-sdk-v2": "1.21.4",
|
"aws-iot-device-sdk-v2": "1.21.4",
|
||||||
"dayjs": "1.11.13",
|
"dayjs": "1.11.13",
|
||||||
"lodash": "4.17.21"
|
"lodash": "4.17.21"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/js": "9.27.0",
|
"@eslint/js": "9.28.0",
|
||||||
"@semantic-release/npm": "12.0.1",
|
"@semantic-release/npm": "12.0.1",
|
||||||
"@types/lodash": "4.17.17",
|
"@types/lodash": "4.17.17",
|
||||||
"@types/node": "22.15.21",
|
"@types/node": "22.15.29",
|
||||||
"conventional-changelog-conventionalcommits": "9.0.0",
|
"conventional-changelog-conventionalcommits": "9.0.0",
|
||||||
"dotenv": "16.5.0",
|
"dotenv": "16.5.0",
|
||||||
"eslint": "9.27.0",
|
"eslint": "9.28.0",
|
||||||
"eslint-plugin-jsdoc": "50.6.17",
|
"eslint-plugin-jsdoc": "50.7.1",
|
||||||
"eslint-plugin-tsdoc": "0.4.0",
|
"eslint-plugin-tsdoc": "0.4.0",
|
||||||
"pino": "9.7.0",
|
"pino": "9.7.0",
|
||||||
"pino-pretty": "13.0.0",
|
"pino-pretty": "13.0.0",
|
||||||
@@ -70,9 +70,9 @@
|
|||||||
"semantic-release": "24.2.5",
|
"semantic-release": "24.2.5",
|
||||||
"tsup": "8.5.0",
|
"tsup": "8.5.0",
|
||||||
"tsx": "4.19.4",
|
"tsx": "4.19.4",
|
||||||
"typedoc": "0.28.4",
|
"typedoc": "0.28.5",
|
||||||
"typedoc-material-theme": "1.4.0",
|
"typedoc-material-theme": "1.4.0",
|
||||||
"typescript": "5.8.3",
|
"typescript": "5.8.3",
|
||||||
"typescript-eslint": "8.32.1"
|
"typescript-eslint": "8.33.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { ChangeDeviceState } from '@/types/mqtt/in/ChangeDeviceState';
|
|||||||
import { InMessageType } from '@/types/mqtt/in/InMessageType';
|
import { InMessageType } from '@/types/mqtt/in/InMessageType';
|
||||||
import { StartPublishingDeviceStatus } from '@/types/mqtt/in/StartPublishingDeviceStatus';
|
import { StartPublishingDeviceStatus } from '@/types/mqtt/in/StartPublishingDeviceStatus';
|
||||||
import { OutMessageType } from '@/types/mqtt/out/OutMessageType';
|
import { OutMessageType } from '@/types/mqtt/out/OutMessageType';
|
||||||
import { Devices } from '@/types/rest/Devices';
|
import { Devices, DeviceStates, Firmwares } from '@/types/rest';
|
||||||
import { fromCognitoIdentityPool } from '@aws-sdk/credential-providers';
|
import { fromCognitoIdentityPool } from '@aws-sdk/credential-providers';
|
||||||
import {
|
import {
|
||||||
AuthenticationDetails,
|
AuthenticationDetails,
|
||||||
@@ -184,7 +184,43 @@ export class MysaApiClient {
|
|||||||
|
|
||||||
const response = await this._fetcher(`${MysaApiBaseUrl}/devices`, {
|
const response = await this._fetcher(`${MysaApiBaseUrl}/devices`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `${session.getAccessToken().getJwtToken()}`
|
Authorization: `${session.getIdToken().getJwtToken()}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new MysaApiError(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
async getDeviceFirmwares(): Promise<Firmwares> {
|
||||||
|
this._logger.debug(`Fetching device firmwares...`);
|
||||||
|
|
||||||
|
const session = await this.getFreshSession();
|
||||||
|
|
||||||
|
const response = await this._fetcher(`${MysaApiBaseUrl}/devices/firmware`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: `${session.getIdToken().getJwtToken()}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new MysaApiError(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
async getDeviceStates(): Promise<DeviceStates> {
|
||||||
|
this._logger.debug(`Fetching device states...`);
|
||||||
|
|
||||||
|
const session = await this.getFreshSession();
|
||||||
|
|
||||||
|
const response = await this._fetcher(`${MysaApiBaseUrl}/devices/state`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: `${session.getIdToken().getJwtToken()}`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -320,7 +356,7 @@ export class MysaApiClient {
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
this._cognitoUserSession.isValid() &&
|
this._cognitoUserSession.isValid() &&
|
||||||
dayjs.unix(this._cognitoUserSession.getAccessToken().getExpiration()).isAfter()
|
dayjs.unix(this._cognitoUserSession.getIdToken().getExpiration()).isAfter()
|
||||||
) {
|
) {
|
||||||
this._logger.info('Session is valid, no need to refresh');
|
this._logger.info('Session is valid, no need to refresh');
|
||||||
return Promise.resolve(this._cognitoUserSession);
|
return Promise.resolve(this._cognitoUserSession);
|
||||||
|
|||||||
17
src/types/rest/Firmwares.ts
Normal file
17
src/types/rest/Firmwares.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
/** Device firmware information */
|
||||||
|
export interface FirmwareDevice {
|
||||||
|
/** Device ID */
|
||||||
|
Device: string;
|
||||||
|
/** Device firmware version */
|
||||||
|
InstalledVersion: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collection of firmware devices indexed by device ID
|
||||||
|
*
|
||||||
|
* Maps device ID strings to their corresponding firmware device objects, providing a lookup table for all devices
|
||||||
|
* associated with a user account.
|
||||||
|
*/
|
||||||
|
export interface Firmwares {
|
||||||
|
Firmware: Record<string, FirmwareDevice>;
|
||||||
|
}
|
||||||
69
src/types/rest/States.ts
Normal file
69
src/types/rest/States.ts
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
/** Represents a timestamped value with metadata */
|
||||||
|
export interface TimestampedValue<T = number> {
|
||||||
|
/** Timestamp when the value was recorded */
|
||||||
|
t: number;
|
||||||
|
/** The actual value */
|
||||||
|
v: T;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Represents the state of a single device */
|
||||||
|
export interface DeviceState {
|
||||||
|
/** Device identifier */
|
||||||
|
Device: string;
|
||||||
|
/** Overall timestamp for the device state */
|
||||||
|
Timestamp: number;
|
||||||
|
/** Time the device has been on */
|
||||||
|
OnTime: TimestampedValue<number>;
|
||||||
|
/** Temperature set point */
|
||||||
|
SetPoint: TimestampedValue<number>;
|
||||||
|
/** Display brightness level */
|
||||||
|
Brightness: TimestampedValue<number>;
|
||||||
|
/** Schedule mode setting */
|
||||||
|
ScheduleMode: TimestampedValue<number>;
|
||||||
|
/** Hold time setting */
|
||||||
|
HoldTime: TimestampedValue<number>;
|
||||||
|
/** Wi-Fi signal strength */
|
||||||
|
Rssi: TimestampedValue<number>;
|
||||||
|
/** Thermostat mode */
|
||||||
|
TstatMode: TimestampedValue<number>;
|
||||||
|
/** Available heap memory */
|
||||||
|
FreeHeap: TimestampedValue<number>;
|
||||||
|
/** Sensor temperature reading */
|
||||||
|
SensorTemp: TimestampedValue<number>;
|
||||||
|
/** Current mode */
|
||||||
|
Mode: TimestampedValue<number>;
|
||||||
|
/** Voltage measurement */
|
||||||
|
Voltage: TimestampedValue<number>;
|
||||||
|
/** Temperature corrected for calibration */
|
||||||
|
CorrectedTemp: TimestampedValue<number>;
|
||||||
|
/** Duty cycle percentage */
|
||||||
|
Duty: TimestampedValue<number>;
|
||||||
|
/** Heat sink temperature */
|
||||||
|
HeatSink: TimestampedValue<number>;
|
||||||
|
/** Time the device has been off */
|
||||||
|
OffTime: TimestampedValue<number>;
|
||||||
|
/** Connection status */
|
||||||
|
Connected: TimestampedValue<boolean>;
|
||||||
|
/** Current consumption */
|
||||||
|
Current: TimestampedValue<number>;
|
||||||
|
/** Humidity reading */
|
||||||
|
Humidity: TimestampedValue<number>;
|
||||||
|
/** Lock status */
|
||||||
|
Lock: TimestampedValue<number>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collection of device states indexed by device ID
|
||||||
|
*
|
||||||
|
* Maps device ID strings to their corresponding device state objects, providing a lookup table for all devices
|
||||||
|
* associated with a user account.
|
||||||
|
*/
|
||||||
|
export interface DeviceStatesObj {
|
||||||
|
/** Device state objects indexed by their unique device ID strings */
|
||||||
|
[deviceId: string]: DeviceState;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Top-level interface for the device states REST API response. */
|
||||||
|
export interface DeviceStates {
|
||||||
|
DeviceStatesObj: DeviceStatesObj;
|
||||||
|
}
|
||||||
@@ -1 +1,3 @@
|
|||||||
export * from './Devices';
|
export * from './Devices';
|
||||||
|
export * from './Firmwares';
|
||||||
|
export * from './States';
|
||||||
|
|||||||
Reference in New Issue
Block a user