Skip to content

Comments

Fix: /homekit/accessories returns null when characteristic metadata contains NaN or Infinity#2

Open
DarkStarDS9 wants to merge 1 commit intoopenclaw:mainfrom
DarkStarDS9:fix/nan-infinity-json-encoding
Open

Fix: /homekit/accessories returns null when characteristic metadata contains NaN or Infinity#2
DarkStarDS9 wants to merge 1 commit intoopenclaw:mainfrom
DarkStarDS9:fix/nan-infinity-json-encoding

Conversation

@DarkStarDS9
Copy link

Problem

GET /homekit/accessories silently returns null instead of the expected JSON array, causing casa devices to fail with "The data couldn't be read because it isn't in the correct format."

Root Cause

JSONEncoder throws EncodingError.invalidValue when encoding Double.nan or Double.infinity — both of which can appear in HomeKit characteristic metadata (e.g. minValue, maxValue, stepValue). The encodedData() method used try? which silently swallowed the error and fell back to Data("null".utf8).

Fix

In HomeKitMapper.jsonValue(_:), check for NaN/Infinity before returning .number(...) and map them to .null instead:

let d = number.doubleValue
if d.isNaN || d.isInfinite { return .null }
return .number(d)

Testing

  • GET /homekit/accessories now returns a valid JSON envelope with the full accessories array
  • casa devices works correctly
  • Verified with a real HomeKit setup containing Philips Hue and Tado devices across multiple homes

🤖 Generated with Claude Code

… Infinity

JSONEncoder throws EncodingError.invalidValue for NaN/Infinity doubles, causing
the accessories endpoint to silently return null via try?. Map these to JSON null
instead so /homekit/accessories encodes correctly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@DarkStarDS9 DarkStarDS9 marked this pull request as ready for review February 21, 2026 06:18
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.

1 participant