Repository navigation
fix: purifier light detection and display guards used the wrong state - #551
ryan-ronnander wants to merge 1 commit into
Conversation
f5fba49 to
31b1340
Compare
|
@webdjoe could you take a look at this when you get a chance? home-assistant/core#183015 (light detection switch and dark room sensor for the Vital 200S) is blocked on it. I've updated the description to the new PR template, including a direct pyvesync test on the device that the new contribution rules ask for. Once this is in a release, I can request a pyvesync version bump in HA core as its own PR and take #183015 out of draft. Thanks. |
- toggle_light_detection compared the requested state against light_detection_status (the dark/lit sensor reading) instead of light_detection_switch (the feature toggle), so enabling it in a dark room or disabling it in a lit room returned early without calling the API. - toggle_display refused whenever the room was dark, on every model. The Vital 200S accepts setDisplay with light detection on, so the guard now applies only to the Vital 100S (the 11017000 report in webdjoe#351) and checks light_detection_switch. - Add tests for both guards. - Verified on a Levoit Vital 200S (LAP-V201S-WUS).
31b1340 to
4996643
Compare
|
Looking back on #351, it should not have been merged. This library cannot guard against all conditions, it just add unnecessary logic that needs to be maintained for situations like this. I think the best solution is to remove the condition entirely and leave it up to the user to know when it's appropriate to make the request. |
Why
This started with the display switch in Home Assistant failing on my Vital 200S, while the VeSync app changed the same setting without complaint:
Follow-up to #351. The two guards it added check
light_detection_status(whether the room is dark right now) where they meanlight_detection_switch(whether the feature is enabled). On a Levoit Vital 200S (LAP-V201S-WUS), that makes light detection and the display unreliable to control through pyvesync, and so through Home Assistant too. I'm preparing a Home Assistant VeSync change that adds a light detection switch and a dark room sensor for these purifiers. With the current guards, that switch silently does nothing when turned on in a dark room, and the existing display switch fails whenever the room is dark.toggle_light_detectioncheckedlight_detection_status(whether the room is dark right now) where it meantlight_detection_switch(whether the feature is enabled). Turning light detection on in a dark room, or off in a lit room, returnedTruewithout calling the API.toggle_displayrefused wheneverlight_detection_statuswas on, which is the same wrong field. As a result the display switch in HA failed with "Cannot set display when light detection is enabled" depending on how bright the room was.Fix
toggle_light_detectioncompares againstlight_detection_switch.toggle_displaynow applies only to the Vital 100S (LAP-V102S), and checkslight_detection_switch. The Vital 200S acceptssetDisplaywith light detection enabled, and the VeSync app lets you change both settings at any time. The display setting is the master: with light detection on, the device only darkens a display that is set to on while the room is dark.I kept the guard for the Vital 100S because #351 reported
11017000 BYPASS_NOT_SUPPORTEDthere, and I don't own a 100S to check. If someone with a 100S finds that it accepts the call, the guard can go.Only
VeSyncAirBaseV2changes (Vital 100S/200S, Everest Air, Sprout). The Core series and the other purifier classes are untouched.Real-hardware verification
LAP-V201S-WUS(Vital 200S)1.0.16____A script called this branch's methods directly through pyvesync (Python 3.13), not through Home Assistant, with the purifier running and the room lit. Each call returned code 0, and each change was confirmed by a later
update().light_detection_switchondisplay_set_statusoffdisplay_set_statusonlight_detection_switchoffTests
TestAirBaseV2Guardsintest_purifiers.py:Type of change
fix:)feat:)docs:)Checklist
DeviceState; models inmodels/; constants inpyvesync.const).ruff check,pylint,mypy, andpytestpass locally.pytest --write_api) where relevant.Checked on this branch merged onto current
dev. mypy reports the two errors invesyncthermostat.pythatdevalready has; this PR doesn't touch that file. No docs describe these guards, and no new API calls were added, so there are no new fixtures.