local level = ReqBody.level
local device_id = not ReqBody.id and 0xff or ReqBody.id
local fan_t, pump_t = {}, {}
local PumpSupported = false
if type(ProcessingFlow[4].Destination.CtrlMode) == 'string' then
PumpSupported = true
pump_t.max_id = #ProcessingFlow[2].Destination.PumpList
pump_t.min_level = ProcessingFlow[4].Destination.LevelPercentRange[1]
pump_t.max_level = ProcessingFlow[4].Destination.LevelPercentRange[2]
pump_t.ctrl_mode = ProcessingFlow[4].Destination.CtrlMode
pump_t.timeout = ProcessingFlow[4].Destination.TimeOut
end
fan_t.max_id = #ProcessingFlow[1].Destination.FanList
fan_t.min_level = ProcessingFlow[3].Destination.LevelPercentRange[1]
fan_t.max_level = ProcessingFlow[3].Destination.LevelPercentRange[2]
fan_t.ctrl_mode = ProcessingFlow[3].Destination.CtrlMode
fan_t.timeout = ProcessingFlow[3].Destination.TimeOut
if ReqBody.devicetype == 'pump' then
if not PumpSupported then
return { 'PumpNotSupported', PumpSupported, fan_t, pump_t }
end
end
if not ReqBody.devicetype or not ReqBody.level then
return { 'RequiredPropertyNotInput', PumpSupported, fan_t, pump_t }
end
if ReqBody.devicetype ~= 'fan' and ReqBody.devicetype ~= 'pump' then
return { 'RequiredPropertyNotInput', PumpSupported, fan_t, pump_t }
end
local function check_id_and_level(id, device_level, device_t)
if device_t.ctrl_mode == 'Auto' then
return 'CtrlModeIsAuto'
end
if id ~= 0xff and (id < 1 or id > device_t.max_id) then
return 'IdOutOfRange'
end
if device_level < device_t.min_level or device_level > device_t.max_level then
return 'LevelOutOfRange'
end
return true
end
local rsp = {}
if ReqBody.devicetype == 'fan' then
rsp[1] = check_id_and_level(device_id, level, fan_t)
if rsp[1] == true then
rsp[2] = device_id
rsp[3] = level
rsp[4] = fan_t.timeout
return rsp
end
rsp[2] = PumpSupported
rsp[3] = fan_t
rsp[4] = pump_t
rsp[5] = fan_t.timeout
end
if ReqBody.devicetype == 'pump' then
rsp[1] = check_id_and_level(device_id, level, pump_t)
if rsp[1] == true then
rsp[2] = device_id
rsp[3] = level
rsp[4] = pump_t.timeout
return rsp
end
rsp[2] = PumpSupported
rsp[3] = fan_t
rsp[4] = pump_t
rsp[5] = pump_t.timeout
end
return rsp