Skip to content

fix(c-api): declare the battery status values hsc_get_battery() returns - #601

Merged
Sapd merged 1 commit into
Sapd:masterfrom
ChrisLauinger77:fix/c-api-battery-status
Oct 22, 2026
Merged

Sapd merged 1 commit into
Sapd:masterfrom
ChrisLauinger77:fix/c-api-battery-status

Conversation

@ChrisLauinger77

Copy link
Copy Markdown
Contributor

Changes made

hsc_get_battery() casts the C++ battery_status straight into hsc_battery_status_t, but headsetcontrol_c.h declared the legacy values (-1/-2/0/-100/-101) while the library hands out 0-4:

Library returns Header said
0 (unavailable) HSC_BATTERY_AVAILABLE
1 (charging) no constant
2 (available) no constant

So the C sample in LIBRARY_USAGE.md never saw HSC_BATTERY_CHARGING, and the Python sample's BatteryStatus(battery.status) raised ValueError for an ordinary available battery.

  • Declare the values the library has always returned instead of translating them. Existing binaries, including ones that worked around the mismatch with the raw numbers, see no change; code using the named constants starts working.
  • static_asserts keep the C and C++ enums in step.
  • The Python sample's BatteryStatus uses the real values.
  • The library API test now checks the status for an available and a charging battery (test profile 2).

Checklist

  • I adjusted the README (if needed)
  • For new features in HeadsetControl: I discussed it beforehand in Issues or Discussions and adhered to the wiki Not applicable: this is a fix and adds no new capability.

@github-actions github-actions Bot added the awaiting-maintainer The author replied or pushed - our move label Oct 22, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-22T15:36:50.445922Z a77b66e PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

hsc_get_battery() casts the C++ battery_status straight into
hsc_battery_status_t, but the header declared the legacy values
(-1/-2/0/-100/-101) while the library hands out 0-4. A charging headset
reported 1, which matches no constant, and an unavailable one reported 0,
which the header calls HSC_BATTERY_AVAILABLE. The C sample in
LIBRARY_USAGE.md never saw HSC_BATTERY_CHARGING, and the Python sample's
BatteryStatus(battery.status) raised for an ordinary available battery.

Declare the values the library has always returned instead of translating
them, so existing binaries, including ones that worked around the mismatch
with the raw numbers, see no change, while code using the named constants
starts working. static_asserts keep the two enums in step, and the library
API test now checks the status for an available and a charging battery.
@ChrisLauinger77
ChrisLauinger77 force-pushed the fix/c-api-battery-status branch 2 times, most recently from a77b66e to e5c2bce Compare October 22, 2026 15:36
@Sapd
Sapd merged commit 9a9ca48 into Sapd:master Oct 22, 2026
7 checks passed
@github-actions github-actions Bot removed the awaiting-maintainer The author replied or pushed - our move label Oct 22, 2026
@ChrisLauinger77
ChrisLauinger77 deleted the fix/c-api-battery-status branch October 22, 2026 19:40
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