Let the on/off switch on a wide tile switch, instead of sending the opposite of what it shows (0.2.86)

A tap on the On/off switch of a wide or full-page tile moved the knob to on
and back, and the light stayed off. Since firmware 0.2.59 control_event drew
the new position first (Tile::optimistic writes it into state) and then asked
key_action for the action, which read that new position: an off light got
light.turn_off, an on light light.turn_on. A tap on the tile itself was never
affected.

tile_controls::press_key chooses the action first and then shows the new
position; control_event uses it. Unit tests cover a light, a fan, a sensor
and a cover key.

Checked with tools/check.sh (471 Python tests, 19/19 C++) and compiled for
both boards: CYD 1,677,504 B (91.4 %, +16 B), Guition 2,054,640 B (25.3 %).
On Max's Guition Wallbox (OTA from this branch) every tap on the switch sent
the right action and Home Assistant's logbook followed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Max Gramser
2026-09-19 08:15:50 +02:00
parent 311fa2a7fd
commit 2d343a450f
8 changed files with 103 additions and 5 deletions
+11
View File
@@ -128,6 +128,17 @@ int main() {
assert(key_action(make("light.lamp", "off"), TOGGLE).service == "light.turn_on");
assert(!key_action(make("sensor.x", "1"), TOGGLE).valid());
assert(!key_action(make("sensor.x", "1"), RUN).valid());
// A toggle key sends what its tap asks for and then shows the new stand; firmware 0.2.59 to 0.2.71 showed it first
// and so sent an off light light.turn_off.
Tile off_lamp = make("light.lamp", "off");
assert(press_key(off_lamp, TOGGLE).service == "light.turn_on" && off_lamp.state == "on" && off_lamp.optimistic_tap);
off_lamp.undo_optimistic(); assert(off_lamp.state == "off");
Tile on_fan = make("fan.ceiling", "on");
assert(press_key(on_fan, TOGGLE).service == "fan.turn_off" && on_fan.state == "off");
Tile odd = make("sensor.x", "1");
assert(!press_key(odd, TOGGLE).valid() && odd.state == "1" && !odd.optimistic_tap);
Tile shut = make("cover.shutter", "closed", 3);
assert(press_key(shut, COVER_OPEN).service == "cover.open_cover" && shut.state == "closed" && !shut.optimistic_tap);
// Panel kinds.
Tile lamp = make("light.lamp", "on"); lamp.controls = "brightness";