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 { 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, Firmwares } from '@/types/rest';
|
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,
|
||||||
@@ -213,6 +213,24 @@ export class MysaApiClient {
|
|||||||
return response.json();
|
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) {
|
async setDeviceState(deviceId: string, setPoint?: number, mode?: MysaDeviceMode) {
|
||||||
this._logger.debug(`Setting device state for '${deviceId}'`);
|
this._logger.debug(`Setting device state for '${deviceId}'`);
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,17 @@
|
|||||||
|
/** Device firmware information */
|
||||||
export interface FirmwareDevice {
|
export interface FirmwareDevice {
|
||||||
|
/** Device ID */
|
||||||
Device: string;
|
Device: string;
|
||||||
|
/** Device firmware version */
|
||||||
InstalledVersion: string;
|
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 {
|
export interface Firmwares {
|
||||||
Firmware: Record<string, FirmwareDevice>;
|
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,2 +1,3 @@
|
|||||||
export * from './Devices';
|
export * from './Devices';
|
||||||
export * from './Firmwares';
|
export * from './Firmwares';
|
||||||
|
export * from './States';
|
||||||
|
|||||||
Reference in New Issue
Block a user