Skip to content

Commit ac2fa33

Browse files
committed
firmware: Avoid updating state.lock.since when holdopen_button=True
This should avoid MQTT messages being spammed continiously in this case Fixes #14
1 parent 6a783ae commit ac2fa33

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

firmware/dlockoslo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def ensure_unlocked_for_opener():
138138
lock = TemporarilyUnlocked(since=i.current_time, until=i.current_time+temp_unlock_time)
139139

140140
# unlock switch
141-
if i.holdopen_button == True:
141+
if i.holdopen_button == True and lock.state != 'Unlocked':
142142
lock = Unlocked(since=i.current_time, reason='switch')
143143
elif i.holdopen_button == False and lock.state == 'Unlocked' and lock.reason == 'switch':
144144
lock = Locked(since=i.current_time, reason='switch')

firmware/test_doorsystem.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,27 @@ def test_dooropener_after_unlock():
167167
assert states.opener.state == 'TemporarilyActive'
168168

169169

170+
def test_holdopen_since_updates():
171+
states = dlockoslo.States()
172+
assert states.lock.state == 'Locked'
173+
assert states.opener.state == 'Inactive'
174+
inputs = dict(
175+
holdopen_button=True,
176+
current_time=100,
177+
)
178+
states = dlockoslo.next_state(states, dlockoslo.Inputs(**inputs))
179+
assert states.lock.state == 'Unlocked', 'unlocks'
180+
assert states.lock.since == 100, 'update since on initial transition'
181+
182+
inputs = dict(
183+
holdopen_button=True,
184+
current_time=222,
185+
)
186+
states = dlockoslo.next_state(states, dlockoslo.Inputs(**inputs))
187+
assert states.lock.state == 'Unlocked', 'still unlocked'
188+
assert states.lock.since == 100, 'dont update since when no state transition'
189+
190+
170191
def test_bolt_present_reflects_input():
171192
states = dlockoslo.States()
172193
assert states.lock.state == 'Locked'

0 commit comments

Comments
 (0)