Skip to content

Commit

Permalink
schema: add throttle field parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
dcentelles committed Mar 3, 2023
1 parent 6d7dda3 commit a2cd0c9
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ type StateField struct {
DefaultValue interface{}
Type StateFieldType
LossyDebouncing time.Duration
LossyThrottle time.Duration
}

func (e *StateField) MarshalJSON() (res []byte, err error) {
Expand All @@ -333,6 +334,7 @@ func (e *StateField) ToMsi() (msiData map[string]interface{}, err error) {
rawMap := map[string]interface{}{}
rawMap["name"] = e.Name
rawMap["lossyDebouncingMs"] = e.LossyDebouncing.Milliseconds()
rawMap["lossyThrottleMs"] = e.LossyThrottle.Milliseconds()
var fieldTypeStr string
switch e.Type {
case T_INT:
Expand Down Expand Up @@ -369,6 +371,13 @@ func (e *StateField) FromMsi(rawField map[string]interface{}) (err error) {
lossyDebouncingMs = 0
}
e.LossyDebouncing = time.Millisecond * time.Duration(lossyDebouncingMs)

var lossyThrottleMs uint
if lossyThrottleMs, err = ei.N(rawField).M("lossyThrottleMs").Uint(); err != nil {
lossyThrottleMs = 0
}
e.LossyThrottle = time.Millisecond * time.Duration(lossyThrottleMs)

e.Size = ei.N(rawField).M("size").IntZ()
e.DefaultValue = ei.N(rawField).M("defaultValue").RawZ()
switch {
Expand Down

0 comments on commit a2cd0c9

Please sign in to comment.