From 3cd085fb9e6e697fe0cd3b2b621860546ddd7285 Mon Sep 17 00:00:00 2001 From: PandaX <18610165312@163.com> Date: Tue, 17 Oct 2023 16:14:19 +0800 Subject: [PATCH] =?UTF-8?q?[=E4=BC=98=E5=8C=96]=E8=AE=BE=E5=A4=87=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E5=B1=95=E7=A4=BA=E6=97=B6=EF=BC=8C=E5=A6=82=E6=9E=9C?= =?UTF-8?q?bool=EF=BC=8Cenum=E5=B1=95=E7=A4=BA=E8=AE=BE=E7=BD=AE=E7=9A=84?= =?UTF-8?q?=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + apps/device/api/device.go | 15 +++++++++++++++ iothub/hook_message_work/hook_message_work.go | 5 +---- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index a114973..7c275f5 100644 --- a/.gitignore +++ b/.gitignore @@ -8,5 +8,6 @@ # Test binary, built with `go test -c` *.test +/fatal # Output of the go coverage tool, specifically when used with LiteIDE *.out \ No newline at end of file diff --git a/apps/device/api/device.go b/apps/device/api/device.go index 87bc243..800d611 100644 --- a/apps/device/api/device.go +++ b/apps/device/api/device.go @@ -10,11 +10,13 @@ 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" @@ -114,6 +116,19 @@ 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 { diff --git a/iothub/hook_message_work/hook_message_work.go b/iothub/hook_message_work/hook_message_work.go index 65d3162..c0a7666 100644 --- a/iothub/hook_message_work/hook_message_work.go +++ b/iothub/hook_message_work/hook_message_work.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "github.com/PandaXGO/PandaKit/biz" - "log" "pandax/apps/device/entity" "pandax/apps/device/services" ruleEntity "pandax/apps/rule/entity" @@ -83,8 +82,7 @@ func (s *HookService) handleOne(msg *netbase.DeviceEventInfo) { //检测设备影子并修改设备影子状态 if msg.Type == message.ConnectMes { shadow.InitDeviceShadow(msg.DeviceAuth.Name, msg.DeviceAuth.ProductId) - err := shadow.DeviceShadowInstance.SetOnline(msg.DeviceAuth.Name) - log.Println(err) + shadow.DeviceShadowInstance.SetOnline(msg.DeviceAuth.Name) } else { shadow.DeviceShadowInstance.SetOffline(msg.DeviceAuth.Name) } @@ -180,7 +178,6 @@ func SetDeviceShadow(etoken *global_model.DeviceAuth, msgVals map[string]interfa biz.ErrIsNilAppendErr(err, "设置设备影子点失败") } if message.TelemetryMes == msgType { - log.Println(etoken.Name) err := shadow.DeviceShadowInstance.SetDevicePoint(etoken.Name, global.TslTelemetryType, tel.Key, msgVals[tel.Key]) biz.ErrIsNilAppendErr(err, "设置设备影子点失败") }