From 96ba1d238d29272e0fa1ec5a78b82198ce0468a9 Mon Sep 17 00:00:00 2001 From: prudy Date: Tue, 25 Jun 2024 17:35:59 +0200 Subject: [PATCH] Ecoharmonogram: Gather cumulative entries, no duplicates. (#2188) Co-authored-by: prudy --- .../source/ecoharmonogram_pl.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/ecoharmonogram_pl.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/ecoharmonogram_pl.py index 40a83c6d6..b9647ddb1 100644 --- a/custom_components/waste_collection_schedule/waste_collection_schedule/source/ecoharmonogram_pl.py +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/ecoharmonogram_pl.py @@ -127,6 +127,12 @@ def fetch(self): entries.extend(self._create_entries(sp, town)) return entries + def _entry_exists(self, dmy, name, entries: [Collection]): + for e in entries: + if dmy == e.date and name == e.type: + return True + return False + def _create_entries(self, sp, town): streets = Ecoharmonogram.fetch_streets( sp, town, self.street_input, self.house_number_input @@ -157,18 +163,17 @@ def _create_entries(self, sp, town): z["name"] = get.get("name") schedules.append(z) - entries = [] for sch in schedules: days = sch.get("days").split(";") month = sch.get("month") year = sch.get("year") for d in days: - entries.append( - Collection( - datetime.date(int(year), int(month), int(d)), - sch.get("name"), + dmy = datetime.date(int(year), int(month), int(d)) + name = sch.get("name") + if not self._entry_exists(dmy, name, entries): + entries.append( + Collection(dmy, name) ) - ) if self.additional_sides_matcher_input != "": return entries return entries