diff --git a/README.md b/README.md index fbdf2002f..7e35d57a3 100644 --- a/README.md +++ b/README.md @@ -698,6 +698,7 @@ Waste collection schedules in the following formats and countries are supported. - [Ashfield District Council](/doc/source/ashfield_gov_uk.md) / ashfield.gov.uk - [Basildon Council](/doc/source/basildon_gov_uk.md) / basildon.gov.uk - [Basingstoke and Deane Borough Council](/doc/source/basingstoke_gov_uk.md) / basingstoke.gov.uk +- [Bath & North East Somerset Council](/doc/source/bathnes_gov_uk.md) / bathnes.gov.uk - [Bedford Borough Council](/doc/source/bedford_gov_uk.md) / bedford.gov.uk - [Binzone](/doc/source/binzone_uk.md) / southoxon.gov.uk - [Blackburn with Darwen Borough Council](/doc/source/blackburn_gov_uk.md) / blackburn.gov.uk diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/bathnes_gov_uk.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/bathnes_gov_uk.py new file mode 100644 index 000000000..9d6f68aba --- /dev/null +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/bathnes_gov_uk.py @@ -0,0 +1,74 @@ +from datetime import date, datetime +from typing import List + +import requests +from waste_collection_schedule import Collection + +# Include work around for SSL UNSAFE_LEGACY_RENEGOTIATION_DISABLED error +from waste_collection_schedule.service.SSLError import get_legacy_session + +TITLE = "Bath & North East Somerset Council" +DESCRIPTION = ( + "Source for bathnes.gov.uk services for Bath & North East Somerset Council" +) +URL = "https://bathnes.gov.uk" +TEST_CASES = { + "uprn": {"uprn": "10001138699"}, + "houseNumber": {"postcode": "BA1 2LR", "housenameornumber": 1}, + "houseName": {"postcode": "BA2 9AZ", "housenameornumber": "All Saints Church"}, +} + +TYPES = { + "residual": {"icon": "mdi:trash-can", "alias": "Rubbish"}, + "recycling": {"icon": "mdi:recycle", "alias": "Recycling"}, + "organic": {"icon": "mdi:leaf", "alias": "Garden Waste"}, +} + + +class Source: + def __init__(self, uprn=None, postcode=None, housenameornumber=None): + self._postcode = postcode + self._housenameornumber = str(housenameornumber) + self._uprn = uprn + + def fetch(self) -> List[Collection]: + session = get_legacy_session() + + if self._uprn is None: + self._uprn = self.get_uprn(session) + + info = session.get( + f"https://www.bathnes.gov.uk/webapi/api/BinsAPI/v2/getbartecroute/{self._uprn}/true" + ).json() + + entries = [] + for type, props in TYPES.items(): + for dateType in ["Previous", "Next"]: + if info.get(f"{type}Route", "NS") == "NS": + continue + + entries.append( + Collection( + date=datetime.fromisoformat( + info[f"{type}{dateType}Date"] + ).date(), + t=props["alias"], + icon=props["icon"], + ) + ) + + return entries + + def get_uprn(self, session) -> str: + addresses = session.get( + f"https://www.bathnes.gov.uk/webapi/api/AddressesAPI/v2/search/{self._postcode}/150/true" + ).json() + address = next(filter(self.filter_addresses, addresses), None) + if address is None: + raise Exception( + f"House {self._housenameornumber} not found for postcode {self._postcode}" + ) + return address["uprn"] + + def filter_addresses(self, address) -> bool: + return f"|{self._housenameornumber.upper()}|" in address["payment_Address"] diff --git a/doc/source/bathnes_gov_uk.md b/doc/source/bathnes_gov_uk.md new file mode 100644 index 000000000..e3c0f7440 --- /dev/null +++ b/doc/source/bathnes_gov_uk.md @@ -0,0 +1,51 @@ +# Bath & North East Somerset Council + +Support for schedules provided by [Bath & North East Somerset Council](https://www.bathnes.gov.uk/). + +If collection data is available for the address provided, it will return rubbish and recycling waste collection dates. + +## Configuration via configuration.yaml + +```yaml +waste_collection_schedule: + sources: + - name: bathnes_gov_uk + args: + uprn: UPRN +``` + +### Configuration Variables + +**postcode** +_(string) (optional)_ + +**housenameornumber** +_(string|int) (optional)_ + +**uprn** +_(string) (optional)_ + +Either the postcode _and_ housenameornumber or the UPRN should be supplied in the arguments + +## Examples + +```yaml +waste_collection_schedule: + sources: + - name: bathnes_gov_uk + args: + uprn: "10001138699" +``` + +```yaml +waste_collection_schedule: + sources: + - name: bathnes_gov_uk + args: + postcode: "BA1 2LR" + housenameornumber: "1" +``` + +## How to find your UPRN + +An easy way to discover your Unique Property Reference Number (UPRN) is by going to [Find My Address](https://www.findmyaddress.co.uk/) and providing your address details. diff --git a/info.md b/info.md index 4e59fcc2d..a3ef44c3d 100644 --- a/info.md +++ b/info.md @@ -30,7 +30,7 @@ Waste collection schedules from service provider web sites are updated daily, de | Slovenia | Moji odpadki, Ljubljana | | Sweden | Affärsverken, Jönköping - June Avfall & Miljö, Landskrona - Svalövs Renhållning, Lerum Vatten och Avlopp, Linköping - Tekniska Verken, Region Gotland, Ronneby Miljöteknik, Samverkan Återvinning Miljö (SÅM), SRV Återvinning, SSAM, Sysav Sophämntning, Uppsala Vatten och Avfall AB, VA Syd Sophämntning | | Switzerland | A-Region, Andwil, Appenzell, Berg, Bühler, Eggersriet, Gais, Gaiserwald, Goldach, Grosswangen, Grub, Heiden, Herisau, Horn, Hundwil, Häggenschwil, Lindau, Lutzenberg, Muolen, Mörschwil, Münchenstein, Real Luzern, Rehetobel, Rorschach, Rorschacherberg, Schwellbrunn, Schönengrund, Speicher, Stein, Steinach, Teufen, Thal, Trogen, Tübach, Untereggen, Urnäsch, Wald, Waldkirch, Waldstatt, Wittenbach, Wolfhalden | -| United Kingdom | Aberdeenshire Council, Amber Valley Borough Council, Ashfield District Council, Basildon Council, Basingstoke and Deane Borough Council, Bedford Borough Council, Binzone, Blackburn with Darwen Borough Council, Bracknell Forest Council, Bradford Metropolitan District Council, Braintree District Council, Breckland Council, Bristol City Council, Buckinghamshire Waste Collection - Former Chiltern, South Bucks or Wycombe areas, Cambridge City Council, Canterbury City Council, Central Bedfordshire Council, Cherwell District Council, Cheshire East Council, Chesterfield Borough Council, Chichester District Council, City of Doncaster Council, City of York Council, Colchester City Council, Cornwall Council, Croydon Council, Derby City Council, East Cambridgeshire District Council, East Herts Council, East Northamptonshire and Wellingborough, East Riding of Yorkshire Council, Eastbourne Borough Council, Elmbridge Borough Council, Environment First, Exeter City Council, Fareham Council, FCC Environment, Fenland District Council, Fife Council, Gateshead Council, Glasgow City Council, Guildford Borough Council, Harborough District Council, Harlow Council, Herefordshire City Council, Horsham District Council, Huntingdonshire District Council, Kirklees Council, Leicester City Council, Lewes District Council, Lisburn and Castlereagh City Council, Liverpool City Council, London Borough of Bexley, London Borough of Bromley, London Borough of Lewisham, London Borough of Merton, Maldon District Council, Manchester City Council, Mid-Sussex District Council, Middlesbrough Council, Newcastle City Council, Newcastle Under Lyme Borough Council, Newport City Council, North Herts Council, North Kesteven District Council, North Lincolnshire Council, North Somerset Council, Nottingham City Council, Oxford City Council, Peterborough City Council, Portsmouth City Council, Reading Council, Reigate & Banstead Borough Council, Richmondshire District Council, Rotherham Metropolitan Borough Council, Runnymede Borough Council, Rushmoor Borough Council, Salford City Council, Sheffield City Council, South Cambridgeshire District Council, South Derbyshire District Council, South Gloucestershire Council, South Hams District Council, South Norfolk and Broadland Council, South Oxfordshire District Council, South Tyneside Council, Southampton City Council, Stevenage Borough Council, Stockport Council, Stockton-on-Tees Borough Council, Swindon Borough Council, Telford and Wrekin Council, Tewkesbury Borough Council, The Royal Borough of Kingston Council, Tonbridge and Malling Borough Council, Uttlesford District Council, Vale of White Horse District Council, Walsall Council, Waverley Borough Council, Welwyn Hatfield Borough Council, West Berkshire Council, West Devon Borough Council, West Dunbartonshire Council, Wigan Council, Wiltshire Council, Wirral Council, Wyre Forest District Council | +| United Kingdom | Aberdeenshire Council, Amber Valley Borough Council, Ashfield District Council, Basildon Council, Basingstoke and Deane Borough Council, Bath & North East Somerset Council, Bedford Borough Council, Binzone, Blackburn with Darwen Borough Council, Bracknell Forest Council, Bradford Metropolitan District Council, Braintree District Council, Breckland Council, Bristol City Council, Buckinghamshire Waste Collection - Former Chiltern, South Bucks or Wycombe areas, Cambridge City Council, Canterbury City Council, Central Bedfordshire Council, Cherwell District Council, Cheshire East Council, Chesterfield Borough Council, Chichester District Council, City of Doncaster Council, City of York Council, Colchester City Council, Cornwall Council, Croydon Council, Derby City Council, East Cambridgeshire District Council, East Herts Council, East Northamptonshire and Wellingborough, East Riding of Yorkshire Council, Eastbourne Borough Council, Elmbridge Borough Council, Environment First, Exeter City Council, Fareham Council, FCC Environment, Fenland District Council, Fife Council, Gateshead Council, Glasgow City Council, Guildford Borough Council, Harborough District Council, Harlow Council, Herefordshire City Council, Horsham District Council, Huntingdonshire District Council, Kirklees Council, Leicester City Council, Lewes District Council, Lisburn and Castlereagh City Council, Liverpool City Council, London Borough of Bexley, London Borough of Bromley, London Borough of Lewisham, London Borough of Merton, Maldon District Council, Manchester City Council, Mid-Sussex District Council, Middlesbrough Council, Newcastle City Council, Newcastle Under Lyme Borough Council, Newport City Council, North Herts Council, North Kesteven District Council, North Lincolnshire Council, North Somerset Council, Nottingham City Council, Oxford City Council, Peterborough City Council, Portsmouth City Council, Reading Council, Reigate & Banstead Borough Council, Richmondshire District Council, Rotherham Metropolitan Borough Council, Runnymede Borough Council, Rushmoor Borough Council, Salford City Council, Sheffield City Council, South Cambridgeshire District Council, South Derbyshire District Council, South Gloucestershire Council, South Hams District Council, South Norfolk and Broadland Council, South Oxfordshire District Council, South Tyneside Council, Southampton City Council, Stevenage Borough Council, Stockport Council, Stockton-on-Tees Borough Council, Swindon Borough Council, Telford and Wrekin Council, Tewkesbury Borough Council, The Royal Borough of Kingston Council, Tonbridge and Malling Borough Council, Uttlesford District Council, Vale of White Horse District Council, Walsall Council, Waverley Borough Council, Welwyn Hatfield Borough Council, West Berkshire Council, West Devon Borough Council, West Dunbartonshire Council, Wigan Council, Wiltshire Council, Wirral Council, Wyre Forest District Council | | United States of America | City of Oklahoma City, City of Pittsburgh, ReCollect, Republic Services, Seattle Public Utilities |