You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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.
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 newCapability
.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 thecontroller
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.The text was updated successfully, but these errors were encountered: