Skip to content

fix(mqtt): support both 'st/did' and 'status/feature' keys#83

Merged
eman merged 3 commits into
evalfrom
fix/flexible-response-keys
May 8, 2026
Merged

fix(mqtt): support both 'st/did' and 'status/feature' keys#83
eman merged 3 commits into
evalfrom
fix/flexible-response-keys

Conversation

@eman
Copy link
Copy Markdown
Owner

@eman eman commented May 8, 2026

Some Navien devices respond with 'st' and 'did' keys instead of the full 'status' and 'feature' names used in the library's Pydantic models. This PR adds support for both to ensure compatibility with all hardware versions.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the MQTT subscriptions message parsing to accept multiple key variants used by different Navien device protocol versions, so DeviceStatus / DeviceFeature parsing continues to work across hardware/firmware variants.

Changes:

  • Added alternate key support when extracting parsed payloads from MQTT response messages (e.g., status vs st, feature vs did).

Comment thread src/nwp500/mqtt/subscriptions.py Outdated
Comment thread src/nwp500/mqtt/subscriptions.py Outdated
…cedence

- Add get_response_data() helper to mqtt/utils.py that checks nested
  response dict before top-level, and primary key before alt key:
  res[key] → res[alt_key] → message[key] → message[alt_key]
- Use helper in _make_handler() fixing the fallback order (previously
  message[key] was checked before res[alt_key])
- Use same helper in CLI raw_cb path so 'st'/'did' alt keys are
  supported there too, consistent with the typed handler path
- Fix missing return None in EnergyUsageResponse.get_month_data
- Fix mypy no-any-return in MqttConnection.unsubscribe/publish
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comment thread src/nwp500/mqtt/utils.py
Comment thread src/nwp500/cli/handlers.py
Replace or-chain with explicit key-presence checks using a sentinel
object, so falsy values (0, False, {}) are returned correctly and do
not fall through to a lower-precedence candidate.

Also add unit tests for the raw=True CLI path with 'st'/'did' alt keys
and the standard 'status'/'feature' keys.
@eman eman merged commit ea02ba9 into eval May 8, 2026
@eman eman deleted the fix/flexible-response-keys branch May 8, 2026 01:50
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