Add handling to differentiate between switching AC power and set its temperature

This commit is contained in:
ian
2026-01-19 22:35:10 +07:00
parent bea0491211
commit f56f87aa18
2 changed files with 17 additions and 7 deletions
+3 -3
View File
@@ -1,4 +1,4 @@
import { dataMapping } from '~/helpers/utils'
import { getDeviceCommand } from '~/helpers/utils'
import { DeviceCommandBody } from '../schema'
import { sendCommandToThirdParty } from './command'
import { alphabetToNumberString } from '~/helpers/alphabet_conversion'
@@ -11,8 +11,8 @@ export default abstract class CommandService {
}> {
const unitNumber = alphabetToNumberString(body.unitNumber)
const topicData = `${body.merchantName}/${body.floorName}_${unitNumber}-${body.deviceName}-${body.roomName}-${body.deviceType}-${body.commandType}-${body.towerNumber}`
const cmd = dataMapping.find((device) => device.deviceName == body.deviceName)
const request = await sendCommandToThirdParty(topicData, `${cmd?.command}${body.payload.action}`)
const cmd = getDeviceCommand(body.deviceName, body.deviceType)
const request = await sendCommandToThirdParty(topicData, `${cmd}${body.payload.action}`)
if (request.status !== 200 || request.data.status == 400) {
return {
status: 'error' as const,