package rpc import ( "encoding/json" "time" "src.dualinventive.com/go/dinet/ditime" ) // ResultValueItem represents a single DI-Net RPC message result item type ResultValueItem struct { UID uint16 `json:"uid" msgpack:"uid"` // UID represents the sensor,notify Unique ID Time ditime.Time `json:"time" msgpack:"time"` // Time stamp of value Value interface{} `json:"value" msgpack:"value"` // Value Values *ResultValuesItem `json:"values" msgpack:"values"` // Values } // ResultValuesItem represents multiple samples with a interval type ResultValuesItem struct { Interval time.Duration `json:"interval" msgpack:"interval"` Samples []float64 `json:"samples" msgpack:"samples"` } // UnmarshalJSON unmarshals a byte slice to a ResultValueItem func (rvi *ResultValueItem) UnmarshalJSON(b []byte) error { type alias ResultValueItem r := &alias{} r.Value = &json.RawMessage{} if err := json.Unmarshal(b, r); err != nil { return err } *rvi = ResultValueItem(*r) return nil } // GetValue unmarshals the value property into the provided argument func (rvi *ResultValueItem) GetValue(v interface{}) error { if rm, ok := rvi.Value.(*json.RawMessage); ok { return json.Unmarshal(*rm, v) } return ErrMsgNoData } // ResultInfoItem represents a single DI-Net RPC message info item type ResultInfoItem struct { UID uint16 `json:"uid" msgpack:"uid"` // UID represents the sensor,notify Unique ID Label string `json:"label" msgpack:"label"` // Label is the human-readable label Type string `json:"type" msgpack:"type"` // Type is the type of this item Enum map[string]int `json:"enum,omitempty" msgpack:"enum,omitempty"` // Enumeration when type is "enum" } // ResultConfigValueItem represents a single DI-Net RPC config message result item type ResultConfigValueItem struct { UID uint16 `json:"uid" msgpack:"uid"` // UID represents the config Unique ID Value interface{} `json:"value" msgpack:"value"` // Value } // ResultConfigInfoItem represents a single DI-Net RPC config message info item type ResultConfigInfoItem struct { UID uint16 `json:"uid" msgpack:"uid"` // UID represents the sensor,notify Unique ID Label string `json:"label" msgpack:"label"` // Label is the human-readable label Type string `json:"type" msgpack:"type"` // Type is the type of this item Default interface{} `json:"default" msgpack:"default"` // Default is the default value of this // configuration and is set after a config:reset }