mirror of
https://github.com/bourquep/mysa-js-sdk.git
synced 2026-02-04 01:31:05 +00:00
feat: Added getDeviceStates API
This commit is contained in:
@@ -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}'`);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user