StateChangedListener Weird Behavoir

Tags: #<Tag:0x00007f616f7b19c0>

I am writing my first binding and have a working data polling cycle, except for the initial state update does not show on the UI. I used the DenonMarantzBinding as a guide for how to peice together a working prototype and believe the problem stems from the fact that it processes updates via the stateChangedListener rather than updating the state directly. Whenever one of the values changes from what it was when the program was loaded it will correctly display that value. My issue is just with the first state creation cycle and need a little help figuring out how to handle the situation.

GitHub Repo Link

I do not get your problem. If no state update is received how should the binding now what value it should set? Once a value is received, your channel is updated, right?

I think its some type of race condition where the UI isn’t ready for the first update. I have log entries in where the first state update is received, but doesn’t make it to the UI. I based my State getters and setters based on the method used in the DenonMarantz binding, so it doesn’t notify the handler unless the state actually changed. That means if the initial update is somehow missed I will just see dashes on the UI until the state changes from the first value. Is there perhaps a better way to approach the http polling, like perhaps doing a state update every polling cycle?

    public void setTemperature(String temperature) {
        StringType newVal = StringType.valueOf(temperature);
        if (!newVal.equals(this.temperature)) {
            this.temperature = newVal;
            handler.stateChanged(BryantBindingConstants.CHANNEL_TEMPERATURE, this.temperature);
        }
    }