Exemplo n.º 1
0
def test_lock_alarm_level(mock_openzwave):
    """Test alarm level for Z-Wave lock."""
    node = MockNode()
    values = MockEntityValues(
        primary=MockValue(data=None, node=node),
        access_control=None,
        alarm_type=MockValue(data=None, node=node),
        alarm_level=MockValue(data=None, node=node),
    )
    device = lock.get_device(node=node, values=values, node_config={})

    assert lock.ATTR_LOCK_STATUS not in device.extra_state_attributes

    values.alarm_type.data = 21
    values.alarm_level.data = 1
    value_changed(values.alarm_type)
    value_changed(values.alarm_level)
    assert (device.extra_state_attributes[lock.ATTR_LOCK_STATUS] ==
            "Manually Locked by Key Cylinder or Inside thumb turn")

    values.alarm_type.data = 18
    values.alarm_level.data = "alice"
    value_changed(values.alarm_type)
    value_changed(values.alarm_level)
    assert (device.extra_state_attributes[lock.ATTR_LOCK_STATUS] ==
            "Locked with Keypad by user alice")

    values.alarm_type.data = 161
    values.alarm_level.data = 1
    value_changed(values.alarm_type)
    value_changed(values.alarm_level)
    assert (device.extra_state_attributes[lock.ATTR_LOCK_STATUS] ==
            "Tamper Alarm: Too many keypresses")
Exemplo n.º 2
0
def test_lock_alarm_type(mock_openzwave):
    """Test alarm type for Z-Wave lock."""
    node = MockNode()
    values = MockEntityValues(
        primary=MockValue(data=None, node=node),
        access_control=None,
        alarm_type=MockValue(data=None, node=node),
        alarm_level=None,
    )
    device = lock.get_device(node=node, values=values, node_config={})

    assert lock.ATTR_LOCK_STATUS not in device.extra_state_attributes

    values.alarm_type.data = 21
    value_changed(values.alarm_type)
    assert (device.extra_state_attributes[lock.ATTR_LOCK_STATUS] ==
            "Manually Locked None")

    values.alarm_type.data = 18
    value_changed(values.alarm_type)
    assert (device.extra_state_attributes[lock.ATTR_LOCK_STATUS] ==
            "Locked with Keypad by user None")

    values.alarm_type.data = 161
    value_changed(values.alarm_type)
    assert device.extra_state_attributes[
        lock.ATTR_LOCK_STATUS] == "Tamper Alarm: None"

    values.alarm_type.data = 9
    value_changed(values.alarm_type)
    assert device.extra_state_attributes[
        lock.ATTR_LOCK_STATUS] == "Deadbolt Jammed"
Exemplo n.º 3
0
def test_get_device_detects_lock(mock_openzwave):
    """Test get_device returns a Z-Wave lock."""
    node = MockNode()
    values = MockEntityValues(
        primary=MockValue(data=None, node=node),
        access_control=None,
        alarm_type=None,
        alarm_level=None,
    )

    device = lock.get_device(node=node, values=values, node_config={})
    assert isinstance(device, lock.ZwaveLock)
Exemplo n.º 4
0
def test_lock_access_control(mock_openzwave):
    """Test access control for Z-Wave lock."""
    node = MockNode()
    values = MockEntityValues(
        primary=MockValue(data=None, node=node),
        access_control=MockValue(data=11, node=node),
        alarm_type=None,
        alarm_level=None,
    )
    device = lock.get_device(node=node, values=values, node_config={})

    assert device.extra_state_attributes[
        lock.ATTR_NOTIFICATION] == "Lock Jammed"
Exemplo n.º 5
0
def test_lock_state_workaround(mock_openzwave):
    """Test value changed for Z-Wave lock using notification state."""
    node = MockNode(manufacturer_id="0090", product_id="0440")
    values = MockEntityValues(
        primary=MockValue(data=True, node=node),
        access_control=MockValue(data=1, node=node),
        alarm_type=None,
        alarm_level=None,
    )
    device = lock.get_device(node=node, values=values)
    assert device.is_locked
    values.access_control.data = 2
    value_changed(values.access_control)
    assert not device.is_locked
Exemplo n.º 6
0
def test_lock_value_changed(mock_openzwave):
    """Test value changed for Z-Wave lock."""
    node = MockNode()
    values = MockEntityValues(
        primary=MockValue(data=None, node=node),
        access_control=None,
        alarm_type=None,
        alarm_level=None,
    )
    device = lock.get_device(node=node, values=values, node_config={})

    assert not device.is_locked

    values.primary.data = True
    value_changed(values.primary)

    assert device.is_locked
