Beispiel #1
0
def test__sync_lock_activity_ignores_old_data():
    """Test _sync_lock_activity unlocking."""
    data = MockAugustComponentData(last_lock_status_update_timestamp=1)
    august_lock = _mock_august_lock()
    data.set_mocked_locks([august_lock])
    lock = MockAugustComponentLock(data, august_lock)
    first_lock_activity_timestamp = 1234
    lock_activity = MockActivity(
        action=ACTION_LOCK_UNLOCK,
        activity_start_timestamp=first_lock_activity_timestamp,
        activity_end_timestamp=first_lock_activity_timestamp,
    )
    lock._sync_lock_activity(lock_activity)
    assert lock.last_update_lock_status["lock_status"] == LockStatus.UNLOCKED
    assert lock.last_update_lock_status[
        "activity_start_time_utc"] == dt.as_utc(
            datetime.datetime.fromtimestamp(first_lock_activity_timestamp))

    # Now we do the update with an older start time to
    # make sure it ignored
    data.set_last_lock_status_update_time_utc(
        august_lock.device_id,
        dt.as_utc(datetime.datetime.fromtimestamp(1000)))
    lock_activity_timestamp = 2
    lock_activity = MockActivity(
        action=ACTION_LOCK_LOCK,
        activity_start_timestamp=lock_activity_timestamp,
        activity_end_timestamp=lock_activity_timestamp,
    )
    lock._sync_lock_activity(lock_activity)
    assert lock.last_update_lock_status["lock_status"] == LockStatus.UNLOCKED
    assert lock.last_update_lock_status[
        "activity_start_time_utc"] == dt.as_utc(
            datetime.datetime.fromtimestamp(first_lock_activity_timestamp))
Beispiel #2
0
def test__sync_door_activity_ignores_old_data():
    """Test _sync_door_activity dooropen then expired doorclosed."""
    data = MockAugustComponentData(last_door_state_update_timestamp=1)
    lock = _mock_august_lock()
    data.set_mocked_locks([lock])
    door = MockAugustComponentDoorBinarySensor(data, "door_open", lock)
    first_door_activity_timestamp = 1234
    door_activity = MockActivity(
        action=ACTION_DOOR_OPEN,
        activity_start_timestamp=first_door_activity_timestamp,
        activity_end_timestamp=first_door_activity_timestamp,
    )
    door._sync_door_activity(door_activity)
    assert door.last_update_door_state["door_state"] == LockDoorStatus.OPEN
    assert door.last_update_door_state["activity_start_time_utc"] == dt.as_utc(
        datetime.datetime.fromtimestamp(first_door_activity_timestamp))

    # Now we do the update with an older start time to
    # make sure it ignored
    data.set_last_door_state_update_time_utc(
        lock.device_id, dt.as_utc(datetime.datetime.fromtimestamp(1000)))
    door_activity_timestamp = 2
    door_activity = MockActivity(
        action=ACTION_DOOR_CLOSED,
        activity_start_timestamp=door_activity_timestamp,
        activity_end_timestamp=door_activity_timestamp,
    )
    door._sync_door_activity(door_activity)
    assert door.last_update_door_state["door_state"] == LockDoorStatus.OPEN
    assert door.last_update_door_state["activity_start_time_utc"] == dt.as_utc(
        datetime.datetime.fromtimestamp(first_door_activity_timestamp))
Beispiel #3
0
def test_lock_throws_august_api_http_error():
    """Test lock."""
    data = MockAugustComponentData(api=MockAugustApiFailing())
    lock = _mock_august_lock()
    data.set_mocked_locks([lock])
    last_err = None
    try:
        data.unlock("mocklockid1")
    except HomeAssistantError as err:
        last_err = err
    assert (
        str(last_err)
        == "mocklockid1 Name: This should bubble up as its user consumable"
    )
Beispiel #4
0
def test__sync_door_activity_doorclosed():
    """Test _sync_door_activity doorclosed."""
    data = MockAugustComponentData(last_door_state_update_timestamp=1)
    lock = _mock_august_lock()
    data.set_mocked_locks([lock])
    door = MockAugustComponentDoorBinarySensor(data, "door_open", lock)
    door_activity_timestamp = 1234
    door_activity = MockActivity(
        action=ACTION_DOOR_CLOSED,
        activity_start_timestamp=door_activity_timestamp,
        activity_end_timestamp=door_activity_timestamp,
    )
    door._sync_door_activity(door_activity)
    assert door.last_update_door_state["door_state"] == LockDoorStatus.CLOSED
    assert door.last_update_door_state["activity_start_time_utc"] == dt.as_utc(
        datetime.datetime.fromtimestamp(door_activity_timestamp))
Beispiel #5
0
def _create_august_data_with_lock_details(lock_details):
    locks = []
    for lock in lock_details:
        if isinstance(lock, LockDetail):
            locks.append(_mock_august_lock(lock.device_id))
    authentication = _mock_august_authentication("original_token", 1234)
    authenticator = _mock_august_authenticator()
    token_refresh_lock = MagicMock()
    api = MagicMock()
    api.get_lock_status = MagicMock(return_value=(MagicMock(), MagicMock()))
    api.get_lock_detail = MagicMock(side_effect=lock_details)
    api.get_operable_locks = MagicMock(return_value=locks)
    api.get_doorbells = MagicMock(return_value=[])
    return august.AugustData(
        MagicMock(), api, authentication, authenticator, token_refresh_lock
    )
Beispiel #6
0
def _mocked_august_component_lock():
    data = MockAugustComponentData(last_lock_status_update_timestamp=1)
    august_lock = _mock_august_lock()
    data.set_mocked_locks([august_lock])
    return MockAugustComponentLock(data, august_lock)
Beispiel #7
0
 def __init__(self, august_data=None):
     """Init the mock for august component AugustLock class."""
     self._data = august_data
     self._door = _mock_august_lock()
Beispiel #8
0
def test_get_lock_name():
    """Get the lock name from August data."""
    data = MockAugustComponentData(last_lock_status_update_timestamp=1)
    lock = _mock_august_lock()
    data.set_mocked_locks([lock])
    assert data.get_lock_name("mocklockid1") == "mocklockid1 Name"