feat: Added getDeviceStates API

This commit is contained in:
Pascal Bourque
2025-06-02 07:25:04 -04:00
parent be940daf91
commit 6b4e41828a
4 changed files with 98 additions and 1 deletions

View File

@@ -6,7 +6,7 @@ import { ChangeDeviceState } from '@/types/mqtt/in/ChangeDeviceState';
import { InMessageType } from '@/types/mqtt/in/InMessageType';
import { StartPublishingDeviceStatus } from '@/types/mqtt/in/StartPublishingDeviceStatus';
import { OutMessageType } from '@/types/mqtt/out/OutMessageType';
import { Devices, Firmwares } from '@/types/rest';
import { Devices, DeviceStates, Firmwares } from '@/types/rest';
import { fromCognitoIdentityPool } from '@aws-sdk/credential-providers';
import {
AuthenticationDetails,
@@ -213,6 +213,24 @@ export class MysaApiClient {
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()}`
}
});
if (!response.ok) {
throw new MysaApiError(response);
}
return response.json();
}
async setDeviceState(deviceId: string, setPoint?: number, mode?: MysaDeviceMode) {
this._logger.debug(`Setting device state for '${deviceId}'`);