Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ The integration is event driven: it only reacts to state changes of the configur
### Door lock and children

* Unlocking or opening the lock disarms. A lock that comes back from "unavailable" (radio, bridge, battery) as unlocked does not count as unlocking.
* If the lock falls back after locking or reports "jammed", the panel stays armed, a message is sent and locking is retried once.
* If the lock falls back after locking or reports "jammed", the panel stays armed, locking is retried silently. A message is sent only if the retry also fails.
* Arming locks the door when it is closed and no children are alone at home.
* **Children alone at home** (switch) prevents automatic arming and locking and controls the camera. It is reset a configurable time after unlocking and at night.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Die Integration arbeitet ereignisgesteuert: Sie reagiert nur auf Zustandswechsel
### Türschloss und Kinder

* Entriegeln oder Öffnen des Schlosses schaltet unscharf. Meldet sich ein Schloss nach "nicht verfügbar" (Funk, Bridge, Batterie) als entriegelt zurück, zählt das nicht als Entriegeln.
* Fällt das Schloss nach dem Abschließen zurück oder meldet es "blockiert", bleibt die Anlage scharf, es kommt eine Meldung und ein zweiter Versuch.
* Fällt das Schloss nach dem Abschließen zurück oder meldet es "blockiert", bleibt die Anlage scharf, es folgt ein stiller zweiter Versuch. Erst wenn auch dieser scheitert, kommt eine Meldung.
* Beim Scharfschalten wird abgeschlossen, wenn die Tür zu ist und keine Kinder alleine zuhause sind.
* **Kinder alleine zuhause** (Schalter) verhindert automatisches Scharfschalten und Abschließen und steuert die Kamera. Er wird eine einstellbare Zeit nach dem Entriegeln und nachts zurückgesetzt.

