mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 02:48:34 +08:00
[优化]设备状态展示时,如果bool,enum展示设置的值
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -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
|
||||
@@ -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 {
|
||||
|
||||
@@ -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, "设置设备影子点失败")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user