vapourismo / knx-go

KNX clients and protocol implementation in Go
MIT License
91 stars 59 forks source link

Add Datapoint interface #73

Closed annismckenzie closed 11 months ago

annismckenzie commented 11 months ago

First off, thank you for the hard work you put into this library – it works very very well in my KNX-HomeKit bridge project (releasing as open source as well soon).

In that project I needed a way to create and store concrete values of datapoint types. The problem is that Produce only returns a DatapointValue so type assertions are necessary when trying to use Unit() (part of the DatapointMeta interface) or String() (from fmt.Stringer).

Would you consider this change of adding a combined interface and returning that from Produce()?

type Datapoint interface {
    DatapointValue
    DatapointMeta
    fmt.Stringer
}

This change does not require any other changes besides the 3 I made in the type registry and the test suite is still green without any changes.

Thank you for considering it – in case you do accept the change I'd update the commit message description to explain the reasoning before the merge.

vapourismo commented 11 months ago

Seems straightforward to me. I left two minor comments, apart from that I'd be happy to merge it.

annismckenzie commented 11 months ago

I made the changes you suggested and split the change up into 2 commits. Take another look?