Need help with state options in binding

Starting point:
I want to add options to my channel based on the presets/favourites, other devices in the network, …

I have found the following thread regarding dynamic state options.
The documentation is bit short but better than nothing :slight_smile:
I also looked at the following bindings : KODI, Squeezebox, onewire, Sonos but I can’t figure what’s going wrong.

I compared the code and added the class and references.
However, now I get the following error in VS Code:
HandlerFactory.java:[43,1679] The @NonNull field stateDescriptionProvider may not have been initialized.

Also I notice that the color scheme is not respected.
Source can be found here
Any advice where to look? I spent already a few hours on testing but each I get stuck at the same point.

Thx

Hi Lennert,

Have a look here - what is missing in your code is explained in the example at the bottom of the section:

Therefore the ThingHandlerFactory has to reference the bundle instance and pass it to the handler.

Do you plan to support multiple languages in your state descriptions? Because you added the i18n code (although I suspect you just copied the code and have no idea why it’s there :wink:)

To add to Christoph comment. You need to add @Reference:

  @Reference
  private yamahamusiccastStateDescriptionProvider stateDescriptionProvider;

Also please respect java naming conventions for class and field names.

Thanks for the pointers already.

I do know what i18n code is for but getting a bit desperate. So this part is there as I saw it in the other bindings and in the documentation.
The @Reference part is in there but still getting the same message.

Regarding the naming conventions: will do in a later stage. Currently looking to get this working.
Perhaps do tabula rasa and start over (once more :unamused:)

To get ride of the null message change the following as the constructor:

private final yamahamusiccastStateDescriptionProvider stateDescriptionProvider;

@Activate
public yamahamusiccastHandlerFactory(@Reference yamahamusiccastStateDescriptionProvider stateDescriptionProvider) {
    this.stateDescriptionProvider = stateDescriptionProvider;
}

You rock! :ok_hand:
Green build after these changes. :checkered_flag:

I could not have found this one by myself. As said, I will work on coding guidelines.
Now try to get the options updated.
Thx again

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.