mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-10 15:17:41 +00:00
return device status for each device
This commit is contained in:
@ -6,6 +6,7 @@ import {
|
||||
ConvertedAction,
|
||||
TuyaResponseInterface,
|
||||
} from '../interfaces';
|
||||
import { GetDeviceDetailsFunctionsStatusInterface } from 'src/device/interfaces/get.device.interface';
|
||||
|
||||
@Injectable()
|
||||
export class TuyaService {
|
||||
@ -284,4 +285,24 @@ export class TuyaService {
|
||||
);
|
||||
}
|
||||
}
|
||||
async getDevicesInstructionStatusTuya(
|
||||
deviceUuid: string,
|
||||
): Promise<GetDeviceDetailsFunctionsStatusInterface> {
|
||||
try {
|
||||
const path = `/v1.0/iot-03/devices/status`;
|
||||
const response = await this.tuya.request({
|
||||
method: 'GET',
|
||||
path,
|
||||
query: {
|
||||
device_ids: deviceUuid,
|
||||
},
|
||||
});
|
||||
return response as GetDeviceDetailsFunctionsStatusInterface;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
'Error fetching device functions status from Tuya',
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,10 @@ export class SpaceDeviceService {
|
||||
const tuyaDetails = await this.getDeviceDetailsByDeviceIdTuya(
|
||||
device.deviceTuyaUuid,
|
||||
);
|
||||
|
||||
const tuyaDeviceStatus =
|
||||
await this.tuyaService.getDevicesInstructionStatusTuya(
|
||||
device.deviceTuyaUuid,
|
||||
);
|
||||
return {
|
||||
uuid: device.uuid,
|
||||
deviceTuyaUuid: device.deviceTuyaUuid,
|
||||
@ -45,7 +48,10 @@ export class SpaceDeviceService {
|
||||
productType: device.productDevice.prodType,
|
||||
isActive: device.isActive,
|
||||
updatedAt: device.updatedAt,
|
||||
deviceTag: device.tag,
|
||||
subspace: device.subspace,
|
||||
...tuyaDetails,
|
||||
status: tuyaDeviceStatus.result[0].status,
|
||||
};
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
|
Reference in New Issue
Block a user