-
-
Notifications
You must be signed in to change notification settings - Fork 658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding Sefton Council #2931
Adding Sefton Council #2931
Conversation
Very much appreciated @northerngeek! I've not been able to configure this add-on before - will give it a try right now. Hello from Waterloo, Liverpool! |
@northerngeek what would the yaml waste_collection_schedule look like to access your data source please? I can see that this is what I need to supply to get started with this HACS add-on waste_collection_schedule: Same for the sensor yaml please - apologies I'm a total newb in yaml and configuration HACS add-ons sensor:
Thanks |
Hi John/@1x02d8 , Greetings from Formby! Hopefully it gets approved soon to be merged (or some kind person helps me with making it ready to be merged) and you can just configure everything via the UI (much easier than YAML!) in the standard way. I didn't personally use YAML so couldn't provide a tonne of insight sorry - in order to test this was working for me, I "simply"*:
* I say simply but none of this is ever simple! Good luck! |
You're a star John - thanks so much. I already have the repo installed so I'll wait for the merge to be approved and I'll re-download the repository and configure via the front-end. Fingers crossed, your hard work will benefit others. Did you manage access an ICS file or did you have to extract the dates info from the PDF? |
No iCAL I'm afraid, and PDF is a nightmare format as far as I'm concerned - I just used Requests and BeautifulSoup (Python libraries) to navigate through the forms on the Sefton website, and extract the next dates from the webpage that loads - one downside of this is you only get the next collection, rather than a full year's worth. Looking at the PDF again, I suppose I could try and download it, find text that's coloured white and try to use that, although the "Arrangements to be confirmed" areas would be tricky. Differentiating between brown and grey coloured tables may be tricky too - I've tinkered with PDFs in C# before and the way the page is assembled is a bit like stamping layers of elements on top of each other (or it felt that way at least), so what would be trivial in a Word Processor (e.g. "how big are this document's margins") is surprisingly complex. ... If further out dates would be helpful, I'll try and figure out if there's a way. |
|
||
class Source: | ||
def __init__(self, houseNumberOrName:str | int, Streetname:str, Postcode:str): # argX correspond to the args dict in the source configuration | ||
self._houseNumberOrName = houseNumberOrName.upper() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self._houseNumberOrName = houseNumberOrName.upper()
should probably be self._houseNumberOrName = str(houseNumberOrName).upper()
as this fails if houseNumberOrName is an integer (only happens using YAML configuration in the real world) you could modify one of your test case to have an integer houseNumberOrName
def __init__(self, houseNumberOrName:str | int, Streetname:str, Postcode:str): # argX correspond to the args dict in the source configuration | ||
self._houseNumberOrName = houseNumberOrName.upper() | ||
self._Streetname = Streetname | ||
self._Postcode = Postcode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer python naming conventions (variables not capitalized and using Snake case): houseNumberOrName
-> house_number_or_name
and Streetname
-> streetname
and Postcode
-> postcode
don't forget to change PARAM_DESCRIPTIONS as well
I know there are some other sources not using this convention but it's probably best to use them
break | ||
request = sess.post('https://www.sefton.gov.uk/bins-and-recycling/bins-and-recycling/when-is-my-bin-collection-day/', data=payload) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could add
if 'selectedValue' not in payload:
raise SourceArgumentNotFoundWithSuggestions("houseNumberOrName", self._houseNumberOrName,[option.text.strip() for option in option_tags])
below the for so you'll get an error message suggesting alternatives if you enter something invalid
(you may need to rename variable as described above)
doc/source/sefton_gov_uk.md
Outdated
args: | ||
Postcode: Postcode | ||
Streetname: Streetname | ||
House Number Or Name: houseNumberOrName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Key must be written exactly like the constructor variable name (houseNumberOrName
instead of House Number Or Name
)
doc/source/sefton_gov_uk.md
Outdated
**Streetname** | ||
*(string) (required)* | ||
|
||
**House Name or Number** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be the name of the YAML key
368058a
to
1c520c7
Compare
Replaced by #2947 |
Great job John! That's configured via the front-end and working fine for me. HA is now correctly telling me to put my black bin out this Friday and my brown bin next Friday - love it!!! Once they start collecting the green bins - will this collection date appear also? Very impressed by your Python skills to dig this info from a nebulous web page |
Hi @1x02d8, Fantastic, I'm really pleased it's working for you. There's still one more green bin collection for my road this year and it shows up, looking at a random address in Waterloo I can see the way things are formatted is very slightly different but I think the code will still work. If the green bins don't appear when they resume, feel free to send me a message and I'll happily tweak it. You're too kind with your comments on my Python, but I'm really pleased it was helpful to somebody else, that's made my day! |
Two happy Northern Geeks! |
First bit of Python (and I'm sure it shows!) so feel free to provide any critiques and if anybody wants to suggest how to make the GUI prompts work better I'm all ears. That said, it does manage to retrieve information from Sefton Council's webpages for bin collections, so it's a (functioning) start!