mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 02:48:34 +08:00
[优化]使用tsl设置默认值设置设备影子
This commit is contained in:
@@ -10,13 +10,11 @@ import (
|
||||
"github.com/PandaXGO/PandaKit/biz"
|
||||
"github.com/PandaXGO/PandaKit/model"
|
||||
"github.com/PandaXGO/PandaKit/restfulx"
|
||||
"pandax/apps/device/tsl"
|
||||
"pandax/apps/device/util"
|
||||
"pandax/pkg/cache"
|
||||
"pandax/pkg/global"
|
||||
"pandax/pkg/global_model"
|
||||
"pandax/pkg/shadow"
|
||||
"pandax/pkg/tool"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -116,19 +114,6 @@ func (p *DeviceApi) GetDeviceStatus(rc *restfulx.ReqCtx) {
|
||||
if v, ok := rs[tel.Key]; ok {
|
||||
sdv.Value = v.Value
|
||||
sdv.Time = v.UpdatedAt
|
||||
// 如果
|
||||
if classify == global.TslTelemetryType && (tel.Type == "bool" || tel.Type == "enum") {
|
||||
var boolDefine tsl.ValueType
|
||||
err := tool.MapToStruct(tel.Define, &boolDefine)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
boolDefine.Type = tel.Type
|
||||
value := boolDefine.ConvertValue(v.Value)
|
||||
if val, ok := value.(string); ok && val != "" {
|
||||
sdv.Value = val
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if classify == global.TslAttributesType {
|
||||
if value, ok := tel.Define["default_value"]; ok {
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/PandaXGO/PandaKit/biz"
|
||||
"pandax/apps/device/entity"
|
||||
"pandax/apps/device/services"
|
||||
"pandax/apps/device/tsl"
|
||||
ruleEntity "pandax/apps/rule/entity"
|
||||
ruleService "pandax/apps/rule/services"
|
||||
"pandax/iothub/netbase"
|
||||
@@ -178,7 +179,20 @@ func SetDeviceShadow(etoken *global_model.DeviceAuth, msgVals map[string]interfa
|
||||
biz.ErrIsNilAppendErr(err, "设置设备影子点失败")
|
||||
}
|
||||
if message.TelemetryMes == msgType {
|
||||
err := shadow.DeviceShadowInstance.SetDevicePoint(etoken.Name, global.TslTelemetryType, tel.Key, msgVals[tel.Key])
|
||||
var value interface{}
|
||||
// tsl转化
|
||||
var tslValue tsl.ValueType
|
||||
err := tool.MapToStruct(tel.Define, &tslValue)
|
||||
if err != nil {
|
||||
value = msgVals[tel.Key]
|
||||
} else {
|
||||
tslValue.Type = tel.Type
|
||||
value = tslValue.ConvertValue(msgVals[tel.Key])
|
||||
if value == nil {
|
||||
value = msgVals[tel.Key]
|
||||
}
|
||||
}
|
||||
err = shadow.DeviceShadowInstance.SetDevicePoint(etoken.Name, global.TslTelemetryType, tel.Key, value)
|
||||
biz.ErrIsNilAppendErr(err, "设置设备影子点失败")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user