Skip to content

fix(ha): round home_status brightness readback to nearest percent#596

Merged
matedev01 merged 3 commits into
GeniePod:mainfrom
e11734937-beep:fix/home-status-brightness-readback-rounding
Jul 6, 2026
Merged

fix(ha): round home_status brightness readback to nearest percent#596
matedev01 merged 3 commits into
GeniePod:mainfrom
e11734937-beep:fix/home-status-brightness-readback-rounding

Conversation

@e11734937-beep

Copy link
Copy Markdown
Contributor

What

home_status reports a light's brightness one percent too low. summarize_state formats it with integer value * 100 / 255, which truncates toward zero, while the write path (normalize_brightness) rounds a percent onto the 0-255 scale. The two directions disagree, and so does Home Assistant's own brightness_pct (which rounds):

user sets stored (0-255) old readback correct
75% 191 74% 75%
99% 252 98% 99%
15% 38 14% 15%

Fix

Round the readback to the nearest percent so home_status matches both the write path and HA. Blast radius is the single brightness-format expression — no other caller or domain is touched.

Real Behavior Proof

  • Added regression test brightness_readback_rounds_to_nearest_percent. Fail-before: expected rounded 75%, got: Living room lamp is on, brightness 74%. Pass-after: green.
  • cargo fmt --check clean
  • cargo clippy --all-targets -- -D warnings clean
  • cargo test full suite: 0 failed (lib 807 passed / 4 ignored)

`summarize_state` reports a light's brightness with integer
`value * 100 / 255`, which truncates toward zero. The write path
(`normalize_brightness`) rounds when mapping a percent onto the 0-255
scale, so the two directions disagree: a light set to 75% is stored as
191/255 and read back as "74%"; 99% (stored 252) reads back as "98%";
15% (stored 38) as "14%". Home Assistant's own brightness_pct rounds,
so the spoken status also disagreed with the HA UI.

Round the readback to the nearest percent so home_status matches both
the write path and HA. Blast radius is the single brightness-format
expression; no other caller or domain is touched.

## Real Behavior Proof
- [x] Added regression test `brightness_readback_rounds_to_nearest_percent`;
      fail-before printed `got: Living room lamp is on, brightness 74%` for a
      75% light, pass-after is green.
- [x] `cargo fmt --check` clean
- [x] `cargo clippy --all-targets -- -D warnings` clean
- [x] `cargo test` full suite: 0 failed (lib 807 passed / 4 ignored)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions github-actions Bot added the bug Something isn't working label Jul 3, 2026
@e11734937-beep

Copy link
Copy Markdown
Contributor Author

Hi @matedev01 — flagging #596 in case it slipped the queue. It has been green across all checks and mergeable, and I just rebased it onto latest main so it is current. It is a small home_status brightness readback-rounding fix. Happy to adjust anything if useful — thanks for maintaining genie-claw!

@matedev01 matedev01 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM — correct fix (.round() matches both HA's brightness_pct and normalize_brightness), regression test covers 191->75%, 252->99%, 255->100% boundary. HA 35/35, BFCL 96%.

@matedev01 matedev01 merged commit 0512cb6 into GeniePod:main Jul 6, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants