dawidchyrzynski / arduino-home-assistant

ArduinoHA allows to integrate an Arduino/ESP based device with Home Assistant using MQTT.
https://dawidchyrzynski.github.io/arduino-home-assistant/
GNU Affero General Public License v3.0
480 stars 116 forks source link

HASelect.setState() should allow setting -1 #146

Closed rrozema closed 7 months ago

rrozema commented 1 year ago

It would be very helpful to me if HASelect would allow to set the state back to -1 after it has been some valid state. In HA this should result in an update to the same 'unknown' value that is shown initially when no state has been assigned yet.

My scenario is a fake "traffic light", where the 3 lights can be controlled by individual switches per light but the lights can also be controlled via a "traffic light" select. If the individual switches are in a valid "traffic light"-combination (exactly 1 light is on), the "traffic light" select should show this combination's name. When however an invalid combination is chosen (0, 2 or 3 lights are on at the same time) using the switches, the select should be updated to the -1 - 'unknown' value. I do however not want the select to show this "unknown" option to the user to choose from.

My idea is to add some setDefaultOption() method that allows the developer to specify the text for this -1 value.

rrozema commented 1 year ago

I've been testing this and I don't know if it's even possible to set a value that is not in the list of options (i.e. this is what would be needed to set -1). So far I haven't been able to do it myself, so I won't blame you if you reject this ;-) , but if you could have a look to see if you can think of a way to (re-)set the select's state -1 and have HA show 'unavailable' (or something like that) I would certainly appreciate it!

dawidchyrzynski commented 7 months ago

This feature will be available in the upcoming version of the library. Please refer to the linked Pull Request for more information.