Skip to content

fix: wire up nightlight brightness/toggle for Sprout Humidifier (LEH-B381S)#528

Merged
webdjoe merged 3 commits into
webdjoe:devfrom
rakeshpyboina:fix/sprout-nightlight-brightness
Jul 12, 2026
Merged

fix: wire up nightlight brightness/toggle for Sprout Humidifier (LEH-B381S)#528
webdjoe merged 3 commits into
webdjoe:devfrom
rakeshpyboina:fix/sprout-nightlight-brightness

Conversation

@rakeshpyboina

Copy link
Copy Markdown
Contributor

Summary

The LEH-B381S (Sprout Humidifier) already declares NIGHTLIGHT / NIGHTLIGHT_BRIGHTNESS support in device_map.py, and VeSyncSproutHumid already had a working private _set_nightlight_state helper that builds the correct setLightStatus payload. However, the class never overrode the base class's set_nightlight_brightness / toggle_nightlight methods, so any caller (e.g. Home Assistant's select/switch entities) fell through to the base-class stub, which just logs Nightlight brightness has not been configured. and returns False instead of calling the API.

Traceback this was pulled from (Home Assistant, via select.async_select_option):

File ".../vesync/select.py", line 194, in async_select_option
ERROR [pyvesync.base_devices.humidifier_base] Nightlight brightness has not been configured.
  • Added set_nightlight_brightness and toggle_nightlight overrides to VeSyncSproutHumid, wired to the existing _set_nightlight_state helper (mirroring the pattern used in VeSyncHumid200300S/VeSyncHumid1000S).
  • Fixed a latent bug in _set_nightlight_state: it unconditionally stored the passed-in brightness (including None) as the new state, and would send "brightness": null to the API when toggling the light before a brightness had ever been read or set. It now falls back to the last known brightness, or 100 if none is known yet.

Test plan

  • Added turn_on_nightlight, turn_off_nightlight, and set_nightlight_brightness test cases for LEH-B381S in test_humidifiers.py
  • Recorded new API fixtures in src/tests/api/vesynchumidifier/LEH-B381S.yaml
  • pytest src/tests/ — 355 passed, 3 skipped
  • mypy src/pyvesync/devices/vesynchumidifier.py — no issues
  • Validated against a physical LEH-B381S device (reporter has the device; will confirm in this thread)

🤖 Generated with Claude Code

…B381S)

VeSyncSproutHumid already had a working _set_nightlight_state helper
that builds the correct setLightStatus payload, but never overrode the
base class's set_nightlight_brightness/toggle_nightlight stubs. As a
result, any caller (e.g. Home Assistant's select/switch entities) hit
the base class fallback, which logs "Nightlight brightness has not
been configured" and returns False instead of calling the API.

Also fixes a latent bug in _set_nightlight_state: it unconditionally
stored the passed-in brightness (including None) as the new state,
and would send "brightness": null to the API when toggling the light
before a brightness had ever been read or set. It now falls back to
the last known brightness, or 100 if none is known yet.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@rakeshpyboina

Copy link
Copy Markdown
Contributor Author

Validated against my physical LEH-B381S (Sprout Humidifier) and VeSync account. All three methods work correctly end-to-end:

```
Before: nightlight_status=on, nightlight_brightness=51

--- turn_on_nightlight() ---
success=True, status=on, brightness=51

--- set_nightlight_brightness(30) ---
success=True, status=on, brightness=30

--- turn_off_nightlight() ---
success=True, status=off, brightness=30
```

Confirmed each state change matched what happened on the physical device/Levoit app.

@webdjoe
webdjoe merged commit 58eee3b into webdjoe:dev Jul 12, 2026
6 checks passed
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