Skip to content

Honor target_range in number min/max; fix Frizzlife LP365P volume scaling#5324

Closed
nalditopr wants to merge 3 commits into
make-all:mainfrom
nalditopr:fix-number-target-range
Closed

Honor target_range in number min/max; fix Frizzlife LP365P volume scaling#5324
nalditopr wants to merge 3 commits into
make-all:mainfrom
nalditopr:fix-number-target-range

Conversation

@nalditopr

@nalditopr nalditopr commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Fixes #5323

What

  1. DpsConfig.range() now honors target_range. A number's
    native_min_value/native_max_value come from range(), which applied
    scale but ignored target_range, so numbers with a target_range remap
    exposed their bounds in raw dps units. That made sliders show raw units
    (e.g. a 0.01–0.1 min-flow showing 0–9) and rejected values outside the raw
    range before the target_range conversion could run. range() now returns
    the target_range bounds when configured (guarded by scaled; the write
    path reads the raw range from config directly, so it is unaffected).

  2. Frizzlife LP365P "Allowed flow volume" fixed (scale + writability).
    The firmware offset-encodes this value: gallons = raw*20 + 20
    (raw 0–6420–1300 gal). The old mapping used scale: 0.01 plus a
    {dps_val: 0, value: 50} special case, which mis-read (~900 for a real
    200 gal). It also routed the value through value_redirect
    (mode4/5/6 → modeN_val), which does not apply the leaf target_range
    on write — so sets never reached the device. Replaced with a direct
    target_range mapping on the value DP.

Verified on a live LP365P (protocol 3.5)

  • Min-flow slider bounds correct (0.01–0.1). ✅
  • Allowed-flow-volume reads correctly, matching the Smart Life app
    (raw 0/7/9/64 ⇄ 20/160/200/1300 gal). ✅
  • Allowed-flow-volume writes correctly from HA — set 200 gal → dp115
    raw 9, confirmed by direct device read. ✅ (Through value_redirect the
    same set left dp115 unchanged; direct binding fixes it.)

Note on multi-mode

The direct mapping tracks the Mode 4 register (dp115). The previous
value_redirect form auto-followed the active advanced mode but was
non-writable for this offset encoding. If preserving auto-follow is
preferred, the value_redirect write path would need to apply the
redirected dp's target_range (it currently honors scale but not
target_range); happy to take it that direction instead.

DpsConfig.range() applied scale but ignored target_range, so a number
entity whose displayed value comes from a target_range remap reported its
min/max in raw dps units. The slider then shows raw units, and values
outside the raw range are rejected by core before the target_range write
conversion runs. Return the target_range bounds when one is configured.
The allowed flow volume is offset-encoded by the firmware
(gallons = raw * 20 + 20, raw 0-64 <-> 20-1300 gal). The previous mapping
used scale 0.01 with a raw-0 -> 50 special case, which mis-read (about 900
for a real 200 gal) and could not be written. Use a target_range remap
with the correct 20-1300 gal range.
@nalditopr

Copy link
Copy Markdown
Contributor Author

Root cause of the volume write failure isolated on a live LP365P: it is the value_redirect write path, not a read-only DP. With the value modeled via value_redirect (mode4/5/6 -> modeN_val) a set does not reach the device. Re-modeling the same DP (115) as the entity's direct value with the identical target_range makes the write land correctly (set 200 gal -> dp115 raw 9, verified by direct device read). So the leaf target_range is honored on direct reads/writes but lost when reached through value_redirect on write. Options: (a) fix the value_redirect write path to apply the redirected dp's target_range, or (b) model these per-mode values directly. Happy to adjust this PR whichever way you prefer.

…rect)

Routing the volume value through value_redirect (mode4/5/6 -> modeN_val)
does not apply the leaf target_range on write, so sets never reached the
device (verified: redirect write left dp115 unchanged, direct write of the
same value lands correctly). Bind the value directly to dp115 with the
target_range remap so it reads and writes in gallons. This tracks the
Mode 4 register; auto-following the active advanced mode would require the
value_redirect write path to apply the redirected dp's target_range.
- dps_val: us_units
value: gal
- value: L
- id: 111

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

The problem with simplifying this is it will now only work in one mode.

Did you try putting the target_range in each mapping here where it will be picked up by the logic to report the min and max to HA, as well as on the target dp of the value_redirect to use when calculating actual changes?

@github-project-automation github-project-automation Bot moved this from 👀 In review to 🏗 Stalled in Tuya Local Jun 18, 2026
@make-all make-all added the awaiting feedback Needs more information label Jun 20, 2026
@nalditopr nalditopr closed this Jun 26, 2026
@github-project-automation github-project-automation Bot moved this from 🏗 Stalled to ✅ Done in Tuya Local Jun 26, 2026
make-all added a commit that referenced this pull request Jun 27, 2026
When range is called for determining the HA side range, we should use target_range
instead when available.

PR #5324 by @nalditopr
make-all added a commit that referenced this pull request Jun 27, 2026
@make-all make-all removed the awaiting feedback Needs more information label Jun 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Number entities ignore target_range for min/max (wrong slider bounds; values un-writable)

2 participants