openhab / openhab-addons

Add-ons for openHAB
https://www.openhab.org/
Eclipse Public License 2.0
1.9k stars 3.59k forks source link

[ism8] Allow linking switch-r to Contact items #17742

Open holgerfriedrich opened 1 week ago

holgerfriedrich commented 1 week ago

switch-r elements are typically mapped to Switch items. With this PR, you can also map them to Contact items. This is better suited for the read-only elements.

Additionally, I added the warning statement about DPT 1.009 to the README. (It is the same as for KNX, DPT1.009 should have been inverted. Implementing it correctly will break existing installations.)

Without this PR, Contact items are not compatible and will not be updated.

I am not sure about the approach (using DecimalType 0 and 1 instead of enum identifiers from OnOffType).

Further testing is recommended. I did a short developer test, Contact and Switch items are now being filled correctly when data arrives.

lsiepel commented 1 week ago

Personally i like the idea to let the user choose the item they like to use. On the other hand a contact is not a read-only switch, there are more differences. The state On/Off vs Open/Close for instance. I remember this has been talked about before in different bindings, not sure how it ended and failed to find it again.

I think it would be best to create an issue at the main UI repo to ask for real read-only switch support. As currently the user is able to toggle the switch even if it is marked read-only.

Do you have an example where a contact is a better fit then a switch?

holgerfriedrich commented 1 week ago

I use contact items for all read-only switch items. I use it with the Android apps and still the basic ui. Most of my items are set by the KNX binding, which can handle both Switch and Contact.

As you said, this leads to some inconsistencies, open/close is obvious for doors and windows, but not for, e.g., a fire alarm. On is mapped to open. For KNX DPT 1.009 it should be opposite. I defined a MAP to get useful text for my Contact items, as well as I copied icons from the classic icon set with the proper naming. image Works for me, but it is inconvenient for new users. When I use switches, the switch symbol interferes with the item text. And I could accidentally click the switch from the UI.

I used the same approach for ism8, but the Contact items did not update. No warning in the logs. This is why I created this PR. "0" and "1" seems to work for Switch and Contact.

A read-only switch supported by all UIs would make this easier, but do you think this is a lot of work to do.... Do you think we should start this discussion?

lolodomo commented 1 week ago

For read-only switch, with sitemap UIs, you can simply use a Text element. Edit: or even Default element which checks if the item is read-only.

holgerfriedrich commented 1 week ago

For read-only switch, with sitemap UIs, you can simply use a Text element. Edit: or even Default element which checks if the item is read-only.

Yes, if the elements of the sitemap are listed explicitly. If you just include Groups to your sitemap and let OH generate the list of items OH will stick to the type of the single element....