mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-27 00:14:54 +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: {
|
where: {
|
||||||
uuid: updateDeviceInRoomDto.deviceUuid,
|
uuid: updateDeviceInRoomDto.deviceUuid,
|
||||||
},
|
},
|
||||||
relations: ['spaceDevice'],
|
relations: ['spaceDevice', 'spaceDevice.parent'],
|
||||||
});
|
});
|
||||||
|
if (device.spaceDevice.parent.spaceTuyaUuid) {
|
||||||
|
await this.transferDeviceInSpacesTuya(
|
||||||
|
device.deviceTuyaUuid,
|
||||||
|
device.spaceDevice.parent.spaceTuyaUuid,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
uuid: device.uuid,
|
uuid: device.uuid,
|
||||||
roomUuid: device.spaceDevice.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) {
|
async controlDevice(controlDeviceDto: ControlDeviceDto, deviceUuid: string) {
|
||||||
try {
|
try {
|
||||||
const deviceDetails = await this.getDeviceByDeviceUuid(deviceUuid, false);
|
const deviceDetails = await this.getDeviceByDeviceUuid(deviceUuid, false);
|
||||||
|
|||||||
Reference in New Issue
Block a user