finished get mac address api

This commit is contained in:
faris Aljohari
2024-11-16 23:18:20 -06:00
parent d3724f0417
commit c7a6986292
2 changed files with 28 additions and 0 deletions

View File

@ -90,3 +90,9 @@ export interface GetPowerClampFunctionsStatusInterface {
success: boolean;
msg: string;
}
export interface GetMacAddressInterface {
uuid: string;
mac: string;
sn: string;
id: string;
}

View File

@ -20,6 +20,7 @@ import {
GetDeviceDetailsFunctionsInterface,
GetDeviceDetailsFunctionsStatusInterface,
GetDeviceDetailsInterface,
GetMacAddressInterface,
GetPowerClampFunctionsStatusInterface,
controlDeviceInterface,
getDeviceLogsInterface,
@ -535,6 +536,9 @@ export class DeviceService {
const response = await this.getDeviceDetailsByDeviceIdTuya(
deviceDetails.deviceTuyaUuid,
);
const macAddress = await this.getMacAddressByDeviceIdTuya(
deviceDetails.deviceTuyaUuid,
);
return {
...response,
@ -542,6 +546,7 @@ export class DeviceService {
productUuid: deviceDetails.productDevice.uuid,
productType: deviceDetails.productDevice.prodType,
permissionType: userDevicePermission,
macAddress: macAddress.mac,
};
} catch (error) {
throw new HttpException(
@ -582,7 +587,24 @@ export class DeviceService {
);
}
}
async getMacAddressByDeviceIdTuya(
deviceId: string,
): Promise<GetMacAddressInterface> {
try {
const path = `/v1.0/devices/factory-infos?device_ids=${deviceId}`;
const response = await this.tuya.request({
method: 'GET',
path,
});
return response.result[0];
} catch (error) {
throw new HttpException(
'Error fetching mac address device from Tuya',
HttpStatus.INTERNAL_SERVER_ERROR,
);
}
}
async getDeviceInstructionByDeviceId(
deviceUuid: string,
): Promise<DeviceInstructionResponse> {