From 23fa0fe067925ce2d2bc8eec5d4483638e72b017 Mon Sep 17 00:00:00 2001 From: Jason Rumney Date: Mon, 13 Jan 2025 22:37:59 +0900 Subject: [PATCH] Boost score for product_id match to 101% 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 --- custom_components/tuya_local/helpers/device_config.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/custom_components/tuya_local/helpers/device_config.py b/custom_components/tuya_local/helpers/device_config.py index f3fb467ace..5e2f7b6a7e 100644 --- a/custom_components/tuya_local/helpers/device_config.py +++ b/custom_components/tuya_local/helpers/device_config.py @@ -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: @@ -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 @@ -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 = [] @@ -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)