Skip to content

fix: call detect_bulb() in *_percentage() methods before reading value_max#714

Open
jasonacox-sam wants to merge 1 commit into
jasonacox:masterfrom
jasonacox-sam:fix/brightness-percentage-before-detect
Open

fix: call detect_bulb() in *_percentage() methods before reading value_max#714
jasonacox-sam wants to merge 1 commit into
jasonacox:masterfrom
jasonacox-sam:fix/brightness-percentage-before-detect

Conversation

@jasonacox-sam

Copy link
Copy Markdown
Collaborator

Fixes #713

Problem

When set_brightness_percentage(), set_white_percentage(), or set_colourtemp_percentage() is called before bulb detection has run, self.dpset['value_max'] is still -1 (the unconfigured default). The computed raw value is wrong, which causes the < 0 fallback in set_brightness() to fire and pin the device to full brightness regardless of the requested percentage.

Fix

Add a if not self.bulb_configured: self.detect_bulb(nowait=nowait) guard at the top of each _percentage() method, before the value_max multiplication. This mirrors the guard already present in set_brightness(), set_white(), and other lower-level methods.

Affected Methods

  • set_brightness_percentage()
  • set_white_percentage()
  • set_colourtemp_percentage()

Testing

Workaround confirmed by @andreidiaconescu18 in #713 — calling d.status() first (which triggers detect_bulb()) makes set_brightness_percentage(75) work correctly. This PR makes that detection automatic.

— Sam ⚙️

…thods

When set_brightness_percentage(), set_white_percentage(), or
set_colourtemp_percentage() is called before bulb detection has run,
self.dpset['value_max'] is still -1 (the unconfigured default). The
computed raw value is then wrong — always -1 — which triggers the
fallback in set_brightness() and pins the device to full brightness
regardless of the requested percentage.

Fix: call detect_bulb() if bulb_configured is False before computing
the raw value from value_max. This mirrors the guard already present
in set_brightness(), set_white(), and other lower-level methods.

Fixes jasonacox#713
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.

set_brightness_percentage() - not working properly

1 participant