mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 16:34:55 +00:00
return device status for each device
This commit is contained in:
@ -6,6 +6,7 @@ import {
|
|||||||
ConvertedAction,
|
ConvertedAction,
|
||||||
TuyaResponseInterface,
|
TuyaResponseInterface,
|
||||||
} from '../interfaces';
|
} from '../interfaces';
|
||||||
|
import { GetDeviceDetailsFunctionsStatusInterface } from 'src/device/interfaces/get.device.interface';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TuyaService {
|
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(
|
const tuyaDetails = await this.getDeviceDetailsByDeviceIdTuya(
|
||||||
device.deviceTuyaUuid,
|
device.deviceTuyaUuid,
|
||||||
);
|
);
|
||||||
|
const tuyaDeviceStatus =
|
||||||
|
await this.tuyaService.getDevicesInstructionStatusTuya(
|
||||||
|
device.deviceTuyaUuid,
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
uuid: device.uuid,
|
uuid: device.uuid,
|
||||||
deviceTuyaUuid: device.deviceTuyaUuid,
|
deviceTuyaUuid: device.deviceTuyaUuid,
|
||||||
@ -45,7 +48,10 @@ export class SpaceDeviceService {
|
|||||||
productType: device.productDevice.prodType,
|
productType: device.productDevice.prodType,
|
||||||
isActive: device.isActive,
|
isActive: device.isActive,
|
||||||
updatedAt: device.updatedAt,
|
updatedAt: device.updatedAt,
|
||||||
|
deviceTag: device.tag,
|
||||||
|
subspace: device.subspace,
|
||||||
...tuyaDetails,
|
...tuyaDetails,
|
||||||
|
status: tuyaDeviceStatus.result[0].status,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn(
|
console.warn(
|
||||||
|
|||||||
Reference in New Issue
Block a user