Add handling to differentiate between switching AC power and set its temperature
This commit is contained in:
+14
-4
@@ -5,22 +5,32 @@ export const passwordVerify = (password: string, hash: string) => Bun.password.v
|
|||||||
export const dataMapping = [
|
export const dataMapping = [
|
||||||
{
|
{
|
||||||
deviceName: 'AC',
|
deviceName: 'AC',
|
||||||
|
deviceType: 'S',
|
||||||
command: 'AC=',
|
command: 'AC=',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
deviceName: 'AC',
|
||||||
|
deviceType: 'A',
|
||||||
|
command: 'Temp=',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
deviceName: 'L',
|
deviceName: 'L',
|
||||||
|
deviceType: 'S',
|
||||||
command: 'Light=',
|
command: 'Light=',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
deviceName: 'DL',
|
deviceName: 'DL',
|
||||||
|
deviceType: 'S',
|
||||||
command: 'Doorlock=',
|
command: 'Doorlock=',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
deviceName: 'BL',
|
deviceName: 'BL',
|
||||||
command: 'Blind=',
|
deviceType: 'S',
|
||||||
},
|
|
||||||
{
|
|
||||||
deviceName: 'BL',
|
|
||||||
command: 'Blind=',
|
command: 'Blind=',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
export const getDeviceCommand = (deviceName: string, deviceType: string): string => {
|
||||||
|
const device = dataMapping.find((item) => item.deviceName === deviceName && item.deviceType === deviceType)
|
||||||
|
return device?.command || ''
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { dataMapping } from '~/helpers/utils'
|
import { getDeviceCommand } from '~/helpers/utils'
|
||||||
import { DeviceCommandBody } from '../schema'
|
import { DeviceCommandBody } from '../schema'
|
||||||
import { sendCommandToThirdParty } from './command'
|
import { sendCommandToThirdParty } from './command'
|
||||||
import { alphabetToNumberString } from '~/helpers/alphabet_conversion'
|
import { alphabetToNumberString } from '~/helpers/alphabet_conversion'
|
||||||
@@ -11,8 +11,8 @@ export default abstract class CommandService {
|
|||||||
}> {
|
}> {
|
||||||
const unitNumber = alphabetToNumberString(body.unitNumber)
|
const unitNumber = alphabetToNumberString(body.unitNumber)
|
||||||
const topicData = `${body.merchantName}/${body.floorName}_${unitNumber}-${body.deviceName}-${body.roomName}-${body.deviceType}-${body.commandType}-${body.towerNumber}`
|
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 cmd = getDeviceCommand(body.deviceName, body.deviceType)
|
||||||
const request = await sendCommandToThirdParty(topicData, `${cmd?.command}${body.payload.action}`)
|
const request = await sendCommandToThirdParty(topicData, `${cmd}${body.payload.action}`)
|
||||||
if (request.status !== 200 || request.data.status == 400) {
|
if (request.status !== 200 || request.data.status == 400) {
|
||||||
return {
|
return {
|
||||||
status: 'error' as const,
|
status: 'error' as const,
|
||||||
|
|||||||
Reference in New Issue
Block a user