Skip to content

Commit

Permalink
Initial RWM support (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
DynaSpan authored Dec 17, 2024
1 parent 1913e9e commit fae5394
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ _Component to integrate with the following providers._
| rd4 |
| rova |
| rmn |
| rwm |
| schouwenand |
| spaarnelanden |
| sudwestfryslan |
Expand Down
11 changes: 9 additions & 2 deletions custom_components/afvalwijzer/collector/main_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
SENSOR_COLLECTORS_ICALENDAR,
SENSOR_COLLECTORS_OPZET,
SENSOR_COLLECTORS_RD4,
SENSOR_COLLECTORS_XIMMIO,
SENSOR_COLLECTORS_XIMMIO
)

try:
from . import burgerportaal, circulus, deafvalapp, icalendar, mijnafvalwijzer, opzet, rd4, ximmio
from . import burgerportaal, circulus, deafvalapp, icalendar, mijnafvalwijzer, opzet, rd4, rwm, ximmio
except ImportError as err:
_LOGGER.error(f"Import error {err.args}")

Expand Down Expand Up @@ -101,6 +101,13 @@ def __init__(
self.street_number,
self.suffix,
)
elif provider == "rwm":
waste_data_raw = rwm.get_waste_data_raw(
self.provider,
self.postal_code,
self.street_number,
self.suffix,
)
else:
_LOGGER.error(f"Unknown provider: {provider}")
raise ValueError(f"Unknown provider: {provider}")
Expand Down
56 changes: 56 additions & 0 deletions custom_components/afvalwijzer/collector/rwm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from ..const.const import _LOGGER, SENSOR_COLLECTORS_RWM
from ..common.main_functions import _waste_type_rename
from datetime import datetime
import requests
from urllib3.exceptions import InsecureRequestWarning

requests.packages.urllib3.disable_warnings(InsecureRequestWarning)


def get_waste_data_raw(provider, postal_code, street_number, suffix):
try:
if provider != "rwm":
raise ValueError(f"Invalid provider: {provider}, please verify")

##########################################################################
# First request: get bag id
##########################################################################
url = SENSOR_COLLECTORS_RWM["getAddress"].format(postal_code, street_number)

response = requests.get(url=url, timeout=60).json()

if not response:
_LOGGER.error("Address not found!")
return []

bagId = response[0]["bagid"]

##########################################################################
# Second request: get the dates
##########################################################################
url = SENSOR_COLLECTORS_RWM["getSchedule"].format(bagId)

response = requests.get(url=url, timeout=60).json()

if not response:
_LOGGER.error("Could not retrieve trash schedule!")
return []

waste_data_raw = []

for item in response:
if item["ophaaldatum"] is not None:
data = {
"type": _waste_type_rename(item["title"].strip().lower()),
"date": datetime.strptime(item["ophaaldatum"], "%Y-%m-%d").strftime("%Y-%m-%d"),
}
waste_data_raw.append(data)

except requests.exceptions.RequestException as err:
raise ValueError(err) from err

return waste_data_raw


if __name__ == "__main__":
print("Yell something at a mountain!")
2 changes: 2 additions & 0 deletions custom_components/afvalwijzer/common/main_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ def _waste_type_rename(item_name):
"gemengde plastics": "plastic",
"gft & etensresten": "gft",
"glass": "glas",
"gft afval": "gft",
"green": "gft",
"groene container": "gft",
"groente": "gft",
"groente-, fruit en tuinafval": "gft",
"groente, fruit- en tuinafval": "gft",
"grof tuinafval": "takken",
"grey": "restafval",
"grijze container": "restafval",
"kca": "chemisch",
Expand Down
5 changes: 5 additions & 0 deletions custom_components/afvalwijzer/const/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@
"deafvalapp": "https://dataservice.deafvalapp.nl/dataservice/DataServiceServlet?service=OPHAALSCHEMA&land=NL&postcode={0}&straatId=0&huisnr={1}&huisnrtoev={2}",
}

SENSOR_COLLECTORS_RWM = {
"getAddress": "https://rwm.nl/adressen/{0}:{1}",
"getSchedule": "https://rwm.nl/rest/adressen/{0}/afvalstromen"
}

CONF_COLLECTOR = "provider"
CONF_API_TOKEN = "api_token"
CONF_POSTAL_CODE = "postal_code"
Expand Down

0 comments on commit fae5394

Please sign in to comment.