Skip to content

fix: get_last_feeding returns most recent FEED_DONE regardless of API order - #29

Open
jadenv wants to merge 1 commit into
ThomasHFWright:masterfrom
jadenv:fix/get-last-feeding-ordering
Open

fix: get_last_feeding returns most recent FEED_DONE regardless of API order#29
jadenv wants to merge 1 commit into
ThomasHFWright:masterfrom
jadenv:fix/get-last-feeding-ordering

Conversation

@jadenv

@jadenv jadenv commented Apr 28, 2026

Copy link
Copy Markdown

Problem

get_last_feeding() stopped returning the correct feeding after the PetSafe API changed the ordering of messages returned by GET /smart-feed/feeders/{id}/messages?days=N.

Previously the API returned messages newest-first, so iterating and returning the first FEED_DONE match was correct. In the last week or so, it seems API silently changed to returning messages oldest-first, causing get_last_feeding() to return a stale feeding from days ago instead of the most recent one.

Example API response (current ordering — oldest first)

[
  {"message_type": "FEED_DONE", "created_at": "2025-04-20T08:00:00Z", "payload": {"time": 1745136000, "amount": 1}},
  {"message_type": "FEED_DONE", "created_at": "2025-04-20T12:00:00Z", "payload": {"time": 1745150400, "amount": 1}},
  {"message_type": "FEED_DONE", "created_at": "2025-04-20T17:00:00Z", "payload": {"time": 1745168400, "amount": 2}}
]

With the old implementation the first FEED_DONE found (8:00 AM) was returned instead of the most recent one (5:00 PM).

Fix

Instead of returning the first FEED_DONE in iteration order, filter to all valid FEED_DONE entries and return the one with the highest payload.time Unix timestamp — making the result correct regardless of what order the API returns messages in the future.

@jadenv

jadenv commented Jun 1, 2026

Copy link
Copy Markdown
Author

@ThomasHFWright Any chance we could get this merged soon? Thanks!

@IAmTheMitchell

Copy link
Copy Markdown

I opened (and closed) a duplicate PR before I saw this. My fix was the same.

Would really appreciate if we could get this merged in!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants