mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-10 15:17:41 +00:00
Transfer device to parent space in Tuya when updating device in room
This commit is contained in:
@ -197,8 +197,15 @@ export class DeviceService {
|
||||
where: {
|
||||
uuid: updateDeviceInRoomDto.deviceUuid,
|
||||
},
|
||||
relations: ['spaceDevice'],
|
||||
relations: ['spaceDevice', 'spaceDevice.parent'],
|
||||
});
|
||||
if (device.spaceDevice.parent.spaceTuyaUuid) {
|
||||
await this.transferDeviceInSpacesTuya(
|
||||
device.deviceTuyaUuid,
|
||||
device.spaceDevice.parent.spaceTuyaUuid,
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
uuid: device.uuid,
|
||||
roomUuid: device.spaceDevice.uuid,
|
||||
@ -210,7 +217,26 @@ export class DeviceService {
|
||||
);
|
||||
}
|
||||
}
|
||||
async transferDeviceInSpacesTuya(
|
||||
deviceId: string,
|
||||
spaceId: string,
|
||||
): Promise<controlDeviceInterface> {
|
||||
try {
|
||||
const path = `/v2.0/cloud/thing/${deviceId}/transfer`;
|
||||
const response = await this.tuya.request({
|
||||
method: 'POST',
|
||||
path,
|
||||
body: { space_id: spaceId },
|
||||
});
|
||||
|
||||
return response as controlDeviceInterface;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
'Error transferring device in spaces from Tuya',
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
async controlDevice(controlDeviceDto: ControlDeviceDto, deviceUuid: string) {
|
||||
try {
|
||||
const deviceDetails = await this.getDeviceByDeviceUuid(deviceUuid, false);
|
||||
|
Reference in New Issue
Block a user