Expand Down
45 changes: 35 additions & 10 deletions custom_components/alarm_assistant/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ def __init__(self, hass: HomeAssistant, entry: AlarmConfigEntry) -> None:
# door lock: when we last sent "lock" and whether we already retried
self.lock_sent: datetime | None = None
self.lock_retried = False
self.lock_failure_reported = False
# call
self.call_block_until: datetime | None = None
self.call_acked = False
Expand Down Expand Up @@ -1036,6 +1037,8 @@ def _armed(self, automatic: bool) -> None:
else:
self._log("log_auto_armed" if automatic else "log_armed")
self.lock_retried = False
self.lock_failure_reported = False
self._cancel("lock_check")
self._lock_door()
for entity_id in self._filter("armed_on", self.opt_list(CONF_ARM_ON_ENTITIES)):
self.config_entry.async_create_task(
Expand Down Expand Up @@ -1095,28 +1098,50 @@ def _lock_bounced(self, old: State | None, new: State) -> bool:

def _lock_failed(self) -> None:
self.lock_sent = None
self._log("log_lock_failed")
retry = not self.lock_retried
self._notify(
self._push(CONF_NOTIFY),
self._mark(self.t("title_lock_failed")),
self._mark(self.t("push_lock_retry" if retry else "push_lock_failed")),
)
if retry:
if not self.lock_retried:
self.lock_retried = True
self._log("log_lock_retry", seconds=LOCK_RETRY)
self._schedule(
"lock_retry",
dt_util.utcnow() + timedelta(seconds=LOCK_RETRY),
lambda _now: self._lock_door() if self.state in sm.ARMED_STATES else None,
self._retry_lock,
)
elif not self.lock_failure_reported:
self.lock_failure_reported = True
self._cancel("lock_check")
self._log("log_lock_failed")
self._notify(
self._push(CONF_NOTIFY),
self._mark(self.t("title_lock_failed")),
self._mark(self.t("push_lock_failed")),
)

def _retry_lock(self, _now: datetime) -> None:
lock = self.opt(CONF_LOCK)
if self.state not in sm.ARMED_STATES or not lock or not self.opt(CONF_LOCK_ON_ARM):
return
if self.kids_home or not self._filter("lock", [lock]):
return
door = self.opt(CONF_LOCK_DOOR)
if (door and self._value(door) != sm.OFF) or self._value(lock) in (*INVALID, None):
self._lock_failed()
return
self._lock_door()
self._schedule(
"lock_check", dt_util.utcnow() + timedelta(seconds=LOCK_SETTLE), self._check_lock
)

def _check_lock(self, _now: datetime) -> None:
if self.state in sm.ARMED_STATES and self._value(self.opt(CONF_LOCK)) != "locked":
self._lock_failed()

def disarm(self, by_lock: bool = False) -> None:
if self.state == sm.DISARMED:
return
if self.state == sm.TRIGGERED:
self._sirens_off()
self.lock_sent = None
for key in ("exit", "entry", "trigger_end", "lock_retry"):
for key in ("exit", "entry", "trigger_end", "lock_retry", "lock_check"):
self._cancel(key)
self.state = sm.DISARMED
self.bypassed = []
Expand Down
2 changes: 1 addition & 1 deletion custom_components/alarm_assistant/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"issue_tracker": "https://github.com/Jumpmaster2/Alarm-Assistant/issues",
"requirements": [],
"single_config_entry": true,
"version": "0.6.1"
"version": "0.6.2"
}
9 changes: 4 additions & 5 deletions custom_components/alarm_assistant/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@
"en": "Alarm armed, these open sensors are ignored until disarming: {sensors}.",
},
"title_lock_failed": {"de": "Tür nicht abgeschlossen", "en": "Door not locked"},
"push_lock_retry": {
"de": "Das Schloss hat sich nicht verriegelt. Die Alarmanlage bleibt scharf, "
"Abschließen wird gleich noch einmal versucht.",
"en": "The lock did not engage. The alarm stays armed, locking is retried shortly.",
},
"push_lock_failed": {
"de": "Das Schloss hat sich wieder nicht verriegelt. Die Alarmanlage bleibt scharf, "
"die Tür ist aber nicht abgeschlossen.",
Expand Down Expand Up @@ -142,6 +137,10 @@
},
"log_auto_armed": {"de": "Automatisch scharf geschaltet", "en": "Armed automatically"},
"log_locked": {"de": "Tür abgeschlossen", "en": "Door locked"},
"log_lock_retry": {
"de": "Abschließen nicht bestätigt, neuer Versuch in {seconds} s",
"en": "Locking not confirmed, retrying in {seconds} s",
},
"log_lock_failed": {
"de": "Abschließen fehlgeschlagen, bleibt scharf",
"en": "Locking failed, stays armed",
Expand Down
28 changes: 26 additions & 2 deletions tests/ha/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ async def test_lock_falling_back_does_not_disarm(
await advance(hass, freezer, 3)
await set_state(hass, LOCK, "unlocked")
assert _state(hass) == "armed_away"
assert any("retried" in c.data["message"] for c in calls["notify"])
assert not any("lock" in c.data["message"].lower() for c in calls["notify"])
# one retry, a second failure only warns
await advance(hass, freezer, 11)
assert len(calls["lock"]) == 2
Expand All @@ -258,6 +258,30 @@ async def test_lock_falling_back_does_not_disarm(
assert _state(hass) == "disarmed"


@pytest.mark.parametrize("outcome", ["locked", "unchanged", "disarmed", "jammed"])
async def test_lock_retry_outcomes(
hass: HomeAssistant, base_states, calls, freezer: FrozenDateTimeFactory, outcome: str
) -> None:
freezer.move_to(START)
await setup_entry(hass, make_entry(**REACTIONS))
await _arm(hass)
if outcome == "jammed":
await set_state(hass, LOCK, "jammed")
else:
await set_state(hass, LOCK, "locking")
await set_state(hass, LOCK, "unlocked")
assert not any("lock" in c.data["message"].lower() for c in calls["notify"])
if outcome == "disarmed":
await _disarm(hass)
await advance(hass, freezer, 11)
assert len(calls["lock"]) == (1 if outcome == "disarmed" else 2)
if outcome in ("locked", "jammed"):
await set_state(hass, LOCK, "locked")
await advance(hass, freezer, 25)
failures = [c for c in calls["notify"] if "again" in c.data["message"]]
assert len(failures) == (1 if outcome == "unchanged" else 0)


async def test_code(
hass: HomeAssistant, base_states, calls, freezer: FrozenDateTimeFactory
) -> None:
Expand Down Expand Up @@ -802,7 +826,7 @@ async def test_jammed_lock_warns_and_retries(
await set_state(hass, LOCK, "locking")
await set_state(hass, LOCK, "jammed")
assert _state(hass) == "armed_away"
assert any("retried" in c.data["message"] for c in calls["notify"])
assert not any("lock" in c.data["message"].lower() for c in calls["notify"])
await advance(hass, freezer, 11)
assert len(calls["lock"]) == 2

Expand Down
Loading