mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 10:44:55 +00:00
finished update name device api
This commit is contained in:
@ -13,6 +13,7 @@ import { ConfigService } from '@nestjs/config';
|
||||
import {
|
||||
AddDeviceDto,
|
||||
AddSceneToFourSceneDeviceDto,
|
||||
UpdateDeviceDto,
|
||||
UpdateDeviceInSpaceDto,
|
||||
} from '../dtos/add.device.dto';
|
||||
import {
|
||||
@ -291,6 +292,26 @@ export class DeviceService {
|
||||
);
|
||||
}
|
||||
}
|
||||
async updateDeviceNameTuya(
|
||||
deviceId: string,
|
||||
deviceName: string,
|
||||
): Promise<controlDeviceInterface> {
|
||||
try {
|
||||
const path = `/v2.0/cloud/thing/${deviceId}/attribute`;
|
||||
const response = await this.tuya.request({
|
||||
method: 'POST',
|
||||
path,
|
||||
body: { type: 1, data: deviceName },
|
||||
});
|
||||
|
||||
return response as controlDeviceInterface;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
'Error updating device name from Tuya',
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
async controlDevice(controlDeviceDto: ControlDeviceDto, deviceUuid: string) {
|
||||
try {
|
||||
const deviceDetails = await this.getDeviceByDeviceUuid(deviceUuid, false);
|
||||
@ -555,6 +576,27 @@ export class DeviceService {
|
||||
);
|
||||
}
|
||||
}
|
||||
async updateDevice(deviceUuid: string, updateDeviceDto: UpdateDeviceDto) {
|
||||
try {
|
||||
const device = await this.getDeviceByDeviceUuid(deviceUuid);
|
||||
if (device.deviceTuyaUuid) {
|
||||
await this.updateDeviceNameTuya(
|
||||
device.deviceTuyaUuid,
|
||||
updateDeviceDto.deviceName,
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
uuid: device.uuid,
|
||||
deviceName: updateDeviceDto.deviceName,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
'Error updating device',
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
async getDeviceDetailsByDeviceIdTuya(
|
||||
deviceId: string,
|
||||
): Promise<GetDeviceDetailsInterface> {
|
||||
|
||||
Reference in New Issue
Block a user