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

[miio] dynamically generate channelTypes #9158

Merged
merged 7 commits into from
Dec 4, 2020

Conversation

marcelrv
Copy link
Contributor

@marcelrv marcelrv commented Nov 28, 2020

  • Simplify the json database creation for new models and less chance for errors
  • Drive statedescription from Json
  • drive options from Json
    Related to [miio] Binding enhancements #7276

@marcelrv marcelrv requested a review from cpmeister November 28, 2020 13:18
@marcelrv marcelrv added the enhancement An enhancement or new feature for an existing add-on label Nov 28, 2020
@marcelrv marcelrv mentioned this pull request Nov 28, 2020
26 tasks
@marcelrv
Copy link
Contributor Author

jenkins build error unrelated to this PR

Simplify the json database creation for new models and less chance for
errors
Related to openhab#7276

Signed-off-by: Marcel Verpaalen <[email protected]>
Signed-off-by: Marcel Verpaalen <[email protected]>
@marcelrv marcelrv force-pushed the miio-ChannelProvider branch from 864ddd4 to c801f69 Compare November 29, 2020 18:34
Co-authored-by: Connor Petty <[email protected]>
Signed-off-by: Marcel Verpaalen <[email protected]>
@marcelrv
Copy link
Contributor Author

marcelrv commented Dec 2, 2020

Thanks for the improvements suggested in the feedback. Implemented.
Note: Jenkins build error unrelated to this PR

Signed-off-by: Marcel Verpaalen <[email protected]>
@marcelrv marcelrv added rebuild Triggers Jenkins PR build and removed rebuild Triggers Jenkins PR build labels Dec 3, 2020
return null;
}

public void addChannelType(MiIoBasicChannel miChannel, String model) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed in my own bindings that my channels would not show up in the UI if the channel types weren't available in the ChannelTypeProvider before the thing handler was started. Is there something special about your setup here or did you find some kind of workaround to prevent that issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not experienced that. I'll do some specific testing on that.
It very well can be the case, but as the basicHandler changes the type from generic to basic after it did the identification it would have satisfied that requirement. But... I would need to check the code if it still does that when the type has already changed, I guess than indeed it may be an issue.
I wonder how other bindings are doing this, as in many cases the channel definition is based on something that is loaded of the device.
How did you solve it?

Copy link
Contributor

@cpmeister cpmeister Dec 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up encoding all of the relevant channel information into the channel type name itself. And then reconstructed the channel type by decoding the information in the name on demand. Wish I didn't have to do that and that there was some way around it so that's why I was asking if you are experiencing the same issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange. I don't see the behavior. If I change the model info on an existing thing, the new channels appear in the mainUI almost instant. No reloading of the page (I go from the code page to the channel page and the new channels are there)
No specific actions I take to handle the reloading the handler.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well if it works for you then that is good enough to me. I'll sort out my own setup some other time.

Copy link

@fastlorenzo fastlorenzo Feb 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cpmeister could you point out the code you've used so we can have a look (cc @markus7017)
We're having the same issue with a binding where the channels show up in the console but not in the UI on OH3, and it appears to be related to channel ChannelType. All works well in OH2.5
Thx!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned before, I had to implement the ChannelTypeProvider such that the ChannelType information could be derived from the ChannelTypeUID without having a handler inject ChannelType definitions into the provider ahead of time.

https://github.com/openhab/openhab-addons/blob/main/bundles/org.openhab.binding.bluetooth.generic/src/main/java/org/openhab/binding/bluetooth/generic/internal/CharacteristicChannelTypeProvider.java

@fastlorenzo What binding are you having trouble with?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick reply!

I ended up fixing it by checking in the ChannelTypeRegistry if the ChannelType exists before dynamically creating the channels.

This is the Carnet binding (interface with Audi/VW API), so all channels are taken from the car info, and are different even with the same car model (depending on options for example)

https://github.com/markus7017/openhab-addons/pull/14/files

@cpmeister cpmeister merged commit 2597ff2 into openhab:main Dec 4, 2020
@cpmeister cpmeister added this to the 3.0.0.M5 milestone Dec 4, 2020
@marcelrv marcelrv deleted the miio-ChannelProvider branch December 14, 2020 08:58
boehan pushed a commit to boehan/openhab-addons that referenced this pull request Apr 12, 2021
* [miio] dynamically generate channelTypes

Simplify the json database creation for new models and less chance for
errors
Related to openhab#7276

Signed-off-by: Marcel Verpaalen <[email protected]>
Co-authored-by: Connor Petty <[email protected]>
marcfischerboschio pushed a commit to bosch-io/openhab-addons that referenced this pull request May 5, 2022
* [miio] dynamically generate channelTypes

Simplify the json database creation for new models and less chance for
errors
Related to openhab#7276

Signed-off-by: Marcel Verpaalen <[email protected]>
Co-authored-by: Connor Petty <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature for an existing add-on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants