mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 04:06:03 +01:00
Add source for Breckland Council, UK - update
Add ICON_Map Add support for uprn Update documentation
This commit is contained in:
@@ -8,17 +8,33 @@ DESCRIPTION = "Source for breckland.gov.uk"
|
||||
URL = "https://www.breckland.gov.uk/mybreckland"
|
||||
TEST_CASES = {
|
||||
"test1" : {"postcode":"IP22 2LJ","address":"glen travis" },
|
||||
"test2" : {"uprn":"10011977093"},
|
||||
}
|
||||
|
||||
API_URL = "https://www.breckland.gov.uk/apiserver/ajaxlibrary"
|
||||
ICON_MAP = {
|
||||
"Refuse Collection Service": "mdi:trash-can",
|
||||
"Recycling Collection Service": "mdi:recycle",
|
||||
"Garden Waste Service": "mdi:leaf",
|
||||
}
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
headers = {'referer': URL}
|
||||
|
||||
class Source:
|
||||
def __init__(self,postcode,address):
|
||||
def __init__(self,postcode=None,address=None,uprn=None):
|
||||
self._postcode = postcode
|
||||
self._address = address
|
||||
self._uprn = uprn
|
||||
|
||||
def fetch(self):
|
||||
|
||||
if self._postcode == None and self._address == None and self._uprn == None:
|
||||
_LOGGER.error("no attributes - specify postcode and address or just uprn")
|
||||
return []
|
||||
|
||||
if self._uprn == None:
|
||||
json_data = {
|
||||
"jsonrpc":"2.0",
|
||||
"id":"",
|
||||
@@ -29,9 +45,7 @@ class Source:
|
||||
}
|
||||
}
|
||||
|
||||
headers = {'referer': 'https://www.breckland.gov.uk/mybreckland'}
|
||||
url = 'https://www.breckland.gov.uk/apiserver/ajaxlibrary'
|
||||
r = requests.post(url, json=json_data,headers=headers)
|
||||
r = requests.post(API_URL, json=json_data,headers=headers)
|
||||
|
||||
if r.status_code != 200:
|
||||
_LOGGER.error("Error querying calender data")
|
||||
@@ -39,12 +53,11 @@ class Source:
|
||||
|
||||
json_response = r.json()
|
||||
|
||||
uprn = ""
|
||||
for key in json_response['result']:
|
||||
if self._address.lower() in key['name'].lower():
|
||||
uprn = (key['uprn'])
|
||||
self._uprn = (key['uprn'])
|
||||
|
||||
if uprn == "":
|
||||
if self._uprn == None:
|
||||
_LOGGER.error("Error querying calender data")
|
||||
return []
|
||||
|
||||
@@ -53,12 +66,12 @@ class Source:
|
||||
"id":"",
|
||||
"method":"Breckland.Whitespace.JointWasteAPI.GetBinCollectionsByUprn",
|
||||
"params":{
|
||||
"uprn":uprn,
|
||||
"uprn":self._uprn,
|
||||
"environment":"live"
|
||||
}
|
||||
}
|
||||
|
||||
r = requests.post(url, json=json_data,headers=headers)
|
||||
r = requests.post(API_URL, json=json_data,headers=headers)
|
||||
|
||||
if r.status_code != 200:
|
||||
_LOGGER.error("Error querying calender data")
|
||||
@@ -72,6 +85,10 @@ class Source:
|
||||
for data in waste:
|
||||
print(data['collectiontype'])
|
||||
print(data['nextcollection'])
|
||||
entries.append(Collection(datetime.strptime(data['nextcollection'],'%d/%m/%Y %H:%M:%S').date(),data['collectiontype']))
|
||||
entries.append(Collection(
|
||||
datetime.strptime(data['nextcollection'],'%d/%m/%Y %H:%M:%S').date(),
|
||||
data['collectiontype'],
|
||||
ICON_MAP.get(data['collectiontype'])
|
||||
))
|
||||
|
||||
return entries
|
||||
@@ -11,16 +11,20 @@ waste_collection_schedule:
|
||||
args:
|
||||
postcode: POSTCODE
|
||||
address: ADDRESS
|
||||
uprn: UPRN
|
||||
|
||||
```
|
||||
|
||||
### Configuration Variables
|
||||
|
||||
**POSTCODE**
|
||||
*(string) (required)*
|
||||
*(string) (optional)*
|
||||
|
||||
**ADDRESS**
|
||||
*(string) (required)*
|
||||
*(string) (optional)*
|
||||
|
||||
**UPRN**
|
||||
*(string) (optional)*
|
||||
|
||||
## Examples
|
||||
|
||||
@@ -33,8 +37,20 @@ waste_collection_schedule:
|
||||
address: "glen travis"
|
||||
```
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: breckland_gov_uk
|
||||
args:
|
||||
uprn: "10011977093"
|
||||
```
|
||||
|
||||
If uprn is provided, only uprn is used. Otherwise postcode and address are required.
|
||||
|
||||
You can find all relevant informations at [Breckland Council](https://www.breckland.gov.uk/mybreckland) homepage
|
||||
use the POSTCODE -> click find address.
|
||||
Choose your address. Please only use the first part of your address. If you got an error, use less charecters from address.
|
||||
|
||||
## 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 providng your address details.
|
||||
|
||||
Reference in New Issue
Block a user