Skip to content

Commit

Permalink
Boost score for product_id match to 101%
Browse files Browse the repository at this point in the history
A product id match signals a perfect match, but at 100% it does not
appear any better than dps that happen to match.

Also do not require all non-optional keys to match when the product id
is already matched. A partial match is still likely to be the correct
device. Only discard the match if there are mismatches in the dps
types.

PR #2773
  • Loading branch information
make-all committed Jan 13, 2025
1 parent 6a8abe1 commit 23fa0fe
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions custom_components/tuya_local/helpers/device_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def _get_required_dps(self):
required_dps_list = [d for d in self._get_all_dps() if not d.optional]
return required_dps_list

def _entity_match_analyse(self, entity, keys, matched, dps):
def _entity_match_analyse(self, entity, keys, matched, dps, product_match):
"""
Determine whether this entity can be a match for the dps
Args:
Expand All @@ -208,7 +208,7 @@ def _entity_match_analyse(self, entity, keys, matched, dps):
"""
all_dp = keys + matched
for d in entity.dps():
if (d.id not in all_dp and not d.optional) or (
if (d.id not in all_dp and not d.optional and not product_match) or (
d.id in all_dp and not _typematch(d.type, dps[d.id])
):
return False
Expand All @@ -223,7 +223,7 @@ def match_quality(self, dps, product_ids=None):
if product_ids:
for p in self._config.get("products", []):
if p.get("id", "MISSING_ID!?!") in product_ids:
product_match = 100
product_match = 101

keys = list(dps.keys())
matched = []
Expand All @@ -234,7 +234,7 @@ def match_quality(self, dps, product_ids=None):
return product_match

for e in self.all_entities():
if not self._entity_match_analyse(e, keys, matched, dps):
if not self._entity_match_analyse(e, keys, matched, dps, product_match > 0):
return 0

return product_match or round((total - len(keys)) * 100 / total)
Expand Down

0 comments on commit 23fa0fe

Please sign in to comment.