-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[mqtt] Simplify homeassistant thing types, and use AbstractStorageBasedTypeProvider #16600
[mqtt] Simplify homeassistant thing types, and use AbstractStorageBasedTypeProvider #16600
Conversation
...ing.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/MqttChannelTypeProvider.java
Outdated
Show resolved
Hide resolved
...ing.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/MqttChannelTypeProvider.java
Outdated
Show resolved
Hide resolved
...ing.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/MqttChannelTypeProvider.java
Outdated
Show resolved
Hide resolved
...ing.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/MqttChannelTypeProvider.java
Outdated
Show resolved
Hide resolved
...c/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/AbstractComponent.java
Outdated
Show resolved
Hide resolved
....binding.mqtt.homie/src/main/java/org/openhab/binding/mqtt/homie/internal/homie300/Node.java
Outdated
Show resolved
Hide resolved
...c/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/AbstractComponent.java
Outdated
Show resolved
Hide resolved
...c/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/AbstractComponent.java
Show resolved
Hide resolved
...c/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/AbstractComponent.java
Outdated
Show resolved
Hide resolved
...c/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/AbstractComponent.java
Outdated
Show resolved
Hide resolved
@ccutrer : did you notice the build failed ? |
I did. And I've gotten to the point that I can reproduce the failures locally, but have not yet had time to troubleshoot them (or address @antroids comments). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've addressed (most) the review comments, but not looked at itests. The suggested changes have also caused (non-test) test failures - I think related to some of the foreach changes, possibly due to needing to mock different methods. I don't have time today to look into any of that, but will when I can
...c/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/AbstractComponent.java
Show resolved
Hide resolved
...c/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/AbstractComponent.java
Outdated
Show resolved
Hide resolved
...c/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/AbstractComponent.java
Outdated
Show resolved
Hide resolved
While I do have an outstanding question (about preferred amount of backwards compatibility), the ball is in my court to fix unit tests after recent changes to address review comments. Unfortunately I don't know when I'll have time to dig in to this PR. Life has been excessively busy lately, leaving little time for hobbies. |
This pull request has been mentioned on openHAB Community. There might be relevant details there: |
Instead, use state descriptions for the varying parts, which means that there is not an explosion of channel types for every single Home Assistant channel, which can cause performance issues if you have a lot of devices/channels Signed-off-by: Cody Cutrer <cody@cutrer.us>
This has two important impacts, and one not-as-important-but-still- beneficial impact: * ThingTypes are not created for Things that are never actually created, but only discovered, reducing bloat. * Avoids warnings about things types not being in the registry * Thing IDs end up like mqtt:homeassistant:broker:mydevice instead of mqtt:homeassistant_mydevice:broker:mydevice Note that already-created things will maintain their original ID, and it's only new things created from auto-discovery that will have the new, shorter thing IDs. Signed-off-by: Cody Cutrer <cody@cutrer.us>
This is triggered by a property only set by discovery, so will only apply to newly created things. Channel groups are now named after simply the component type and object_id, if possible, and without additional encoding, instead off encoding the unique_id. Most devices will encode the component type and device identifiers into the unique_id, and of arbitrary format, so it is far more complicated than necessary, when a channel group is already only within the scope of the thing/device. Many component types that can only ever have one channel (button, switch, sensor, select, scene, etc.) will not be in a channel group anymore. In this case their channel id is what their group id would have been, without the repetitiveness of "sensor_<unique_id>#sensor". Signed-off-by: Cody Cutrer <cody@cutrer.us>
Includes both homie and homeassistant dynamic things. It also fixes all ordering issues in both bindings in order to be consistent in how types are persisted: * For Homie, Nodes (channel groups) and Properties (channels) are ordered in the way they are defined in $nodes and $properties * For Home Assistant, Components are ordered by label. This includes both single channel components that are not in a channel group, as well as channel groups. We also ensure that on the Thing itself non-grouped channels consistently sort before grouped channels. Signed-off-by: Cody Cutrer <cody@cutrer.us>
Signed-off-by: Cody Cutrer <cody@cutrer.us>
Signed-off-by: Cody Cutrer <cody@cutrer.us>
Signed-off-by: Cody Cutrer <cody@cutrer.us>
the ternary accidentally got swapped Signed-off-by: Cody Cutrer <cody@cutrer.us>
b54d5da
to
c835743
Compare
Signed-off-by: Cody Cutrer <cody@cutrer.us>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I rebased to get changes from main, and tests should pass now. 🤞 this is ready to go.
...c/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/AbstractComponent.java
Show resolved
Hide resolved
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/problem-adding-a-switch-to-a-dimmer/155304/19 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
- The binding documentation could use some examples or maybe file based configuration. Not sure if that makes sense, but this PR might be a good moment to update/extend the documentation.
- Please create a notice about the semi-non-breaking change in the https://github.com/openhab/openhab-distro/pulls
- Do you want to create a PR with removing the obsolete parts and have that as a draft waiting for the next stable or how do you want to make sure a follow up is taking place?
I'll wait for @antroids to confirm all his comments are addressed.
Indeed, it's quite light on examples. But I'm suspicious that file-based configuration does not work for Home Assistant at all. And I'm also aware of other issues surrounding discovery that I want to fix. I plan on investigating all that - and updating the docs as I confirm things work - after this PR is submitted. This PR is already large and complex enough, most anything else I do will conflict with it. It's also difficult to test because it relies on changes across both mqtt.generic and mqtt.homeassistant, so I can't just update a single bundle - you have to update them all, and then restart openHAB.
I've got it ready at ccutrer@dfe751a. Once this PR merges, I'll rebase it, then open a draft PR against this repo. |
ping @antroids |
Signed-off-by: Cody Cutrer <cody@cutrer.us> Co-Authored-By: Anton Kharuzhy <publicantroids@gmail.com>
.../java/org/openhab/binding/mqtt/homeassistant/internal/handler/HomeAssistantThingHandler.java
Outdated
Show resolved
Hide resolved
...ssistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/ComponentChannel.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Cody Cutrer <cody@cutrer.us>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Let's get rid of this PR 😁
I actually still use file-based configuration, but IMO it's just a feature for backward compatibility.
…edTypeProvider (openhab#16600) * [mqtt.homeassistant] don't dynamically generate channel types Signed-off-by: Cody Cutrer <cody@cutrer.us>
…edTypeProvider (openhab#16600) * [mqtt.homeassistant] don't dynamically generate channel types Signed-off-by: Cody Cutrer <cody@cutrer.us> Signed-off-by: Patrik Gfeller <patrik.gfeller@proton.me>
…edTypeProvider (openhab#16600) * [mqtt.homeassistant] don't dynamically generate channel types Signed-off-by: Cody Cutrer <cody@cutrer.us>
…edTypeProvider (openhab#16600) * [mqtt.homeassistant] don't dynamically generate channel types Signed-off-by: Cody Cutrer <cody@cutrer.us>
This is a rather large PR, but is built of a few commits with essentially two distinct goals. I have not tested them individually, and there are lots of interactions between the two goals, which is why I did not disentangle them.
This first goal is to simplify and optimize thing and channel types for mqtt.homeassistant. This fixes #14295. This in itself has two user visible changes:
mqtt:homeassistant
in its ID. In practice, newly discovered things will get UIDs such asmqtt:homeassistant:mosquitto:awair-element-63611
instead ofmqtt:homeassistant_awair_2Delement_2D63611:mosquitto:awair_2Delement_2D63611
(unnecessary escaping has also been removed). Existing things will not change their UID. I'm not sure if this is considered a breaking change, since existing things will not change at all. But if you were to delete the thing, and re-add it from discovery, it would end up with a different ID. This new behavior matches how mqtt.homie works.For this change, I did a bit of hoop-jumping to pass a property through from auto-discovery, so that existing things will not have their channels change, only newly discovered and created things will use this new channel type. Again, I'm not sure if this counts as a breaking change. If it does, I'm possibly inclined to not use this hinky property, and simply apply the new channel IDs to all things. An example change is from
mqtt:homeassistant_zigbee2mqtt_5F0x8cf681fffe32e58e:mosquitto:zigbee2mqtt_5F0x8cf681fffe32e58e:0x8cf681fffe32e58e_5Fbattery_5Fzigbee2mqtt#sensor
tomqtt:homeassistant:mosquitto:zigbee2mqtt_5F0x8cf681fffe32e58e:sensor_battery
The second goal is relatively simple - use AbstractStorageBasedTypeProvider. Because the thing and channel group types are dynamic, they don't exist in the binding's XML. But since openHAB 4.0, if a thing type isn't available at startup, it will leave the thing in an unknown state for two minutes before it initializes it. By using AbstractStorageBasedTypeProvider, the dynamic types will be persisted to JSON storage, and thus available immediately at startup, avoiding the two minute delay. This fixes #15577