openhab-addons
openhab-addons copied to clipboard
[mqtt.generic] Send ON/OFF for dimmer channels when so configured
Similar to how UP/DOWN are processed for rollershutters.
Fixes #7991
As a general question: Wouldn't it make sense to use the converters introduced in https://github.com/openhab/openhab-core/pull/3355?
I was not aware of their existence. Yes, it probably would make sense to use those, but I would prefer to get this PR in as is, and then do a separate (much larger!) PR converting to those. It will need to consider how all the "downstream" MQTT bindings rely on their conversions, and possibly add more capabilities to core. In particular, some of the recent Home Assistant components I've added rely on non-round-trippable conversions. I.e. Cover/Rollershutter you send OPEN, but the state is open (or fully configurable command and state values). I have a WIP I haven't opened a PR for yet for Lock where you send LOCK, UNLOCK, or OPEN, but the states are LOCKED, UNLOCKED, LOCKING, UNLOCKING, JAMMED.
Note that this conflicts with #15925. I'd rather that one merge first. Once that's done, I'll rebase this one.
I just tested this, and it's ready for review
ping @antroids @jlaur @lolodomo
Ping @antroids @jlaur @lolodomo
Please rebase.
ping @ccutrer
rebased, conflicts resolved, which then required some changes to tests, and squashed it all together
Looking through this again, there's nothing that prevents you from still entering a number for the special ON/OFF values. They'll just be treated as a string --- exactly as before. The only difference is that on/off no longer have a default (of 1/0). Which isn't actually a difference, because ON/OFF (on sending a command) will first be translated to PercentType.HUNDRED/PercentType.ZERO, and then scaled to the min/max, ending up at 100/0 or 1/0 as appropriate. On return back from MQTT with a current state, this commit will actually fix a bug if your min/max is 0-100, but you leave the on string as the default of "1", "1" would inadvertently get treated as 100%, not 1%.