ColorItem / Hue and Saturation updates

Hey,

i have following challenge in the homekit binding with Color Item.
iOS home app sends HUE and saturation as separate requests at the same time.

Currently i do following to

setHue(newHue) {
            State state = item.getState();
            item.send(new HSBType(new DecimalType(newHue), 
                                        ((HSBType) state).getSaturation(),
                                        ((HSBType) state).getBrightness()));
}

setSaturation(newSaturation) {
               State state = item.getItem().getState();
               item.send(new HSBType(((HSBType) state).getHue(),
                        new PercentType(newSaturation), ((HSBType) state).getBrightness()));
}

the issue is - both methods get executed almost at the same time so that i have 2 commands:

  • one with new HUE but old saturation
  • another one with new saturation but old hue.

depending in which orders commands get executed, either new hue or new saturation get lost.

the only solution i can think of is to put setState() directly after send(). setState makes update faster and hence reduces the risks that one will read before another one is done with update. but this would probably lead to some issue with rule triggers.

are there any better options?

is there a way to check whether an item has commands in queue ?

Obviously this does not apply directly within a binding, but the general approach may give you some hints.

The critical thing you need to determine is if you always get a pair of data chunks. If so, you can build a trap that is set when one arrives and is released when the second arrives.

If there may or may not be a second payload, you will have to implement a timeout to escape prematurely. You might want to do that anyway, as a failsafe in error situations.

1 Like

As @rossko57 this example should solve this problem.

thank you @rossko57 @mjcumming!
i will try to implement the same approach in the binding.

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