Skip to content

Commit

Permalink
New Source: Joondalup, Australia (#3312)
Browse files Browse the repository at this point in the history
* initial commit

* corrections

* GUI descriptions added

* .md added

* updates

* filename typo

* rename file

* tidy-up

* typos, update_docu_links

* reformatting md + adding one typehint

---------

Co-authored-by: 5ila5 <5ila5@users.noreply.github.com>
  • Loading branch information
dt215git and 5ila5 authored Dec 28, 2024
1 parent 9959c92 commit 41a1fcb
Show file tree
Hide file tree
Showing 8 changed files with 319 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ If your service provider is not listed, feel free to open a [source request issu
- [City of Cockburn](/doc/source/cockburn_wa_gov_au.md) / cockburn.wa.gov.au
- [City of Darebin](/doc/source/darebin_vic_gov_au.md) / darebin.vic.gov.au
- [City of Greater Geelong](/doc/source/geelongaustralia_com_au.md) / geelongaustralia.com.au
- [City of Joondalup](/doc/source/joondalup_wa_gov_au.md) / joondalup.wa.gov.au
- [City of Kingston](/doc/source/kingston_vic_gov_au.md) / kingston.vic.gov.au
- [City of Mitcham](/doc/source/app_my_local_services_au.md) / mitchamcouncil.sa.gov.au
- [City of Mount Gambier](/doc/source/app_my_local_services_au.md) / mountgambier.sa.gov.au
Expand Down
6 changes: 6 additions & 0 deletions custom_components/waste_collection_schedule/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@
"default_params": {},
"id": "geelongaustralia_com_au"
},
{
"title": "City of Joondalup",
"module": "joondalup_wa_gov_au",
"default_params": {},
"id": "joondalup_wa_gov_au"
},
{
"title": "City of Kingston",
"module": "kingston_vic_gov_au",
Expand Down
26 changes: 26 additions & 0 deletions custom_components/waste_collection_schedule/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,32 @@
},
"data_description": {}
},
"args_joondalup_wa_gov_au": {
"title": "Quelle konfigurieren",
"description": "Konfiguriere deinen Service Provider. \n\nYour house number, street name, and suburb as they appear when searching for your collection schedule on the Joonalup website: https://www.joondalup.wa.gov.au/residents/waste-and-recycling/residential-bin-collections. Alternatively, you can use your mapkey, if you know it.\n\nMehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/joondalup_wa_gov_au.md",
"data": {
"calendar_title": "Kalender Titel",
"mapkey": "Mapkey",
"number": "Nummer",
"street": "Straße",
"suburb": "Suburb"
},
"data_description": {
"calendar_title": "Ein lesbarerer oder benutzerfreundlicherer Name für den Müllkalender. Wenn nichts angegeben wird, wird der Name der Quelle verwendet."
}
},
"reconfigure_joondalup_wa_gov_au": {
"title": "Quelle Neu Konfigurieren",
"description": "Konfiguriere deinen Service Provider. \n\nYour house number, street name, and suburb as they appear when searching for your collection schedule on the Joonalup website: https://www.joondalup.wa.gov.au/residents/waste-and-recycling/residential-bin-collections. Alternatively, you can use your mapkey, if you know it.\n\nMehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/joondalup_wa_gov_au.md",
"data": {
"calendar_title": "Kalender Titel",
"mapkey": "Mapkey",
"number": "Nummer",
"street": "Straße",
"suburb": "Suburb"
},
"data_description": {}
},
"args_kingston_vic_gov_au": {
"title": "Quelle konfigurieren",
"description": "Konfiguriere deinen Service Provider. Mehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/kingston_vic_gov_au.md",
Expand Down
35 changes: 35 additions & 0 deletions custom_components/waste_collection_schedule/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,41 @@
},
"data_description": {}
},
"args_joondalup_wa_gov_au": {
"title": "Configure Source",
"description": "Configure your service provider. \n\nYour house number, street name, and suburb as they appear when searching for your collection schedule on the Joonalup website: https://www.joondalup.wa.gov.au/residents/waste-and-recycling/residential-bin-collections. Alternatively, you can use your mapkey, if you know it.\n\nMore details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/joondalup_wa_gov_au.md.",
"data": {
"calendar_title": "Calendar Title",
"mapkey": "The unique identifier for your property used by the Joonalup website",
"number": "Your house number as it appears on the Joonalup website",
"street": "Your stree name as it appears on the Joonalup website",
"suburb": "Your suburb as it appears on the Joonalup website"
},
"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.",
"mapkey": "The unique identifier for your property used by the Joonalup website",
"number": "Your house number as it appears on the Joonalup website",
"street": "Your stree name as it appears on the Joonalup website",
"suburb": "Your suburb as it appears on the Joonalup website"
}
},
"reconfigure_joondalup_wa_gov_au": {
"title": "Reconfigure Source",
"description": "Configure your service provider. \n\nYour house number, street name, and suburb as they appear when searching for your collection schedule on the Joonalup website: https://www.joondalup.wa.gov.au/residents/waste-and-recycling/residential-bin-collections. Alternatively, you can use your mapkey, if you know it.\n\nMore details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/joondalup_wa_gov_au.md.",
"data": {
"calendar_title": "Calendar Title",
"mapkey": "The unique identifier for your property used by the Joonalup website",
"number": "Your house number as it appears on the Joonalup website",
"street": "Your stree name as it appears on the Joonalup website",
"suburb": "Your suburb as it appears on the Joonalup website"
},
"data_description": {
"mapkey": "The unique identifier for your property used by the Joonalup website",
"number": "Your house number as it appears on the Joonalup website",
"street": "Your stree name as it appears on the Joonalup website",
"suburb": "Your suburb as it appears on the Joonalup website"
}
},
"args_kingston_vic_gov_au": {
"title": "Configure Source",
"description": "Configure your service provider. More details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/kingston_vic_gov_au.md.",
Expand Down
26 changes: 26 additions & 0 deletions custom_components/waste_collection_schedule/translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,32 @@
},
"data_description": {}
},
"args_joondalup_wa_gov_au": {
"title": "Configurazione Sorgente",
"description": "Compila i campi per ottenere le informazioni sul tuo servizio di raccolta. \n\nYour house number, street name, and suburb as they appear when searching for your collection schedule on the Joonalup website: https://www.joondalup.wa.gov.au/residents/waste-and-recycling/residential-bin-collections. Alternatively, you can use your mapkey, if you know it.\n\nMaggiori informazioni: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/joondalup_wa_gov_au.md.",
"data": {
"calendar_title": "Nome Calendario",
"mapkey": "Mapkey",
"number": "Numero",
"street": "Strada",
"suburb": "Suburb"
},
"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."
}
},
"reconfigure_joondalup_wa_gov_au": {
"title": "Riconfigurazione Sorgente",
"description": "Compila i campi per ottenere le informazioni sul tuo servizio di raccolta. \n\nYour house number, street name, and suburb as they appear when searching for your collection schedule on the Joonalup website: https://www.joondalup.wa.gov.au/residents/waste-and-recycling/residential-bin-collections. Alternatively, you can use your mapkey, if you know it.\n\nPer maggiori informazioni: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/joondalup_wa_gov_au.md.",
"data": {
"calendar_title": "Nome Calendario",
"mapkey": "Mapkey",
"number": "Numero",
"street": "Strada",
"suburb": "Suburb"
},
"data_description": {}
},
"args_kingston_vic_gov_au": {
"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/kingston_vic_gov_au.md.",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import json
from datetime import date, datetime, timedelta

import requests
from dateutil.rrule import FR, MO, SA, SU, TH, TU, WE, WEEKLY, rrule
from requests.utils import requote_uri
from waste_collection_schedule import Collection # type: ignore[attr-defined]

TITLE = "City of Joondalup"
DESCRIPTION = "Source for City of Joondalup (WA) waste collection."
URL = "https://www.joondalup.wa.gov.au"
TEST_CASES = {
"test address": {
"number": "2",
"street": "Ashburton Drive",
"suburb": "Heathridge",
},
"test mapkey": {
"mapkey": 785,
},
}
HEADERS: dict = {
"user-agent": "Mozilla/5.0",
"accept": "application/json, text/plain, */*",
}
DAYS: dict = {
"MONDAY": MO,
"TUESDAY": TU,
"WEDNESDAY": WE,
"THURSDAY": TH,
"FRIDAY": FR,
"SATURDAY": SA,
"SUNDAY": SU,
}
ICON_MAP: dict = {
"Recycling": "mdi:recycle",
"Bulk Put Out": "mdi:tree",
"Bulk Pick Up": "mdi:tree",
"General Waste": "mdi:trash-can",
"Green Waste": "mdi:leaf",
}

HOW_TO_GET_ARGUMENTS_DESCRIPTION = { # Optional dictionary to describe how to get the arguments, will be shown in the GUI configuration form above the input fields, does not need to be translated in all languages
"en": "Your house number, street name, and suburb as they appear when searching for your collection schedule on the Joonalup website: https://www.joondalup.wa.gov.au/residents/waste-and-recycling/residential-bin-collections. Alternatively, you can use your mapkey, if you know it.",
}

PARAM_DESCRIPTIONS = { # Optional dict to describe the arguments, will be shown in the GUI configuration below the respective input field
"en": {
"number": "Your house number as it appears on the Joonalup website",
"street": "Your stree name as it appears on the Joonalup website",
"suburb": "Your suburb as it appears on the Joonalup website",
"mapkey": "The unique identifier for your property used by the Joonalup website",
},
}

PARAM_TRANSLATIONS = { # Optional dict to translate the arguments, will be shown in the GUI configuration form as placeholder text
"en": {
"number": "Your house number as it appears on the Joonalup website",
"street": "Your stree name as it appears on the Joonalup website",
"suburb": "Your suburb as it appears on the Joonalup website",
"mapkey": "The unique identifier for your property used by the Joonalup website",
},
}

# _LOGGER = logging.getLogger(__name__)


class Source:
def __init__(
self,
number=None,
street=None,
suburb=None,
mapkey=None,
):
if mapkey is None:
self._number = str(number)
self._street = str(street)
self._suburb = str(suburb).upper()
self._mapkey = None
else:
self._number = None
self._street = None
self._suburb = None
self._mapkey = str(mapkey)

def format_date(self, s: str) -> date:
dt = datetime.strptime(s, "%A %d/%m/%Y").date()
return dt

def generate_general_waste_date(self, s: datetime, d: int) -> date:
rr = rrule(WEEKLY, dtstart=s, byweekday=d)
dt = rr.after(s)
return dt.date()

def generate_recycle_dates(self, s: str) -> tuple:
d: date = self.format_date(s)
dt1: date = d + timedelta(days=-7)
dt2: date = d + timedelta(days=7)
return dt1, dt2

def fetch(self) -> list[Collection]:
start_date = datetime.now() + timedelta(days=-1)

s = requests.Session()

if self._mapkey is None:
# use address details to find the mapkey
search_term = requote_uri(f"{self._street} {self._suburb}")
r = s.get(
f"https://www.joondalup.wa.gov.au/aapi/coj/propertylookup/{search_term}",
headers=HEADERS,
)
properties = json.loads(r.content)
for property in properties:
if str(property["house_no"]) == self._number:
self._mapkey = property["mapkey"]

# use the mapkey to get the schedule
r = s.get(
f"https://www.joondalup.wa.gov.au/aapi/coj/bindatelookup/{self._mapkey}",
headers=HEADERS,
)
pickups = json.loads(r.content)[0]

# some waste types just state the collection day and frequency
# so generate dates for those
general = self.generate_general_waste_date(
start_date, DAYS[pickups["Rubbish_Day"].upper().strip()]
)
recycle1, recycle2 = self.generate_recycle_dates(pickups["Next_Recycling_Date"])

schedule: dict = {
"Recycling": self.format_date(pickups["Next_Recycling_Date"]),
"Bulk Put Out": self.format_date(pickups["Bulk_Rubbish_Put_Out"]),
"Bulk Pick Up": self.format_date(pickups["Bulk_Rubbish_Pick_Up"]),
"General Waste": general,
"Green Waste": recycle1,
"Green Waste ": recycle2, # note the whitespace character to distinguish between keys
}

entries = []

for item in schedule:
entries.append(
Collection(
date=schedule[item],
t=item.strip(),
icon=ICON_MAP.get(item.strip()),
)
)

return entries
71 changes: 71 additions & 0 deletions doc/source/joondalup_wa_gov_au.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# City of Joondalup

Support for schedules provided by [City of Joonalup](https://www.joondalup.wa.gov.au/residents/waste-and-recycling/residential-bin-collections).

## Configuration via configuration.yaml

```yaml
waste_collection_schedule:
sources:
- name: joondalup_wa_gov_au
args:
number: NUMBER
street: STREET
suburb: SUBURB
mapkey: MAPKEY
```
### Configuration Variables
**number**
*(string) (optional)*
Your house number as it appears on the Joondalup website.
**street**
*(string) (optional)*
Your street name as it appears on the Joondalup website.
**suburb**
*(string) (optional)*
Your suburb as it appears on the Joondalup website.
**mapkey**
*(string) (optional)*
The unique identifier for your property used by the Joondalup website.
## Example
Your must provide either:
- the number, street and suburb, or
- the mapkey
The following examples are equivalent
```yaml
waste_collection_schedule:
sources:
- name: joondalup_wa_gov_au
args:
number: "2"
street: "Ashburton Drive"
suburb: "Heathridge"
```
```yaml
waste_collection_schedule:
sources:
- name: joondalup_wa_gov_au
args:
mapkey: "785"
```
## How to find your mapkey, if you want to use it
Search for your collection schedule on the Joondalup website. Wait for the schedule to load and the property image to be displayed. Right-click on the property image and _copy image address_. Examine the copied url, your mapkey is shown at the end of the url.
Loading

0 comments on commit 41a1fcb

Please sign in to comment.