mirror of
https://github.com/SyncrowIOT/backend.git
synced 2026-10-26 01:57:53 +00:00
Refactor Device Module
This commit is contained in:
@@ -43,7 +43,7 @@ export class GroupService {
|
||||
const groupDevices = await this.groupDeviceRepository.find({
|
||||
relations: ['group', 'device'],
|
||||
where: {
|
||||
device: { spaceUuid },
|
||||
device: { spaceDevice: { uuid: spaceUuid } },
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
@@ -129,22 +129,26 @@ export class GroupService {
|
||||
}
|
||||
}
|
||||
async controlDevice(controlDeviceDto: ControlDeviceDto) {
|
||||
const response = await this.controlDeviceTuya(controlDeviceDto);
|
||||
try {
|
||||
const response = await this.controlDeviceTuya(controlDeviceDto);
|
||||
|
||||
if (response.success) {
|
||||
return response;
|
||||
} else {
|
||||
throw new HttpException(
|
||||
response.msg || 'Unknown error',
|
||||
HttpStatus.BAD_REQUEST,
|
||||
);
|
||||
if (response.success) {
|
||||
return response;
|
||||
} else {
|
||||
throw new HttpException(
|
||||
response.msg || 'Unknown error',
|
||||
HttpStatus.BAD_REQUEST,
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
throw new HttpException('Device Not Found', HttpStatus.NOT_FOUND);
|
||||
}
|
||||
}
|
||||
async controlDeviceTuya(
|
||||
controlDeviceDto: ControlDeviceDto,
|
||||
): Promise<controlDeviceInterface> {
|
||||
try {
|
||||
const path = `/v1.0/iot-03/devices/${controlDeviceDto.deviceId}/commands`;
|
||||
const path = `/v1.0/iot-03/devices/${controlDeviceDto.deviceUuid}/commands`;
|
||||
const response = await this.tuya.request({
|
||||
method: 'POST',
|
||||
path,
|
||||
@@ -170,7 +174,7 @@ export class GroupService {
|
||||
await Promise.all(
|
||||
devices.map(async (device) => {
|
||||
return this.controlDevice({
|
||||
deviceId: device.device.deviceTuyaUuid,
|
||||
deviceUuid: device.device.deviceTuyaUuid,
|
||||
code: controlGroupDto.code,
|
||||
value: controlGroupDto.value,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user