Skip to content

Commit

Permalink
fix: add bool,enum type
Browse files Browse the repository at this point in the history
  • Loading branch information
imneov committed Feb 14, 2023
1 parent ee2a8bd commit fd69716
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/runtime/entity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestNewEntity(t *testing.T) {
t.Log(string(en.Raw()))
}

func TestEntity_Handle(t *testing.T) {
func TestEntity_HandleScheme(t *testing.T) {
en, err := NewEntity("en-123", []byte(`{"properties": {"temp": 20}}`))
assert.Nil(t, err)

Expand Down
16 changes: 16 additions & 0 deletions pkg/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,22 @@ func adjustDeviceTSData(bytes []byte, entity Entity) (dataAdjust []byte) {
dt.Value = val
tsDeviceAdjustData[k] = dt
}
case "bool":
dt := &tsData{TS: deviceTime}
str := data.Get(k).String()
val, err := strconv.ParseBool(str)
if err == nil {
dt.Value = val
tsDeviceAdjustData[k] = dt
}
case "enum":
dt := &tsData{TS: deviceTime}
str := data.Get(k).To(tdtl.Number).String()
val, err := strconv.ParseInt(str, 10, 32)
if err == nil {
dt.Value = val
tsDeviceAdjustData[k] = dt
}
default:
log.Warn("adjustTSData skip transform", logf.Any("scheme.telemetry.define.field", typ))
dt := &tsData{TS: deviceTime}
Expand Down
97 changes: 97 additions & 0 deletions pkg/runtime/runtime_2_test.go

Large diffs are not rendered by default.

0 comments on commit fd69716

Please sign in to comment.