for notification_id in current_notifications:
            notification = current_notifications[notification_id]
            if APPS and notification.app_id not in APPS:
                continue
            all_ids.append(notification_id)

        # For now, use _raw_date even though we should use a parsed version of the date.
        # pylint: disable=protected-access
        all_ids.sort(key=lambda x: current_notifications[x]._raw_date)

        if current_notification and current_notification.removed:
            # Stop showing the latest and show that there are no new notifications.
            current_notification = None

        if not current_notification and not all_ids:
            group[0] = NotificationFree(width, height)
        elif all_ids:
            now = time.monotonic()
            if (current_notification and current_notification.id in all_ids
                    and now - last_press < DELAY_AFTER_PRESS):
                index = all_ids.index(current_notification.id)
            else:
                index = len(all_ids) - 1
            if now - last_press >= DEBOUNCE:
                if b.value and index > 0:
                    last_press = now
                    index += -1
                if a.value and index < len(all_ids) - 1:
                    last_press = now
                    index += 1
            # pylint: disable=protected-access
            # Ignore notifications older than the currently shown one.
            if (latest_notification and
                    notification._raw_date < latest_notification._raw_date):
                continue
            new_notification = notification
            break

        if new_notification:
            print(new_notification)
            latest_notification = new_notification
            screen_updated = False
            display.show(
                apple.create_notification_widget(latest_notification,
                                                 display.width,
                                                 display.height))
        elif latest_notification and latest_notification.removed:
            # Stop showing the latest and show that there are no new notifications.
            latest_notification = None
            screen_updated = False
            display.show(NotificationFree(display.width, display.height))

        # Do not refresh the screen more often than every 180 seconds for eInk displays! Rapid
        # refreshes will damage the panel.
        if not screen_updated and display.time_to_refresh == 0:
            display.refresh()
            screen_updated = True

    active_connection = None
    notification_service = None