diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a8cde7..29c0b24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 1.0.0b25 (2026-12-01) + +### Fixed + +- Respect manual overrides when closing after a window is closed, and cancel pending retries when a user takes over a moving cover. + ## 1.0.0b24 (2026-11-29) ### Fixed diff --git a/custom_components/house_assistant/frontend/labels.js b/custom_components/house_assistant/frontend/labels.js index 6b964cf..50759a0 100644 --- a/custom_components/house_assistant/frontend/labels.js +++ b/custom_components/house_assistant/frontend/labels.js @@ -1714,7 +1714,7 @@ export const LABELS = { ], "follow_up_close": [ "Nachziehen", - "Wird das Fenster am Abend geschlossen, fährt das Rollo zu (auch bei Übersteuerung)." + "Wird das Fenster am Abend geschlossen, fährt das Rollo zu, sofern keine Übersteuerung das abendliche Schließen blockiert." ], "evening_custom": [ "Eigene Abendzeiten", @@ -4337,7 +4337,7 @@ export const LABELS = { ], "follow_up_close": [ "Close after window closed", - "If the window is closed in the evening, the cover closes (also during an override)." + "If the window is closed in the evening, the cover closes unless an override blocks evening closing." ], "evening_custom": [ "Own evening times", @@ -6918,7 +6918,7 @@ export const SHUTTER = { ], "follow_up_close": [ "Nachziehen", - "Wird das Fenster am Abend geschlossen, fährt das Rollo zu (auch bei Übersteuerung)." + "Wird das Fenster am Abend geschlossen, fährt das Rollo zu, sofern keine Übersteuerung das abendliche Schließen blockiert." ], "follow_up_earliest": [ "Nachziehen ab", @@ -7316,7 +7316,7 @@ export const SHUTTER = { ], "follow_up_close": [ "Close after window closed", - "If the window is closed in the evening, the cover closes (also during an override)." + "If the window is closed in the evening, the cover closes unless an override blocks evening closing." ], "follow_up_earliest": [ "Close after window closed, from", diff --git a/custom_components/house_assistant/manifest.json b/custom_components/house_assistant/manifest.json index 1965149..11c6966 100644 --- a/custom_components/house_assistant/manifest.json +++ b/custom_components/house_assistant/manifest.json @@ -21,5 +21,5 @@ "loggers": ["anthropic"], "requirements": ["anthropic>=0.125.0"], "single_config_entry": true, - "version": "1.0.0b24" + "version": "1.0.0b25" } diff --git a/custom_components/house_assistant/shutter/engine.py b/custom_components/house_assistant/shutter/engine.py index 2a22ea3..96134fa 100644 --- a/custom_components/house_assistant/shutter/engine.py +++ b/custom_components/house_assistant/shutter/engine.py @@ -1735,6 +1735,7 @@ def _on_cover(self, event: Event[EventStateChangedData]) -> None: return now = dt_util.now() new_pos = as_float(new.attributes.get("current_position")) + takeover = self.tracker.take_over(entity_id, new.context.id, new.context.user_id) own = self.tracker.explains( entity_id, new.context.id, @@ -1751,7 +1752,19 @@ def _on_cover(self, event: Event[EventStateChangedData]) -> None: old_position=old_pos, new_position=new_pos, ) - if self.opt(CONF_OVERRIDE_TRIGGER) == TRIGGER_COMMAND: + if takeover and self.automatic: + self.movements.update( + entity_id, + started=False, + own=True, + old_state=None, + old_position=None, + new_state=new.state, + new_position=new_pos, + now=now.timestamp(), + ) + manual = True + elif self.opt(CONF_OVERRIDE_TRIGGER) == TRIGGER_COMMAND: manual = started else: manual = self.movements.update( diff --git a/custom_components/house_assistant/shutter/logic/override.py b/custom_components/house_assistant/shutter/logic/override.py index 653586d..b1e9e81 100644 --- a/custom_components/house_assistant/shutter/logic/override.py +++ b/custom_components/house_assistant/shutter/logic/override.py @@ -36,6 +36,14 @@ class CommandTracker: def register(self, cover: str, target: int | None, context_id: str | None, now: float) -> None: self._commands[cover] = _Command(target, context_id, now) + def take_over(self, cover: str, context_id: str | None, user_id: str | None) -> bool: + """Forget our command when a different user command takes over.""" + command = self._commands.get(cover) + if command is None or user_id is None or context_id == command.context_id: + return False + del self._commands[cover] + return True + def explains( self, cover: str, diff --git a/custom_components/house_assistant/shutter/logic/window.py b/custom_components/house_assistant/shutter/logic/window.py index 0bea629..9fb8434 100644 --- a/custom_components/house_assistant/shutter/logic/window.py +++ b/custom_components/house_assistant/shutter/logic/window.py @@ -249,8 +249,14 @@ def evening(rules: WindowRules, s: Situation) -> list[Action]: def follow_up(rules: WindowRules, s: Situation, after_earliest: bool) -> list[Action]: """Window closed in the evening: close the cover to the evening position - (ignores overrides).""" - if rules.follow_up_close and s.active and s.evening and after_earliest: + unless an override blocks evening closing.""" + if ( + rules.follow_up_close + and s.active + and s.evening + and after_earliest + and not _override_blocks_evening(rules, s) + ): return [_move(rules.evening_position, R_FOLLOW_UP), Action(MARK_EVENING, R_FOLLOW_UP)] return [] diff --git a/custom_components/house_assistant/strings.json b/custom_components/house_assistant/strings.json index 16889a1..2415193 100644 --- a/custom_components/house_assistant/strings.json +++ b/custom_components/house_assistant/strings.json @@ -1225,7 +1225,7 @@ "data_description": { "evening_close": "Close at the start of the evening mode, once per evening and only with a closed window.", "evening_position": "Target of the evening run and of closing after the window was closed. 0 % = closed; e.g. 20 % leaves a gap on warm nights.", - "follow_up_close": "If the window is closed in the evening, the cover closes (also during an override).", + "follow_up_close": "If the window is closed in the evening, the cover closes unless an override blocks evening closing.", "evening_custom": "Use the following values instead of the global ones.", "evening_earliest": "The evening mode never starts before this time.", "evening_elevation": "The evening mode starts when the sun drops below this elevation (e.g. -4 °).", diff --git a/custom_components/house_assistant/translations/de.json b/custom_components/house_assistant/translations/de.json index b8a340e..4cd4080 100644 --- a/custom_components/house_assistant/translations/de.json +++ b/custom_components/house_assistant/translations/de.json @@ -1225,7 +1225,7 @@ "data_description": { "evening_close": "Zu Beginn des Abendmodus schließen, einmal pro Abend und nur bei geschlossenem Fenster.", "evening_position": "Ziel des Abendlaufs und des Nachziehens. 0 % = zu; z. B. 20 % lässt in warmen Nächten einen Spalt.", - "follow_up_close": "Wird das Fenster am Abend geschlossen, fährt das Rollo zu (auch bei Übersteuerung).", + "follow_up_close": "Wird das Fenster am Abend geschlossen, fährt das Rollo zu, sofern keine Übersteuerung das abendliche Schließen blockiert.", "evening_custom": "Die folgenden Werte statt der globalen verwenden.", "evening_earliest": "Vor dieser Uhrzeit beginnt der Abendmodus nie.", "evening_elevation": "Der Abendmodus beginnt, wenn die Sonne unter diese Höhe sinkt (z. B. -4 °).", diff --git a/custom_components/house_assistant/translations/en.json b/custom_components/house_assistant/translations/en.json index 16889a1..2415193 100644 --- a/custom_components/house_assistant/translations/en.json +++ b/custom_components/house_assistant/translations/en.json @@ -1225,7 +1225,7 @@ "data_description": { "evening_close": "Close at the start of the evening mode, once per evening and only with a closed window.", "evening_position": "Target of the evening run and of closing after the window was closed. 0 % = closed; e.g. 20 % leaves a gap on warm nights.", - "follow_up_close": "If the window is closed in the evening, the cover closes (also during an override).", + "follow_up_close": "If the window is closed in the evening, the cover closes unless an override blocks evening closing.", "evening_custom": "Use the following values instead of the global ones.", "evening_earliest": "The evening mode never starts before this time.", "evening_elevation": "The evening mode starts when the sun drops below this elevation (e.g. -4 °).", diff --git a/docs/covers.en.md b/docs/covers.en.md index 1594c8e..1722603 100644 --- a/docs/covers.en.md +++ b/docs/covers.en.md @@ -31,7 +31,7 @@ The module is event driven: it reacts only to state changes of the entities conf * **Evening mode:** starts when the sun sinks below the configured elevation (default -4 °), at the earliest at 17:00 and at the latest at 21:00. It ends at 03:30 or at sunrise. Values global or per window. * **Evening run:** at the start of the evening mode each cover closes once if the window is closed and no override is active (per window: close despite an override, e.g. bedrooms). * **Evening position:** per window the target of evening run, follow-up closing and vacation in the evening. Default 0 % = closed; e.g. 20 % leaves a gap on warm nights. -* **Follow-up closing:** when a window is closed in the evening, the cover closes (from 16:00, also with an override). +* **Follow-up closing:** when a window is closed in the evening, the cover closes (from 16:00, unless an override blocks evening closing). * **Ventilation position:** when a window is opened and the cover is (almost) closed, it moves to the ventilation position (default 30 %). In the evening after 3 s, in daytime after 60 s, if the window is still open then. ### Window contacts, tilted and door @@ -59,7 +59,7 @@ The module is event driven: it reacts only to state changes of the entities conf Every manual movement (at the switch, in the app, not by House Assistant and not by other automations or scripts) starts an override for the window, default 60 min. Every further movement restarts it. Optionally it also ends at sunrise, with duration 0 only at sunrise. The module remembers its own movements, so late position reports are not taken for manual ones. -In the settings (panel *Covers > General*, card **Manual override**) you choose when it starts: **only when the cover really moves** (default; the position changes by more than 2 %, for covers without a position it stands differently afterwards) or **on every command by hand, also without a movement**. With the default, e.g. "Alexa, open all covers" starts no override for covers already open. +In the settings (panel *Covers > General*, card **Manual override**) you choose when it starts: **only when the cover really moves** (default; the position changes by more than 2 %, for covers without a position it stands differently afterwards) or **on every command by hand, also without a movement**. A user command taking over an active module movement starts an override immediately and cancels its retry. With the default, e.g. "Alexa, open all covers" starts no override for covers already open. ### Extra conditions instead of special rules diff --git a/docs/covers.md b/docs/covers.md index 7c75e9d..6a66867 100644 --- a/docs/covers.md +++ b/docs/covers.md @@ -31,7 +31,7 @@ Das Modul arbeitet ereignisgesteuert: Es reagiert nur auf Zustandswechsel der ei * **Abendmodus:** beginnt, wenn die Sonne unter die eingestellte Höhe sinkt (Standard -4 °), frühestens um 17:00 und spätestens um 21:00. Er endet um 03:30 oder bei Sonnenaufgang. Werte global oder pro Fenster. * **Abendlauf:** zu Beginn des Abendmodus schließt jedes Rollo einmal, wenn das Fenster zu ist und keine Übersteuerung aktiv ist (pro Fenster einstellbar: trotz Übersteuerung schließen, z. B. Schlafräume). * **Abendposition:** pro Fenster das Ziel von Abendlauf, Nachziehen und Urlaub abends. Standard 0 % = zu; z. B. 20 % lässt in warmen Nächten einen Spalt. -* **Nachziehen:** wird am Abend ein Fenster geschlossen, fährt das Rollo zu (ab 16:00, auch bei Übersteuerung). +* **Nachziehen:** wird am Abend ein Fenster geschlossen, fährt das Rollo zu (ab 16:00, sofern keine Übersteuerung das abendliche Schließen blockiert). * **Lüftungsposition:** wird ein Fenster geöffnet und das Rollo ist (fast) zu, fährt es auf die Lüftungsposition (Standard 30 %). Abends nach 3 s, tagsüber nach 60 s, wenn das Fenster dann noch offen ist. ### Fensterkontakte, gekippt und Tür @@ -59,7 +59,7 @@ Das Modul arbeitet ereignisgesteuert: Es reagiert nur auf Zustandswechsel der ei Jede manuelle Bewegung (am Taster, in der App, nicht durch House Assistant und nicht durch andere Automationen oder Skripte) startet eine Übersteuerung für das Fenster, Standard 60 min. Jede weitere Bewegung startet sie neu. Optional endet sie zusätzlich bei Sonnenaufgang, mit Dauer 0 nur bei Sonnenaufgang. Das Modul merkt sich seine eigenen Fahrten, späte Positionsmeldungen werden deshalb nicht fälschlich als manuell gewertet. -In den Einstellungen (Panel *Rollos > Allgemein*, Karte **Manuelle Übersteuerung**) lässt sich wählen, wann sie beginnt: **nur wenn das Rollo wirklich fährt** (Standard; die Position ändert sich um mehr als 2 %, bei Rollos ohne Position steht es danach anders) oder **bei jedem Befehl von Hand, auch ohne Fahrt**. Mit dem Standard startet z. B. „Alexa, alle Rollos auf“ keine Übersteuerung bei Rollos, die schon offen sind. +In den Einstellungen (Panel *Rollos > Allgemein*, Karte **Manuelle Übersteuerung**) lässt sich wählen, wann sie beginnt: **nur wenn das Rollo wirklich fährt** (Standard; die Position ändert sich um mehr als 2 %, bei Rollos ohne Position steht es danach anders) oder **bei jedem Befehl von Hand, auch ohne Fahrt**. Übernimmt ein Benutzerbefehl eine laufende Fahrt des Moduls, startet sofort eine Übersteuerung und der Wiederholungsversuch entfällt. Mit dem Standard startet z. B. „Alexa, alle Rollos auf“ keine Übersteuerung bei Rollos, die schon offen sind. ### Zusatzbedingungen statt Sonderregeln diff --git a/tests/shutter/ha/test_engine.py b/tests/shutter/ha/test_engine.py index 37b0f64..8e2e40a 100644 --- a/tests/shutter/ha/test_engine.py +++ b/tests/shutter/ha/test_engine.py @@ -830,3 +830,57 @@ async def test_heating_day_with_a_too_warm_room_still_protects( await _summer_noon(hass, freezer, heating_entity=HEATING_DAY, room={"temperature_sensor": ROOM}) await advance(hass, freezer, 15 * 60) assert len(calls["set_cover_position"]) == 1 + + +async def test_follow_up_does_not_close_during_override( + hass: HomeAssistant, base_states, calls, freezer: FrozenDateTimeFactory +) -> None: + freezer.move_to("2026-12-15 16:55:00+01:00") + await setup_entry(hass, make_entry()) + await advance(hass, freezer, 10 * 60) + assert len(calls["close_cover"]) == 1 + set_cover(hass, 0) + await hass.async_block_till_done() + await advance(hass, freezer, 20) + set_cover(hass, 0, state="opening") + set_cover(hass, 40) + await hass.async_block_till_done() + assert hass.states.get(OVERRIDE).state == "on" + hass.states.async_set(CONTACT, "on") + await hass.async_block_till_done() + await advance(hass, freezer, 4, step=1) + hass.states.async_set(CONTACT, "off") + await hass.async_block_till_done() + await advance(hass, freezer, 6, step=1) + assert len(calls["close_cover"]) == 1 + + +async def test_user_takes_over_own_movement_cancels_retry( + hass: HomeAssistant, base_states, calls, freezer: FrozenDateTimeFactory +) -> None: + freezer.move_to("2026-12-15 16:55:00+01:00") + await setup_entry(hass, make_entry(verify_after=90)) + await advance(hass, freezer, 6 * 60) + assert len(calls["close_cover"]) == 1 + set_cover(hass, 80, state="closing") + await hass.async_block_till_done() + set_cover(hass, 75, state="opening", context=Context(user_id="user")) + await hass.async_block_till_done() + assert hass.states.get(OVERRIDE).state == "on" + await advance(hass, freezer, 120) + assert len(calls["close_cover"]) == 1 + assert engine_of(hass).windows[WINDOW_ID].last_reason.get("code") != "cover_retry" + + +async def test_ordinary_report_during_own_movement_keeps_retry( + hass: HomeAssistant, base_states, calls, freezer: FrozenDateTimeFactory +) -> None: + freezer.move_to("2026-12-15 16:55:00+01:00") + await setup_entry(hass, make_entry(verify_after=90)) + await advance(hass, freezer, 6 * 60) + assert len(calls["close_cover"]) == 1 + set_cover(hass, 80, state="closing", context=Context(parent_id="automation")) + await hass.async_block_till_done() + assert hass.states.get(OVERRIDE).state == "off" + await advance(hass, freezer, 120) + assert len(calls["close_cover"]) >= 2 diff --git a/tests/shutter/logic/test_override.py b/tests/shutter/logic/test_override.py index 0c82941..bb5da3e 100644 --- a/tests/shutter/logic/test_override.py +++ b/tests/shutter/logic/test_override.py @@ -133,3 +133,13 @@ def test_reached() -> None: assert not reached(100, None, "closed") assert reached(0, None, "closed") assert reached(50, None, "open") + + +def test_user_takes_over_tracked_command() -> None: + tracker = CommandTracker() + tracker.register("cover.a", 0, "ours", 0) + assert not tracker.take_over("cover.a", "ours", "user") + assert not tracker.take_over("cover.a", "other", None) + assert tracker.explains("cover.a", "other", "closing", 50, 1) + assert tracker.take_over("cover.a", "other", "user") + assert not tracker.explains("cover.a", "other", "closing", 50, 2) diff --git a/tests/shutter/logic/test_window.py b/tests/shutter/logic/test_window.py index 3cb110f..0b6a785 100644 --- a/tests/shutter/logic/test_window.py +++ b/tests/shutter/logic/test_window.py @@ -167,9 +167,17 @@ def test_evening_run_for_window_not_in_vacation_simulation() -> None: assert w.evening(replace(RULES, vacation=False), replace(EVENING, vacation=True)) -def test_follow_up_closes_in_the_evening_regardless_of_override() -> None: +def test_follow_up_respects_override() -> None: s = replace(EVENING, override=True, evening_marker=True) - assert kinds(w.follow_up(RULES, s, after_earliest=True))[0] == (w.POSITION, w.R_FOLLOW_UP, 0) + assert w.follow_up(RULES, s, after_earliest=True) == [] + assert kinds(w.follow_up(replace(RULES, override_ignore_evening=True), s, after_earliest=True))[ + 0 + ] == (w.POSITION, w.R_FOLLOW_UP, 0) + assert kinds(w.follow_up(RULES, replace(s, override=False), after_earliest=True))[0] == ( + w.POSITION, + w.R_FOLLOW_UP, + 0, + ) assert w.follow_up(RULES, s, after_earliest=False) == [] assert w.follow_up(RULES, replace(s, evening=False), after_earliest=True) == [] assert w.follow_up(replace(RULES, follow_up_close=False), s, after_earliest=True) == []