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))
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))
def test__sync_lock_activity_unlocked(): """Test _sync_lock_activity unlocking.""" lock = _mocked_august_component_lock() lock_activity_timestamp = 1234 lock_activity = MockActivity( action=ACTION_LOCK_UNLOCK, 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(lock_activity_timestamp))
def test__sync_door_activity_doorclosed(): """Test _sync_door_activity doorclosed.""" data = MockAugustData(last_door_state_update_timestamp=1) door = MockAugustDoorBinarySensor(august_data=data) 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))
def test__sync_door_activity_doored_via_dooropen(): """Test _sync_door_activity dooropen.""" data = MockAugustData(last_door_state_update_timestamp=1) door = MockAugustDoorBinarySensor(august_data=data) door_activity_start_timestamp = 1234 door_activity = MockActivity( action=ACTION_DOOR_OPEN, activity_start_timestamp=door_activity_start_timestamp, activity_end_timestamp=5678, ) 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(door_activity_start_timestamp))
def test__sync_lock_activity_locked_via_lock(): """Test _sync_lock_activity locking.""" data = MockAugustData(last_lock_status_update_timestamp=1) lock = MockAugustLock(august_data=data) lock_activity_start_timestamp = 1234 lock_activity = MockActivity( action=ACTION_LOCK_LOCK, activity_start_timestamp=lock_activity_start_timestamp, activity_end_timestamp=5678, ) lock._sync_lock_activity(lock_activity) assert lock.last_update_lock_status["lock_status"] == LockStatus.LOCKED assert lock.last_update_lock_status["activity_start_time_utc"] == dt.as_utc( datetime.datetime.fromtimestamp(lock_activity_start_timestamp) )
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))