Home-Assistant-Sensor-Afvalbeheer icon indicating copy to clipboard operation
Home-Assistant-Sensor-Afvalbeheer copied to clipboard

Added Calendar support

Open WouterTuinstra opened this issue 3 years ago • 8 comments

I invested some time to add a afvalbeheer calendar in order to support the calendar.

In order to support multi platform component I needed to create a setup in init and therefore moving items out of sensor.py

  • Moved all constants to const.py.
  • Moved the core of getting data from API endpoints and storage to API.py
  • Created new function in API to create WasteData from Config
  • Created new async_setup function in __ init __.py to allow multi platform type support and updated the async_platform config in sensor.py to handle both ways of defining the config
  • Created new Calendar Entity in calendar.py reading all data from WasteData
  • Updated readme with how the new config should look like to support the Calendar entity

I didn't test thoroughly with multiple configurations in the same config there is an issue with the schema the way I tried to test it. But there will be partial support for multiple configurations as data will be stored uniquely based on wastecollector, postcode, streetnumber.

The calendar entity has currently a fixed name and is not looking at the configured resources but will generate from all waste_types an event. Each event inside the calendar will be named according to the waste_type only.

In order to get the calendar working from existing configuration you will have to update the config. The "old" config style will still load successful

Let me know what you think about it.

Wouter

WouterTuinstra avatar Aug 01 '22 19:08 WouterTuinstra

Nice work! Thanks for your contribution.

Give me some time to review the code and test all the possible configs

pippyn avatar Aug 02 '22 10:08 pippyn

Multiple instances of Afvalbeheer is not working yet.

pippyn avatar Aug 02 '22 12:08 pippyn

Initially thought that getting the config working for multiple instance would be challenging but found out it was relatively easy.

WouterTuinstra avatar Aug 07 '22 19:08 WouterTuinstra

With this latest version I don't get any data at all. Not for a single instance or multiple.

pippyn avatar Aug 09 '22 05:08 pippyn

Now it should be working

WouterTuinstra avatar Aug 09 '22 16:08 WouterTuinstra

A remaining error I found so far is line 6 in calander.py from homeassistant.components.aa_test.API import WasteData should be from .API import WasteData

pippyn avatar Aug 10 '22 12:08 pippyn

Updated the reference

WouterTuinstra avatar Aug 10 '22 12:08 WouterTuinstra

A few issues I found:

  • The calendar entities do not have an unique ID (_attr_unique_id)
  • if you use the old setup (i.e. add as a sensor and not a platform) the default values for the config are not loaded. Most importantly CONF_UPDATE_INTERVAL and CONF_DATE_FORMAT

pippyn avatar Aug 11 '22 07:08 pippyn

Added the unique ID for calendar entities and included waste collector name to the name Fixed the default values the config didn't get validated when using sensor due schema was missing in sensor.py

WouterTuinstra avatar Aug 28 '22 11:08 WouterTuinstra

Thank you @WouterTuinstra for your contribution to this project! I've just released v5.0.0

pippyn avatar Aug 29 '22 09:08 pippyn