fix: get_last_feeding returns most recent FEED_DONE regardless of API order - #29
Open
jadenv wants to merge 1 commit into
Open
fix: get_last_feeding returns most recent FEED_DONE regardless of API order#29jadenv wants to merge 1 commit into
jadenv wants to merge 1 commit into
Conversation
Author
|
@ThomasHFWright Any chance we could get this merged soon? Thanks! |
|
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! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
get_last_feeding()stopped returning the correct feeding after the PetSafe API changed the ordering of messages returned byGET /smart-feed/feeders/{id}/messages?days=N.Previously the API returned messages newest-first, so iterating and returning the first
FEED_DONEmatch was correct. In the last week or so, it seems API silently changed to returning messages oldest-first, causingget_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_DONEfound (8:00 AM) was returned instead of the most recent one (5:00 PM).Fix
Instead of returning the first
FEED_DONEin iteration order, filter to all validFEED_DONEentries and return the one with the highestpayload.timeUnix timestamp — making the result correct regardless of what order the API returns messages in the future.