Skip to content

util: look up the integer range by string key, not the range builtin#5384

Merged
make-all merged 1 commit into
make-all:mainfrom
HrachShah:fix/representation-int-range-key
Jun 22, 2026
Merged

util: look up the integer range by string key, not the range builtin#5384
make-all merged 1 commit into
make-all:mainfrom
HrachShah:fix/representation-int-range-key

Conversation

@HrachShah

Copy link
Copy Markdown
Contributor

Summary

  • util/common_funcs.py: representation() looked up the integer range by passing the built-in range function as a key. The config dict is loaded from YAML, so the actual key is the string "range" — the lookup always returned None and a sample DP value of 0 was used regardless of the configured min. The CLI utilities duplicates and match_against (which use make_sample_dps) silently produced wrong sample values, and a real device match could be turned into a false negative if the duplicate detection was matching against a range: {min: 40, max: 70} config.
  • The fix uses the string key "range" and guards against a non-dict / missing min before subscripting, so the function returns the configured minimum when present and falls back to 0 otherwise.

Verification

  • Wrote a standalone script that constructed fake DPs with and without range config. Before the fix, both returned 0. After the fix, the DP with range.min: 5 returns 5 and the DP without a range returns 0.

representation() called dp._config.get(range) when building a sample
DPS value for an integer datapoint. The dict comes from YAML, so all
keys are strings; passing the built-in range() function as a key meant
the lookup always returned None and the configured min was ignored,
falling back to 0 for every int DP. Read the 'range' string key instead,
and guard against a non-dict or missing 'min' before subscripting.

This matters for the CLI utilities (duplicates, match_against) that
consume make_sample_dps: a device with range.min: 40 was producing a
sample of 0, which can fail _typematch against configs that require
values in [40, 70] and turn a real-match case into a false negative.
@make-all

Copy link
Copy Markdown
Owner

I don't think there are any real consequences of this, as none of the current utilities or matching function check whether sample values are in range or not, and the other conditions checked for here are config errors, so it is better that the exception is thrown to alert to an invalid config. I think the quotes around range are correct, but the rest of the defensive programming changes are not adding value.

@make-all
make-all merged commit acaabe3 into make-all:main Jun 22, 2026
4 checks passed
@github-project-automation github-project-automation Bot moved this from 👀 In review to ✅ Done in Tuya Local Jun 22, 2026
make-all added a commit that referenced this pull request Jun 22, 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.

2 participants