From 16ae6802a818a406be40a5a10005c776844badd3 Mon Sep 17 00:00:00 2001 From: firstof9 Date: Thu, 15 Jul 2021 14:55:57 -0700 Subject: [PATCH 1/4] fix: better fix for #488 --- .../mail_and_packages/helpers.py | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/custom_components/mail_and_packages/helpers.py b/custom_components/mail_and_packages/helpers.py index 035baa12..c17fe9db 100644 --- a/custom_components/mail_and_packages/helpers.py +++ b/custom_components/mail_and_packages/helpers.py @@ -745,6 +745,7 @@ def get_count( result = {} today = get_formatted_date() track = None + found = [] # Return Amazon delivered info if sensor_type == const.AMAZON_DELIVERED: @@ -788,17 +789,19 @@ def get_count( data[0], count, ) - - if ( - const.ATTR_PATTERN - in const.SENSOR_DATA[f"{sensor_type.split('_')[0]}_tracking"].keys() - ): - track = const.SENSOR_DATA[f"{sensor_type.split('_')[0]}_tracking"][ - const.ATTR_PATTERN - ][0] - - if track is not None and get_tracking_num and count > 0: - tracking = get_tracking(data[0], account, track) + found.append(data[0]) + + if ( + const.ATTR_PATTERN + in const.SENSOR_DATA[f"{sensor_type.split('_')[0]}_tracking"].keys() + ): + track = const.SENSOR_DATA[f"{sensor_type.split('_')[0]}_tracking"][ + const.ATTR_PATTERN + ][0] + + if track is not None and get_tracking_num and count > 0: + for sdata in found: + tracking = get_tracking(sdata, account, track) if len(tracking) > 0: # Use tracking numbers found for count (more accurate) From 01c5fe3de689c5ac0228ee9b15ac99ae85760f0f Mon Sep 17 00:00:00 2001 From: firstof9 Date: Thu, 15 Jul 2021 15:05:16 -0700 Subject: [PATCH 2/4] extend the tracking numbers list --- custom_components/mail_and_packages/helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/mail_and_packages/helpers.py b/custom_components/mail_and_packages/helpers.py index c17fe9db..694f060e 100644 --- a/custom_components/mail_and_packages/helpers.py +++ b/custom_components/mail_and_packages/helpers.py @@ -801,7 +801,7 @@ def get_count( if track is not None and get_tracking_num and count > 0: for sdata in found: - tracking = get_tracking(sdata, account, track) + tracking.extend(get_tracking(sdata, account, track)) if len(tracking) > 0: # Use tracking numbers found for count (more accurate) From 8bd98b6d16f7cdf3d07ef8a35c7e08cfe1c35b23 Mon Sep 17 00:00:00 2001 From: firstof9 Date: Thu, 15 Jul 2021 15:20:59 -0700 Subject: [PATCH 3/4] make sure not to count the tracking numbers twice --- custom_components/mail_and_packages/helpers.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/custom_components/mail_and_packages/helpers.py b/custom_components/mail_and_packages/helpers.py index 694f060e..2ceaa6d0 100644 --- a/custom_components/mail_and_packages/helpers.py +++ b/custom_components/mail_and_packages/helpers.py @@ -801,7 +801,9 @@ def get_count( if track is not None and get_tracking_num and count > 0: for sdata in found: - tracking.extend(get_tracking(sdata, account, track)) + num = get_tracking(sdata, account, track) + if not any(e in tracking for e in num): + tracking.extend(num) if len(tracking) > 0: # Use tracking numbers found for count (more accurate) From 16a33ab59d7ec5d15d4370d0a36a42fbd02195d8 Mon Sep 17 00:00:00 2001 From: firstof9 Date: Thu, 15 Jul 2021 15:28:22 -0700 Subject: [PATCH 4/4] condense code --- custom_components/mail_and_packages/helpers.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/custom_components/mail_and_packages/helpers.py b/custom_components/mail_and_packages/helpers.py index 2ceaa6d0..49bd6212 100644 --- a/custom_components/mail_and_packages/helpers.py +++ b/custom_components/mail_and_packages/helpers.py @@ -801,9 +801,8 @@ def get_count( if track is not None and get_tracking_num and count > 0: for sdata in found: - num = get_tracking(sdata, account, track) - if not any(e in tracking for e in num): - tracking.extend(num) + tracking.extend(get_tracking(sdata, account, track)) + tracking = list(dict.fromkeys(tracking)) if len(tracking) > 0: # Use tracking numbers found for count (more accurate)