diff --git a/knx/dpt/types.go b/knx/dpt/types.go index 04de8c3..82e9ca0 100644 --- a/knx/dpt/types.go +++ b/knx/dpt/types.go @@ -3,6 +3,8 @@ package dpt +import "fmt" + // A DatapointValue is a value of a datapoint. type DatapointValue interface { // Pack the datapoint to a byte array. @@ -17,3 +19,9 @@ type DatapointMeta interface { // Unit returns the unit of this datapoint type or empty string if it doesn't have a unit. Unit() string } + +type Datapoint interface { + DatapointValue + DatapointMeta + fmt.Stringer +} diff --git a/knx/dpt/types_registry.go b/knx/dpt/types_registry.go index ac91880..3f266a9 100644 --- a/knx/dpt/types_registry.go +++ b/knx/dpt/types_registry.go @@ -9,7 +9,7 @@ import ( ) var ( - types = [...]DatapointValue{ + types = [...]Datapoint{ // 1.xxx new(DPT_1001), new(DPT_1002), @@ -248,14 +248,14 @@ func ListSupportedTypes() []string { } // Produce creates a new instance of the given datapoint-type name e.g. "1.001". -func Produce(name string) (d DatapointValue, ok bool) { +func Produce(name string) (d Datapoint, ok bool) { // Setup the registry setup() // Lookup the given type and create a new instance of that type x, ok := registry[name] if ok { - d = reflect.New(x).Interface().(DatapointValue) + d = reflect.New(x).Interface().(Datapoint) } return d, ok }