@@ -342,49 +342,72 @@ func mqttSubscribeDevice() {
342342 ss := strings .Split (topic , "/" )
343343 id := ss [1 ]
344344 dev := devices .Load (id )
345- if dev == nil {
346- return
345+ if dev != nil {
346+ dev .onSyncResponse (resp )
347+ }
348+
349+ if resp .DeviceId != "" && resp .DeviceId != id {
350+ dev = devices .Load (resp .DeviceId )
351+ if dev != nil {
352+ dev .onSyncResponse (resp )
353+ }
347354 }
348- dev .onSyncResponse (resp )
349355 })
350356
351357 mqtt .SubscribeStruct [ReadResponse ]("device/+/read/response" , func (topic string , resp * ReadResponse ) {
352358 ss := strings .Split (topic , "/" )
353359 id := ss [1 ]
354360 dev := devices .Load (id )
355- if dev == nil {
356- return
361+ if dev != nil {
362+ dev .onReadResponse (resp )
363+ }
364+
365+ if resp .DeviceId != "" && resp .DeviceId != id {
366+ dev = devices .Load (resp .DeviceId )
367+ if dev != nil {
368+ dev .onReadResponse (resp )
369+ }
357370 }
358- dev .onReadResponse (resp )
359371 })
360372
361373 mqtt .SubscribeStruct [WriteResponse ]("device/+/write/response" , func (topic string , resp * WriteResponse ) {
362374 ss := strings .Split (topic , "/" )
363375 id := ss [1 ]
364376 dev := devices .Load (id )
365- if dev == nil {
366- return
377+ if dev != nil {
378+ dev .onWriteResponse (resp )
379+ }
380+
381+ if resp .DeviceId != "" && resp .DeviceId != id {
382+ dev = devices .Load (resp .DeviceId )
383+ if dev != nil {
384+ dev .onWriteResponse (resp )
385+ }
367386 }
368- dev .onWriteResponse (resp )
369387 })
370388
371389 mqtt .SubscribeStruct [ActionResponse ]("device/+/action/response" , func (topic string , resp * ActionResponse ) {
372390 ss := strings .Split (topic , "/" )
373391 id := ss [1 ]
374392 dev := devices .Load (id )
375- if dev == nil {
376- return
393+ if dev != nil {
394+ dev .onActionResponse (resp )
395+ }
396+
397+ if resp .DeviceId != "" && resp .DeviceId != id {
398+ dev = devices .Load (resp .DeviceId )
399+ if dev != nil {
400+ dev .onActionResponse (resp )
401+ }
377402 }
378- dev .onActionResponse (resp )
379403 })
380404
381405 mqtt .SubscribeStruct [SettingResponse ]("device/+/setting/response" , func (topic string , resp * SettingResponse ) {
382406 ss := strings .Split (topic , "/" )
383407 id := ss [1 ]
384408 dev := devices .Load (id )
385- if dev = = nil {
386- return
409+ if dev ! = nil {
410+ dev . onSettingResponse ( resp )
387411 }
388- dev .onSettingResponse (resp )
389412 })
390413}
0 commit comments