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

Fix thing reloading from things file #3526

Merged
merged 3 commits into from
Apr 15, 2023
Merged

Conversation

J-N-K
Copy link
Member

@J-N-K J-N-K commented Apr 6, 2023

Fixes #3527

It was found that things from textual configuration are not properly updated if changes are only made in configuration or label of a channel. The reason is that for assuming equality only uid and accepted item-type of the channel were checked. This is obviously wrong and also confusing because for the thing itself configuration and other fields are also compared.

Another bug in the GenericThingProvider: The things are cached in the provider to determine changes. However, this list was never updated, resulting in changes back to the first version (v1 -> v2 -> v1) not resulting in an update notification, because the new thing and the cached thing are equal.

It was found that things from textual configuration are not properly updated if changes are only made in configuration or label of a channel. The reason is that for equality only uid and accepted item-type where checked.

Signed-off-by: Jan N. Klug <github@klug.nrw>
@J-N-K J-N-K added the bug An unexpected problem or unintended behavior of the Core label Apr 6, 2023
@J-N-K J-N-K marked this pull request as ready for review April 6, 2023 10:01
@J-N-K J-N-K requested a review from a team as a code owner April 6, 2023 10:01
@florian-h05
Copy link
Contributor

I‘ve tested this, and it is very weird: sometimes when you change channels, the thing is updated, but sometimes the thing is not updated.

@J-N-K
Copy link
Member Author

J-N-K commented Apr 6, 2023

If you enable debug logging for org.openhab.core.model.thing, do you see this message in both cases?

logger.debug("Updating thing '{}' from model '{}'.", newThing.UID, modelName);

@florian-h05
Copy link
Contributor

No, Updating thing 'knx:device:bridge:Kueche_Glastaster' from model 'knx.things'. is only logged when it works.

Read things from model 'knx.things' is always logged.

@J-N-K
Copy link
Member Author

J-N-K commented Apr 6, 2023

Ok, so for some reason the code still thinks they are equals even if they are not. Do you have something that always or at least mostly fails (i.e. editing the label fails, editing the configuration works)? Can you share the .things code?

@florian-h05
Copy link
Contributor

florian-h05 commented Apr 6, 2023

It seems like it mostly happens when:

  1. openHAB starts with a given .things file
  2. I change anything of the channel (in this case label) -> Thing updated
  3. I change the channel label back -> Thing not updated

Here the relavent part of my *.things file (I have removed the Things I don't modify):

Bridge knx:ip:bridge [  
    type="ROUTER", 
    ipAddress="", // in TUNNEL Mode: 192.168.180.5
    portNumber=3671, // for TUNNEL mode
    localIp="192.168.180.4",
    readingPause=50, 
    responseTimeout=10, 
    readRetriesLimit=4, 
    autoReconnectPeriod=30,
    localSourceAddr="0.0.0",
    useNAT=false
] {

    Thing device Kueche_Glastaster "Küche Glastaster" @ "Küche" [
        address="1.1.24",
        fetch=true,
        pingInterval=300,
        readInterval=0
    ] {
        Type number             : Temperatur                 "Temperatur"              [ ga="9.001:3/3/130" ]
        Type switch             : Verstaerker_Radio          "Verstärker Radio"        [ ga="2/3/150" ]
        Type switch-control     : Verstaerker_Radio_Status   "Verstärker Radio Status" [ ga="1.011:2/3/151"]
        Type switch             : Verstaerker_BT             "Verstärker BT"           [ ga="2/3/155" ]
        Type switch-control     : Verstaerker_BT_Status      "Verstärker BT Status"    [ ga="1.011:2/3/156" ]
        
    }
    
}

@J-N-K
Copy link
Member Author

J-N-K commented Apr 6, 2023

I think I found it. However, I'm not 100% if my fix is correct, it's in the XTend code and that is always a mystery for me. Currently testing if it works for me.

Signed-off-by: Jan N. Klug <github@klug.nrw>
@J-N-K J-N-K changed the title Fix thing comparison in ThingHelper Fix thing reloading from things file Apr 6, 2023
@J-N-K
Copy link
Member Author

J-N-K commented Apr 6, 2023

Please check this version, it also contains an updated org.openhab.core.model.thing bundle.

@J-N-K J-N-K added rebuild Triggers the Jenkins PR build and removed rebuild Triggers the Jenkins PR build labels Apr 6, 2023
Copy link
Contributor

@florian-h05 florian-h05 left a comment

Choose a reason for hiding this comment

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

Works fine, thanks for the fix!

@jlaur
Copy link
Contributor

jlaur commented Apr 7, 2023

Another bug in the GenericThingProvider: The things are cached in the provider to determine changes. However, this list was never updated, resulting in changes back to the first version (v1 -> v2 -> v1) not resulting in an update notification, because the new thing and the cached thing are equal.

Great finding, thanks for this fix. This is something that has annoyed me for a long time, but never took the time to reproduce or investigate this further. I just had this feeling that it did not work correctly, as it usually happened for me during tests where I was changing configuration back and forth.

Signed-off-by: Jan N. Klug <github@klug.nrw>
Copy link
Member

@wborn wborn left a comment

Choose a reason for hiding this comment

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

LGTM! 👍

@wborn wborn merged commit 016828c into openhab:main Apr 15, 2023
@wborn wborn added this to the 4.0 milestone Apr 15, 2023
@J-N-K J-N-K deleted the bug-thingcompare branch April 15, 2023 07:18
@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/text-configuration-loading-after-change/146244/5

@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/come-back-and-learn-how-to-use-file-based-configuration/147067/15

splatch pushed a commit to ConnectorIO/copybara-hab-core that referenced this pull request Jul 12, 2023
It was found that things from textual configuration are not properly updated if changes are only made in configuration or label of a channel. The reason is that for equality only uid and accepted item-type where checked.

Signed-off-by: Jan N. Klug <github@klug.nrw>
GitOrigin-RevId: 016828c
@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/oh3-model-and-things-go-offline-after-a-while-when-i-configure-the-system/147785/12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of the Core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Things from textual configuration are not properly reloaded
5 participants