mrp: handle NaN elapsed time when calculating position - #2897
Open
seidnerj wants to merge 1 commit into
Open
Conversation
Devices sometimes report NaN for the elapsedTime and elapsedTimeTimestamp
metadata fields. Both are doubles in the protobuf definition, so int()
raises ValueError ("cannot convert float NaN to integer") and playing()
fails entirely. NaN is truthy, so the existing "or 0" fallback does not
help. Return None instead, which is what total_time already does for a
NaN duration.
Also correct the elapsed_time annotation from int to float, matching the
type the protobuf definition actually specifies.
seidnerj
added a commit
to seidnerj/homebridge-appletv-enhanced
that referenced
this pull request
Jul 28, 2026
pyatv 0.18.0 raises "ValueError: cannot convert float NaN to integer" from mrp.position() when a device reports NaN as elapsed time. node-pyatv rethrows it and the orphaned rejection in startUp kills the child bridge. Pin pyatv to the fork carrying the fix until it is released upstream (postlund/pyatv#2897).
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
playing()raisesValueError: cannot convert float NaN to integerwhen a devicereports NaN as elapsed time, which makes the whole call fail:
Seen in the wild via
atvscript(as used by node-pyatv/homebridge-appletv-enhanced),where the raised error terminates the process.
Cause
elapsedTimeandelapsedTimeTimestampare bothdoubleinContentItemMetadata.proto(lines 150 and 189), and devices do occasionally report NaN for them.
position()annotated
elapsed_timeasintand relied on... or 0as a fallback, but NaN istruthy, so it goes straight into
int()and raises.total_time()right above alreadyguards its (also
double)durationfield withmath.isnan;position()never got thesame treatment.
Change
Nonefromposition()whenelapsedTimeorelapsedTimeTimestampis NaN,consistent with what
total_time()does for a NaNduration. A NaN timestamp wouldotherwise raise the same
ValueErrorfromdatetime.fromtimestamp()inside_cocoa_to_timestamp().elapsed_timeannotation frominttofloat, matching the type theprotobuf definition actually specifies.
Tests
Added
test_metadata_position_nan, which fails on master with the traceback above andpasses with this change. Full test suite and chickn linting pass locally.