Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement interface and struct tags for structural information. #3

Open
pwood opened this issue Sep 28, 2022 · 1 comment
Open

Implement interface and struct tags for structural information. #3

pwood opened this issue Sep 28, 2022 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@pwood
Copy link
Member

pwood commented Sep 28, 2022

The vast majority of da's output a status response of some kind, this can be simplistic from a "On/Off" or more complicated for "Power Supply".

At the moment any consumer (shimmeringbee/controller especially) has to have code to convert these structures into JSON, infact there is an developer overhead with added any new Capability.

However, for forethought (or dumb luck), all capabilities that have data to return do so via a function that looks a bit like:

func Status(context.Context, da.Device) interface{} (though not actually an interface{})

Using struct tags and reflection it would be possible to instruct consumers (such as shimmeringbee/controller) on how to display these structures.

While we absolutely could use json tags, JSON may not be our only output format - further the MQTT and Websocket outputs of the controller have the ability to output specific messages for individual field or smallest grouping of fields. A specific struct tag could permit us to calculate where these lines are.

With a little more thinking on the function prototype, or figuring out how to invoke Status generically on all capabilities it may be possible to remove large amounts of the controller code and reduce developer overhead adding new capabilities.

@pwood pwood added the enhancement New feature or request label Sep 28, 2022
@pwood pwood self-assigned this Sep 28, 2022
@pwood
Copy link
Member Author

pwood commented Sep 28, 2022

The existing Status function with its capability specific return type is great for small scale, however it should be possible to generify.

The typing information IS helpful for developing directly against a da, but not that useful when used more generically. I don't think there are any other users of da or zda to be honest, so we could breaking change (major version bump), or add another function to every da that returns interface{}.

Unless there's something we can do with generics? Will have to read up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant