Skip to content

Commit

Permalink
Support for new ROVA API
Browse files Browse the repository at this point in the history
  • Loading branch information
pippyn committed Aug 29, 2024
1 parent e519386 commit b9898ad
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 10 deletions.
2 changes: 1 addition & 1 deletion custom_components.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sensor.afvalbeheer": {
"version": "5.3.9",
"version": "5.3.10",
"local_location": "/custom_components/afvalbeheer/__init__.py",
"remote_location": "https://raw.githubusercontent.com/pippyn/Home-Assistant-Sensor-Afvalbeheer/master/custom_components/afvalbeheer/__init__.py",
"visit_repo": "https://github.com/pippyn/Home-Assistant-Sensor-Afvalbeheer",
Expand Down
60 changes: 55 additions & 5 deletions custom_components/afvalbeheer/API.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def __init__(self, hass, waste_collector, city_name, postcode, street_name, stre
def __select_collector(self):
if self.waste_collector in XIMMIO_COLLECTOR_IDS.keys():
self.collector = XimmioCollector(self.hass, self.waste_collector, self.postcode, self.street_number, self.suffix, self.address_id, self.customer_id)
elif self.waste_collector in ["mijnafvalwijzer", "afvalstoffendienstkalender", "rova"]:
elif self.waste_collector in ["mijnafvalwijzer", "afvalstoffendienstkalender"]:
self.collector = AfvalwijzerCollector(self.hass, self.waste_collector, self.postcode, self.street_number, self.suffix)
elif self.waste_collector == "afvalalert":
self.collector = AfvalAlertCollector(self.hass, self.waste_collector, self.postcode, self.street_number, self.suffix)
Expand All @@ -134,6 +134,8 @@ def __select_collector(self):
self.collector = RD4Collector(self.hass, self.waste_collector, self.postcode, self.street_number, self.suffix)
elif self.waste_collector == "cleanprofs":
self.collector = CleanprofsCollector(self.hass, self.waste_collector, self.postcode, self.street_number, self.suffix)
elif self.waste_collector == "rova":
self.collector = ROVACollector(self.hass, self.waste_collector, self.postcode, self.street_number, self.suffix)
elif self.waste_collector in BURGERPORTAAL_COLLECTOR_IDS.keys():
self.collector = BurgerportaalCollector(self.hass, self.waste_collector, self.postcode, self.street_number, self.suffix)
elif self.waste_collector in OPZET_COLLECTOR_URLS.keys():
Expand Down Expand Up @@ -273,10 +275,7 @@ class AfvalwijzerCollector(WasteCollector):
def __init__(self, hass, waste_collector, postcode, street_number, suffix):
super().__init__(hass, waste_collector, postcode, street_number, suffix)
self.apikey = '5ef443e778f41c4f75c69459eea6e6ae0c2d92de729aa0fc61653815fbd6a8ca'
if self.waste_collector == "rova":
self.waste_collector_url = "inzamelkalender." + self.waste_collector
else:
self.waste_collector_url = self.waste_collector
self.waste_collector_url = self.waste_collector

def __get_data(self):
get_url = 'https://api.{}.nl/webservices/appsinput/?apikey={}&method=postcodecheck&postcode={}&street=&huisnummer={}&toevoeging={}&app_name=afvalwijzer&platform=web&afvaldata={}&langs=nl'.format(
Expand Down Expand Up @@ -1060,6 +1059,57 @@ async def update(self):
return False


class ROVACollector(WasteCollector):
WASTE_TYPE_MAPPING = {
'gft': WASTE_TYPE_GREEN,
'papier': WASTE_TYPE_PAPER,
'pmd': WASTE_TYPE_PACKAGES,
}

def __init__(self, hass, waste_collector, postcode, street_number, suffix):
super().__init__(hass, waste_collector, postcode, street_number, suffix)
self.main_url = 'https://www.rova.nl'

def __get_data(self):
self.today = datetime.today()
self.year = self.today.year
response = requests.get(
'{}/api/waste-calendar/upcoming?houseNumber={}&addition={}&postalcode={}&take=10'.format(self.main_url, self.street_number, self.suffix, self.postcode)
)
return response

async def update(self):
_LOGGER.debug('Updating Waste collection dates using Rest API')

self.collections.remove_all()

try:
r = await self.hass.async_add_executor_job(self.__get_data)
response = r.json()

if not response:
_LOGGER.error('No Waste data found!')
return

for item in response:
waste_type = self.map_waste_type(item["wasteType"]["title"])
date = item["date"]

if not waste_type or not date:
continue

collection = WasteCollection.create(
date=datetime.strptime(date, '%Y-%m-%dT%H:%M:%S%z').replace(tzinfo=None),
waste_type=waste_type
)
if collection not in self.collections:
self.collections.add(collection)

except requests.exceptions.RequestException as exc:
_LOGGER.error('Error occurred while fetching data: %r', exc)
return False


class RecycleApp(WasteCollector):
WASTE_TYPE_MAPPING = {
'grof': WASTE_TYPE_BULKLITTER,
Expand Down
5 changes: 3 additions & 2 deletions custom_components/afvalbeheer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Sensor component for waste pickup dates from dutch and belgium waste collectors
Original Author: Pippijn Stortelder
Current Version: 5.3.9 20240827
Current Version: 5.3.10 20240829
20230705 - Added support for Afval3xBeter
20230822 - Fix icon for papier-pmd
20230927 - Fix ZRD API
Expand All @@ -28,6 +28,7 @@
20240711 - Fix sensor icons
20240827 - Add support for Cleanprofs
20240827 - Small bug fix with configs
20240829 - Support for new ROVA API
Example config:
Configuration.yaml:
Expand Down Expand Up @@ -64,7 +65,7 @@
from .API import get_wastedata_from_config


__version__ = "5.3.9"
__version__ = "5.3.10"


_LOGGER = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion custom_components/afvalbeheer/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@
'hellendoorn': '24434f5b-7244-412b-9306-3a2bd1e22bc1',
'meerlanden': '800bf8d7-6dd1-4490-ba9d-b419d6dc8a45',
'ximmio': '800bf8d7-6dd1-4490-ba9d-b419d6dc8a45',
'meppel': 'b7a594c7-2490-4413-88f9-94749a3ec62a',
'rad': '13a2cad9-36d0-4b01-b877-efcb421a864d',
'twentemilieu': '8d97bb56-5afd-4cbc-a651-b4f7314264b4',
'waardlanden': '942abcf6-3775-400d-ae5d-7380d728b23c',
Expand All @@ -128,6 +127,7 @@

DEPRECATED_AND_NEW_WASTECOLLECTORS = {
'cure': 'mijnafvalwijzer',
'meppel': 'mijnafvalwijzer',
'area': 'areareiniging',
'ophaalkalender': 'recycleapp',
'circulus-berkel': 'circulus',
Expand Down
2 changes: 1 addition & 1 deletion custom_components/afvalbeheer/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"rsa",
"pycryptodome"
],
"version": "5.3.7"
"version": "5.3.10"
}

0 comments on commit b9898ad

Please sign in to comment.