示例#1
0
def test_bolt_present_periodic_update(bolt_present):

    states = dlockoslo.States()
    inputs = dict(bolt_present=bolt_present, )
    states = dlockoslo.next_state(states, dlockoslo.Inputs(**inputs))
    assert states.lock.state == 'Locked'
    assert states.bolt_present == bolt_present
    last_updated = states.bolt_present_updated

    inputs = dict(
        bolt_present=bolt_present,
        current_time=30.0,  # shorter than update setting
    )
    states = dlockoslo.next_state(states, dlockoslo.Inputs(**inputs))
    assert states.lock.state == 'Locked'
    assert states.bolt_present == bolt_present
    assert states.bolt_present_updated == last_updated, 'should not update'

    inputs = dict(
        bolt_present=bolt_present,
        current_time=90.0,  # longer than update setting
    )
    states = dlockoslo.next_state(states, dlockoslo.Inputs(**inputs))
    assert states.lock.state == 'Locked'
    assert states.bolt_present == bolt_present
    assert states.bolt_present_updated > last_updated, 'should update'
    assert states.bolt_present_updated == 90.0
示例#2
0
def test_openbutton_inside_when_locked():
    states = dlockoslo.States()
    assert states.lock.state == 'Locked'
    inputs = dict(openbutton_inside=True, )
    states = dlockoslo.next_state(states, dlockoslo.Inputs(**inputs))
    # should unlock and open
    assert states.lock.state == 'TemporarilyUnlocked'
    assert states.opener.state == 'TemporarilyActive'
示例#3
0
def test_openbutton_inside_when_unlocked():
    states = dlockoslo.States(lock=dlockoslo.Unlocked(since=1))
    assert states.lock.state == 'Unlocked'
    inputs = dict(openbutton_inside=True, )
    states = dlockoslo.next_state(states, dlockoslo.Inputs(**inputs))
    # should just open, leave lock alone
    assert states.lock.state == 'Unlocked'
    assert states.opener.state == 'TemporarilyActive'
示例#4
0
def test_openbutton_outside_when_unlocked():
    states = dlockoslo.States(lock=dlockoslo.Unlocked(since=1))
    assert states.lock.state == 'Unlocked'
    inputs = dict(openbutton_outside=True, )
    states = dlockoslo.next_state(states, dlockoslo.Inputs(**inputs))
    # should _not unlock or open_ (user must open door using app first)
    assert states.lock.state == 'Unlocked'
    assert states.opener.state == 'TemporarilyActive'
示例#5
0
def test_openbutton_outside_when_locked():
    states = dlockoslo.States()
    assert states.lock.state == 'Locked'
    inputs = dict(openbutton_outside=True, )
    states = dlockoslo.next_state(states, dlockoslo.Inputs(**inputs))
    # should _not unlock or open_ (user must open door using app first)
    assert states.lock.state == 'Locked'
    assert states.opener.state == 'Inactive'
示例#6
0
def test_mqtt_unlock_duration():
    states = dlockoslo.States()
    inputs = dict(
        current_time=103,
        mqtt_request=('unlock', 11),
    )
    states = dlockoslo.next_state(states, dlockoslo.Inputs(**inputs))
    assert states.lock.state == 'TemporarilyUnlocked'
    assert states.lock.until == 103 + 11
示例#7
0
def test_switch_unlocks_door():
    states = dlockoslo.States()
    assert states.lock.state == 'Locked'
    assert states.opener.state == 'Inactive'
    inputs = dict(holdopen_button=True, )
    states = dlockoslo.next_state(states, dlockoslo.Inputs(**inputs))
    assert states.lock.state == 'Unlocked', 'unlocks'
    assert states.opener.state == 'Inactive', 'leave opener unchanged'

    inputs = dict(holdopen_button=False, )
    states = dlockoslo.next_state(states, dlockoslo.Inputs(**inputs))
    assert states.lock.state == 'Locked'
示例#8
0
def test_dooropener_after_unlock():
    states = dlockoslo.States()
    assert states.lock.state == 'Locked'
    assert states.opener.state == 'Inactive'
    inputs = dict(holdopen_button=True, )
    states = dlockoslo.next_state(states, dlockoslo.Inputs(**inputs))
    assert states.lock.state == 'Unlocked', 'unlocks'
    assert states.opener.state == 'Inactive', 'leave opener unchanged'

    inputs = dict(
        holdopen_button=True,
        openbutton_outside=True,
    )
    states = dlockoslo.next_state(states, dlockoslo.Inputs(**inputs))
    assert states.opener.state == 'TemporarilyActive'
示例#9
0
def test_bolt_present_reflects_input():
    states = dlockoslo.States()
    assert states.lock.state == 'Locked'
    assert states.opener.state == 'Inactive'
    inputs = dict(bolt_present=False, )
    states = dlockoslo.next_state(states, dlockoslo.Inputs(**inputs))
    assert states.lock.state == 'Locked'
    assert not states.bolt_present

    # False -> True
    inputs = dict(bolt_present=True, )
    states = dlockoslo.next_state(states, dlockoslo.Inputs(**inputs))
    assert states.lock.state == 'Locked'
    assert states.bolt_present

    # True -> False
    inputs = dict(bolt_present=False, )
    states = dlockoslo.next_state(states, dlockoslo.Inputs(**inputs))
    assert states.lock.state == 'Locked'
    assert not states.bolt_present
示例#10
0
def test_compound():
    states = dlockoslo.States()
    assert isinstance(states.lock, dlockoslo.Locked)

    inputs = dict(
        openbutton_outside=False,
        openbutton_inside=False,
        mqtt_connected=True,
        mqtt_request=False,
        holdopen_button=False,
        current_time=100,
    )

    # unlock, trigger dooropener
    inputs['openbutton_outside'] = True
    inputs['mqtt_request'] = ('unlock', True)
    states = dlockoslo.next_state(states, dlockoslo.Inputs(**inputs))
    assert states.connected_light == True
    assert states.lock.state == 'Unlocked'
    assert states.opener.state == 'TemporarilyActive'

    # forward until dooropened deactived, trigger time-based door unlocking
    inputs['current_time'] = 130
    inputs['openbutton_outside'] = False
    inputs['mqtt_request'] = ('unlock', 30)
    states = dlockoslo.next_state(states, dlockoslo.Inputs(**inputs))
    assert states.opener.state == 'Inactive'
    assert states.lock.state == 'TemporarilyUnlocked'

    # clear MQTT message, forward time
    inputs['current_time'] = 200
    inputs['mqtt_request'] = None

    states = dlockoslo.next_state(states, dlockoslo.Inputs(**inputs))
    assert states.opener.state == 'Inactive'
    assert states.lock.state == 'Locked'
示例#11
0
def test_mqtt_unlock_duration_when_unlocked():
    states = dlockoslo.States(lock=dlockoslo.Unlocked(since=1))
    inputs = dict(mqtt_request=('unlock', True), )
    states = dlockoslo.next_state(states, dlockoslo.Inputs(**inputs))
    # should not change state
    assert states.lock.state == 'Unlocked'
示例#12
0
def test_mqtt_lock():
    states = dlockoslo.States(lock=dlockoslo.Unlocked(since=1))
    inputs = dict(mqtt_request=('lock', True), )
    states = dlockoslo.next_state(states, dlockoslo.Inputs(**inputs))
    assert states.lock.state == 'Locked'
示例#13
0
def test_mqtt_unlock():
    states = dlockoslo.States()
    inputs = dict(mqtt_request=('unlock', True), )
    states = dlockoslo.next_state(states, dlockoslo.Inputs(**inputs))
    assert states.lock.state == 'Unlocked'