Exemplo n.º 7
0
def test_track_message_workaround(mock_openzwave):
    """Test value changed for Z-Wave lock by alarm-clearing workaround."""
    node = MockNode(
        manufacturer_id="003B",
        product_id="5044",
        stats={"lastReceivedMessage": [0] * 6},
    )
    values = MockEntityValues(
        primary=MockValue(data=True, node=node),
        access_control=None,
        alarm_type=None,
        alarm_level=None,
    )

    # Here we simulate an RF lock. The first lock.get_device will call
    # update properties, simulating the first DoorLock report. We then trigger
    # a change, simulating the openzwave automatic refreshing behavior (which
    # is enabled for at least the lock that needs this workaround)
    node.stats["lastReceivedMessage"][5] = const.COMMAND_CLASS_DOOR_LOCK
    device = lock.get_device(node=node, values=values)
    value_changed(values.primary)
    assert device.is_locked
    assert device.extra_state_attributes[lock.ATTR_NOTIFICATION] == "RF Lock"

    # Simulate a keypad unlock. We trigger a value_changed() which simulates
    # the Alarm notification received from the lock. Then, we trigger
    # value_changed() to simulate the automatic refreshing behavior.
    values.access_control = MockValue(data=6, node=node)
    values.alarm_type = MockValue(data=19, node=node)
    values.alarm_level = MockValue(data=3, node=node)
    node.stats["lastReceivedMessage"][5] = const.COMMAND_CLASS_ALARM
    value_changed(values.access_control)
    node.stats["lastReceivedMessage"][5] = const.COMMAND_CLASS_DOOR_LOCK
    values.primary.data = False
    value_changed(values.primary)
    assert not device.is_locked
    assert (device.extra_state_attributes[lock.ATTR_LOCK_STATUS] ==
            "Unlocked with Keypad by user 3")

    # Again, simulate an RF lock.
    device.lock()
    node.stats["lastReceivedMessage"][5] = const.COMMAND_CLASS_DOOR_LOCK
    value_changed(values.primary)
    assert device.is_locked
    assert device.extra_state_attributes[lock.ATTR_NOTIFICATION] == "RF Lock"
Exemplo n.º 8
0
def test_lock_turn_on_and_off(mock_openzwave):
    """Test turning on a Z-Wave lock."""
    node = MockNode()
    values = MockEntityValues(
        primary=MockValue(data=None, node=node),
        access_control=None,
        alarm_type=None,
        alarm_level=None,
    )
    device = lock.get_device(node=node, values=values, node_config={})

    assert not values.primary.data

    device.lock()
    assert values.primary.data

    device.unlock()
    assert not values.primary.data
Exemplo n.º 9
0
def test_v2btze_value_changed(mock_openzwave):
    """Test value changed for v2btze Z-Wave lock."""
    node = MockNode(manufacturer_id="010e", product_id="0002")
    values = MockEntityValues(
        primary=MockValue(data=None, node=node),
        v2btze_advanced=MockValue(data="Advanced", node=node),
        access_control=MockValue(data=19, node=node),
        alarm_type=None,
        alarm_level=None,
    )
    device = lock.get_device(node=node, values=values, node_config={})
    assert device._v2btze

    assert not device.is_locked

    values.access_control.data = 24
    value_changed(values.primary)

    assert device.is_locked
Exemplo n.º 10
0
def test_alarm_type_workaround(mock_openzwave):
    """Test value changed for Z-Wave lock using alarm type."""
    node = MockNode(manufacturer_id="0109", product_id="0000")
    values = MockEntityValues(
        primary=MockValue(data=True, node=node),
        access_control=None,
        alarm_type=MockValue(data=16, node=node),
        alarm_level=None,
    )
    device = lock.get_device(node=node, values=values)
    assert not device.is_locked

    values.alarm_type.data = 18
    value_changed(values.alarm_type)
    assert device.is_locked

    values.alarm_type.data = 19
    value_changed(values.alarm_type)
    assert not device.is_locked

    values.alarm_type.data = 21
    value_changed(values.alarm_type)
    assert device.is_locked

    values.alarm_type.data = 22
    value_changed(values.alarm_type)
    assert not device.is_locked

    values.alarm_type.data = 24
    value_changed(values.alarm_type)
    assert device.is_locked

    values.alarm_type.data = 25
    value_changed(values.alarm_type)
    assert not device.is_locked

    values.alarm_type.data = 27
    value_changed(values.alarm_type)
    assert device.is_locked