Skip to content

Implement interface and struct tags for structural information. #3

@pwood

Description

@pwood

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.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions