Skip to content

Commit

Permalink
firmware: Avoid updating state.lock.since when holdopen_button=True
Browse files Browse the repository at this point in the history
This should avoid MQTT messages being spammed continiously in this case
Fixes #14
  • Loading branch information
jonnor committed Jan 12, 2020
1 parent 6a783ae commit ac2fa33
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion firmware/dlockoslo.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def ensure_unlocked_for_opener():
lock = TemporarilyUnlocked(since=i.current_time, until=i.current_time+temp_unlock_time)

# unlock switch
if i.holdopen_button == True:
if i.holdopen_button == True and lock.state != 'Unlocked':
lock = Unlocked(since=i.current_time, reason='switch')
elif i.holdopen_button == False and lock.state == 'Unlocked' and lock.reason == 'switch':
lock = Locked(since=i.current_time, reason='switch')
Expand Down
21 changes: 21 additions & 0 deletions firmware/test_doorsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,27 @@ def test_dooropener_after_unlock():
assert states.opener.state == 'TemporarilyActive'


def test_holdopen_since_updates():
states = dlockoslo.States()
assert states.lock.state == 'Locked'
assert states.opener.state == 'Inactive'
inputs = dict(
holdopen_button=True,
current_time=100,
)
states = dlockoslo.next_state(states, dlockoslo.Inputs(**inputs))
assert states.lock.state == 'Unlocked', 'unlocks'
assert states.lock.since == 100, 'update since on initial transition'

inputs = dict(
holdopen_button=True,
current_time=222,
)
states = dlockoslo.next_state(states, dlockoslo.Inputs(**inputs))
assert states.lock.state == 'Unlocked', 'still unlocked'
assert states.lock.since == 100, 'dont update since when no state transition'


def test_bolt_present_reflects_input():
states = dlockoslo.States()
assert states.lock.state == 'Locked'
Expand Down

0 comments on commit ac2fa33

Please sign in to comment.