diff --git a/custom_components/waste_collection_schedule/translations/de.json b/custom_components/waste_collection_schedule/translations/de.json index 140850868..4bdc9d582 100644 --- a/custom_components/waste_collection_schedule/translations/de.json +++ b/custom_components/waste_collection_schedule/translations/de.json @@ -10942,25 +10942,30 @@ }, "args_adur_worthing_gov_uk": { "title": "Quelle konfigurieren", - "description": "Konfiguriere deinen Service Provider. Mehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/adur_worthing_gov_uk.md", + "description": "Konfiguriere deinen Service Provider. \n\nAn easy way to discover your Unique Property Reference Number (UPRN) is by going to https://www.findmyaddress.co.uk/ and entering in your address details\n\nMehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/adur_worthing_gov_uk.md", "data": { "calendar_title": "Kalender Titel", "address": "Addresse", - "postcode": "PLZ" + "postcode": "PLZ", + "uprn": "UPRN" }, "data_description": { - "calendar_title": "Ein lesbarerer oder benutzerfreundlicherer Name für den Müllkalender. Wenn nichts angegeben wird, wird der Name der Quelle verwendet." + "calendar_title": "Ein lesbarerer oder benutzerfreundlicherer Name für den Müllkalender. Wenn nichts angegeben wird, wird der Name der Quelle verwendet.", + "uprn": "Eine einfache Möglichkeit, Ihre Unique Property Reference Number (UPRN) zu finden, besteht darin, auf https://www.findmyaddress.co.uk/ zu gehen und Ihre Adressdaten einzugeben." } }, "reconfigure_adur_worthing_gov_uk": { "title": "Quelle Neu Konfigurieren", - "description": "Konfiguriere deinen Service Provider. Mehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/adur_worthing_gov_uk.md", + "description": "Konfiguriere deinen Service Provider. \n\nAn easy way to discover your Unique Property Reference Number (UPRN) is by going to https://www.findmyaddress.co.uk/ and entering in your address details\n\nMehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/adur_worthing_gov_uk.md", "data": { "calendar_title": "Kalender Titel", "address": "Addresse", - "postcode": "PLZ" + "postcode": "PLZ", + "uprn": "UPRN" }, - "data_description": {} + "data_description": { + "uprn": "Eine einfache Möglichkeit, Ihre Unique Property Reference Number (UPRN) zu finden, besteht darin, auf https://www.findmyaddress.co.uk/ zu gehen und Ihre Adressdaten einzugeben." + } }, "args_allerdale_gov_uk": { "title": "Quelle konfigurieren", diff --git a/custom_components/waste_collection_schedule/translations/en.json b/custom_components/waste_collection_schedule/translations/en.json index 4b3b7d5bc..1bb60dd62 100644 --- a/custom_components/waste_collection_schedule/translations/en.json +++ b/custom_components/waste_collection_schedule/translations/en.json @@ -10945,25 +10945,30 @@ }, "args_adur_worthing_gov_uk": { "title": "Configure Source", - "description": "Configure your service provider. More details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/adur_worthing_gov_uk.md.", + "description": "Configure your service provider. \n\nAn easy way to discover your Unique Property Reference Number (UPRN) is by going to https://www.findmyaddress.co.uk/ and entering in your address details\n\nMore details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/adur_worthing_gov_uk.md.", "data": { "calendar_title": "Calendar Title", "address": "Address", - "postcode": "Postcode" + "postcode": "Postcode", + "uprn": "Unique Property Reference Number (UPRN)" }, "data_description": { - "calendar_title": "A more readable, or user-friendly, name for the waste calendar. If nothing is provided, the name returned by the source will be used." + "calendar_title": "A more readable, or user-friendly, name for the waste calendar. If nothing is provided, the name returned by the source will be used.", + "uprn": "An easy way to discover your Unique Property Reference Number (UPRN) is by going to https://www.findmyaddress.co.uk/ and entering in your address details" } }, "reconfigure_adur_worthing_gov_uk": { "title": "Reconfigure Source", - "description": "Configure your service provider. More details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/adur_worthing_gov_uk.md.", + "description": "Configure your service provider. \n\nAn easy way to discover your Unique Property Reference Number (UPRN) is by going to https://www.findmyaddress.co.uk/ and entering in your address details\n\nMore details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/adur_worthing_gov_uk.md.", "data": { "calendar_title": "Calendar Title", "address": "Address", - "postcode": "Postcode" + "postcode": "Postcode", + "uprn": "Unique Property Reference Number (UPRN)" }, - "data_description": {} + "data_description": { + "uprn": "An easy way to discover your Unique Property Reference Number (UPRN) is by going to https://www.findmyaddress.co.uk/ and entering in your address details" + } }, "args_allerdale_gov_uk": { "title": "Configure Source", diff --git a/custom_components/waste_collection_schedule/translations/it.json b/custom_components/waste_collection_schedule/translations/it.json index 8a96b0f39..de4c04a02 100644 --- a/custom_components/waste_collection_schedule/translations/it.json +++ b/custom_components/waste_collection_schedule/translations/it.json @@ -10931,25 +10931,30 @@ }, "args_adur_worthing_gov_uk": { "title": "Configurazione Sorgente", - "description": "Compila i campi per ottenere le informazioni sul tuo servizio di raccolta. Maggiori informazioni: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/adur_worthing_gov_uk.md.", + "description": "Compila i campi per ottenere le informazioni sul tuo servizio di raccolta. \n\nAn easy way to discover your Unique Property Reference Number (UPRN) is by going to https://www.findmyaddress.co.uk/ and entering in your address details\n\nMaggiori informazioni: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/adur_worthing_gov_uk.md.", "data": { "calendar_title": "Nome Calendario", "address": "Address", - "postcode": "Codice Postale CAP" + "postcode": "Codice Postale CAP", + "uprn": "UPRN" }, "data_description": { - "calendar_title": "Puoi cambiare il nome del calendario della raccolta dei rifiuti, altrimenti di default verra' utilizzato il nome del tuo fornitore di servizi." + "calendar_title": "Puoi cambiare il nome del calendario della raccolta dei rifiuti, altrimenti di default verra' utilizzato il nome del tuo fornitore di servizi.", + "uprn": "Un modo facile per scoprire il tuo Numero di Riferimento Proprietà Unica (UPRN) è andare su https://www.findmyaddress.co.uk/ e inserire i dettagli del tuo indirizzo." } }, "reconfigure_adur_worthing_gov_uk": { "title": "Riconfigurazione Sorgente", - "description": "Compila i campi per ottenere le informazioni sul tuo servizio di raccolta. Per maggiori informazioni: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/adur_worthing_gov_uk.md.", + "description": "Compila i campi per ottenere le informazioni sul tuo servizio di raccolta. \n\nAn easy way to discover your Unique Property Reference Number (UPRN) is by going to https://www.findmyaddress.co.uk/ and entering in your address details\n\nPer maggiori informazioni: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/adur_worthing_gov_uk.md.", "data": { "calendar_title": "Nome Calendario", "address": "Address", - "postcode": "Codice Postale CAP" + "postcode": "Codice Postale CAP", + "uprn": "UPRN" }, - "data_description": {} + "data_description": { + "uprn": "Un modo facile per scoprire il tuo Numero di Riferimento Proprietà Unica (UPRN) è andare su https://www.findmyaddress.co.uk/ e inserire i dettagli del tuo indirizzo." + } }, "args_allerdale_gov_uk": { "title": "Configurazione Sorgente", diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/adur_worthing_gov_uk.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/adur_worthing_gov_uk.py index 8db7046e5..c96a3c1f4 100644 --- a/custom_components/waste_collection_schedule/waste_collection_schedule/source/adur_worthing_gov_uk.py +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/adur_worthing_gov_uk.py @@ -14,6 +14,7 @@ TEST_CASES = { "Test_001": {"postcode": "BN15 9UX", "address": "1 Western Road North"}, "Test_002": {"postcode": "BN43 5WE", "address": "6 Hebe Road"}, + "Test_003": {"uprn": "100062209109"}, } HEADERS = { "user-agent": "Mozilla/5.0", @@ -23,47 +24,74 @@ "Refuse": "mdi:trash-can", "Garden": "mdi:leaf", } +HOW_TO_GET_ARGUMENTS_DESCRIPTION = { + "en": "An easy way to discover your Unique Property Reference Number (UPRN) is by going to https://www.findmyaddress.co.uk/ and entering in your address details", +} +PARAM_TRANSLATIONS = { + "en": { + "uprn": "Unique Property Reference Number (UPRN)", + } +} +PARAM_DESCRIPTIONS = { + "en": { + "uprn": "An easy way to discover your Unique Property Reference Number (UPRN) is by going to https://www.findmyaddress.co.uk/ and entering in your address details", + } +} class Source: - def __init__(self, postcode, address): - self._postcode = postcode - self._address = address + def __init__(self, postcode=None, address=None, uprn=None): + if uprn is not None: + self._uprn = uprn + self._postcode = None + self._address = None + else: + self._postcode = postcode + self._address = address + self._uprn = None def fetch(self): - if self._postcode is None or self._address is None: - raise SourceArgumentExceptionMultiple( - ["postcode", "address"], - "either postcode or address needs to be provided but neither was", + s = requests.Session() + + if self._uprn is not None: + r = s.get( + f"https://www.adur-worthing.gov.uk/bin-day/?brlu-selected-address={self._uprn}", + headers=HEADERS, ) + html_collections = r.content + else: + if self._postcode is None or self._address is None: + raise SourceArgumentExceptionMultiple( + ["postcode", "address"], + "either postcode or address needs to be provided but neither was", + ) - s = requests.Session() + postcode_search_request = s.get( + f"https://www.adur-worthing.gov.uk/bin-day/?brlu-address-postcode={self._postcode}&return-url=/bin-day/&action=search", + headers=HEADERS, + ) + html_addresses = postcode_search_request.content + addresses = bs4.BeautifulSoup(html_addresses, "html.parser") + addresses_select = addresses.find("select", {"id": "brlu-selected-address"}) - postcode_search_request = s.get( - f"https://www.adur-worthing.gov.uk/bin-day/?brlu-address-postcode={self._postcode}&return-url=/bin-day/&action=search", - headers=HEADERS, - ) - html_addresses = postcode_search_request.content - addresses = bs4.BeautifulSoup(html_addresses, "html.parser") - addresses_select = addresses.find("select", {"id": "brlu-selected-address"}) + found_address = None + for address in addresses_select.find_all("option"): + if self._address.upper() in address.get_text().upper(): + found_address = address - found_address = None - for address in addresses_select.find_all("option"): - if self._address.upper() in address.get_text().upper(): - found_address = address + if found_address is None: + raise SourceArgumentNotFoundWithSuggestions( + "address", + self._address, + [a.get_text() for a in addresses_select.find_all("option")], + ) - if found_address is None: - raise SourceArgumentNotFoundWithSuggestions( - "address", - self._address, - [a.get_text() for a in addresses_select.find_all("option")], + collections_request = s.get( + f"https://www.adur-worthing.gov.uk/bin-day/?brlu-selected-address={found_address['value']}&return-url=/bin-day/", + headers=HEADERS, ) + html_collections = collections_request.content - collections_request = s.get( - f"https://www.adur-worthing.gov.uk/bin-day/?brlu-selected-address={found_address['value']}&return-url=/bin-day/", - headers=HEADERS, - ) - html_collections = collections_request.content bin_collections = bs4.BeautifulSoup(html_collections, "html.parser") bin_days_table = bin_collections.find("table", class_="bin-days") diff --git a/doc/source/adur_worthing_gov_uk.md b/doc/source/adur_worthing_gov_uk.md index 6215f667c..b847cf6c7 100644 --- a/doc/source/adur_worthing_gov_uk.md +++ b/doc/source/adur_worthing_gov_uk.md @@ -11,14 +11,21 @@ waste_collection_schedule: args: postcode: POSTCODE address: FIRST LINE OF ADDRESS (X, STREET NAME) + uprn: UPRN ``` ### Configuration Variables **postcode** -*(string) (required)* +*(string) (optional)* + **address** -*(string) (required)* +*(string) (optional)* + +**uprn** +*(string | integer) (optional)* + +Supply both `postcode` and `address` args, or just the `uprn` arg ## Example @@ -30,3 +37,15 @@ waste_collection_schedule: postcode: BN15 9UX address: 1 Western Road ``` +```yaml +waste_collection_schedule: + sources: + - name: adur_worthing_gov_uk + args: + uprn: 100062209109 + +``` + +## How to get the uprn argument + +An easy way to discover your Unique Property Reference Number (UPRN) is by going to and entering in your address details. \ No newline at end of file