Skip to content

Commit

Permalink
New option for custom mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
pippyn committed Sep 6, 2024
1 parent b9898ad commit 6fabaf3
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 48 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,14 @@ updateinterval: 12
```
If you want to adjust the update interval, you can set this option to the desired hours. Default is 12.

### Custom mapping of waste fractions
```yaml
custommapping:
keukenafval: VET-goed
fraction2: New name for fraction2
```
Some wastecollectors use the wrong fraction name and with this option you can override the default mapping. E.g. Meppel uses keukenafval for the fraction VET-goed, which by default gets mapped to GFT. Default is empty.

### Customer ID for Ximmio commercial address
```yaml
customerid: 123456
Expand Down
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.10",
"version": "5.4.0",
"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
96 changes: 52 additions & 44 deletions custom_components/afvalbeheer/API.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def __eq__(self, other):

class WasteData(object):

def __init__(self, hass, waste_collector, city_name, postcode, street_name, street_number, suffix, address_id, print_waste_type, update_interval, customer_id):
def __init__(self, hass, waste_collector, city_name, postcode, street_name, street_number, suffix, custom_mapping, address_id, print_waste_type, update_interval, customer_id):
self.hass = hass
self.waste_collector = waste_collector
self.city_name = city_name
Expand All @@ -109,37 +109,38 @@ def __init__(self, hass, waste_collector, city_name, postcode, street_name, stre
self.collector = None
self.update_interval = update_interval
self.customer_id = customer_id
self.custom_mapping = custom_mapping
self.__select_collector()

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)
self.collector = XimmioCollector(self.hass, self.waste_collector, self.postcode, self.street_number, self.suffix, self.custom_mapping, self.address_id, self.customer_id)
elif self.waste_collector in ["mijnafvalwijzer", "afvalstoffendienstkalender"]:
self.collector = AfvalwijzerCollector(self.hass, self.waste_collector, self.postcode, self.street_number, self.suffix)
self.collector = AfvalwijzerCollector(self.hass, self.waste_collector, self.postcode, self.street_number, self.suffix, self.custom_mapping)
elif self.waste_collector == "afvalalert":
self.collector = AfvalAlertCollector(self.hass, self.waste_collector, self.postcode, self.street_number, self.suffix)
self.collector = AfvalAlertCollector(self.hass, self.waste_collector, self.postcode, self.street_number, self.suffix, self.custom_mapping)
elif self.waste_collector == "deafvalapp":
self.collector = DeAfvalAppCollector(self.hass, self.waste_collector, self.postcode, self.street_number, self.suffix)
self.collector = DeAfvalAppCollector(self.hass, self.waste_collector, self.postcode, self.street_number, self.suffix, self.custom_mapping)
elif self.waste_collector == "circulus":
self.collector = CirculusCollector(self.hass, self.waste_collector, self.postcode, self.street_number, self.suffix)
self.collector = CirculusCollector(self.hass, self.waste_collector, self.postcode, self.street_number, self.suffix, self.custom_mapping,)
elif self.waste_collector == "limburg.net":
self.collector = LimburgNetCollector(self.hass, self.waste_collector, self.city_name, self.postcode, self.street_name, self.street_number, self.suffix)
self.collector = LimburgNetCollector(self.hass, self.waste_collector, self.city_name, self.postcode, self.street_name, self.street_number, self.suffix, self.custom_mapping)
elif self.waste_collector == "montferland":
self.collector = MontferlandNetCollector(self.hass, self.waste_collector, self.postcode, self.street_number, self.suffix)
self.collector = MontferlandNetCollector(self.hass, self.waste_collector, self.postcode, self.street_number, self.suffix, self.custom_mapping)
elif self.waste_collector == "omrin":
self.collector = OmrinCollector(self.hass, self.waste_collector, self.postcode, self.street_number, self.suffix)
self.collector = OmrinCollector(self.hass, self.waste_collector, self.postcode, self.street_number, self.suffix, self.custom_mapping)
elif self.waste_collector == "recycleapp":
self.collector = RecycleApp(self.hass, self.waste_collector, self.postcode, self.street_name, self.street_number, self.suffix)
self.collector = RecycleApp(self.hass, self.waste_collector, self.postcode, self.street_name, self.street_number, self.suffix, self.custom_mapping)
elif self.waste_collector == "rd4":
self.collector = RD4Collector(self.hass, self.waste_collector, self.postcode, self.street_number, self.suffix)
self.collector = RD4Collector(self.hass, self.waste_collector, self.postcode, self.street_number, self.suffix, self.custom_mapping)
elif self.waste_collector == "cleanprofs":
self.collector = CleanprofsCollector(self.hass, self.waste_collector, self.postcode, self.street_number, self.suffix)
self.collector = CleanprofsCollector(self.hass, self.waste_collector, self.postcode, self.street_number, self.suffix, self.custom_mapping)
elif self.waste_collector == "rova":
self.collector = ROVACollector(self.hass, self.waste_collector, self.postcode, self.street_number, self.suffix)
self.collector = ROVACollector(self.hass, self.waste_collector, self.postcode, self.street_number, self.suffix, self.custom_mapping)
elif self.waste_collector in BURGERPORTAAL_COLLECTOR_IDS.keys():
self.collector = BurgerportaalCollector(self.hass, self.waste_collector, self.postcode, self.street_number, self.suffix)
self.collector = BurgerportaalCollector(self.hass, self.waste_collector, self.postcode, self.street_number, self.suffix, self.custom_mapping)
elif self.waste_collector in OPZET_COLLECTOR_URLS.keys():
self.collector = OpzetCollector(self.hass, self.waste_collector, self.postcode, self.street_number, self.suffix)
self.collector = OpzetCollector(self.hass, self.waste_collector, self.postcode, self.street_number, self.suffix, self.custom_mapping)
else:
persistent_notification.create(
self.hass,
Expand Down Expand Up @@ -172,19 +173,24 @@ def collections(self):

class WasteCollector(ABC):

def __init__(self, hass, waste_collector, postcode, street_number, suffix):
def __init__(self, hass, waste_collector, postcode, street_number, suffix, custom_mapping):
self.hass = hass
self.waste_collector = waste_collector
self.postcode = postcode
self.street_number = street_number
self.suffix = suffix
self.custom_mapping = custom_mapping
self.collections = WasteCollectionRepository()

@abstractmethod
async def update(self):
pass

def map_waste_type(self, name):
if self.custom_mapping:
for from_type, to_type in self.custom_mapping.items():
if from_type.lower() in name.lower():
return to_type
for from_type, to_type in self.WASTE_TYPE_MAPPING.items():
if from_type.lower() in name.lower():
return to_type
Expand All @@ -208,8 +214,8 @@ class AfvalAlertCollector(WasteCollector):
'kerst': WASTE_TYPE_TREE,
}

def __init__(self, hass, waste_collector, postcode, street_number, suffix):
super().__init__(hass, waste_collector, postcode, street_number, suffix)
def __init__(self, hass, waste_collector, postcode, street_number, suffix, custom_mapping):
super().__init__(hass, waste_collector, postcode, street_number, suffix, custom_mapping)
self.main_url = "https://www.afvalalert.nl/kalender"

def __get_data(self):
Expand Down Expand Up @@ -272,8 +278,8 @@ class AfvalwijzerCollector(WasteCollector):
'md': WASTE_TYPE_PACKAGES,
}

def __init__(self, hass, waste_collector, postcode, street_number, suffix):
super().__init__(hass, waste_collector, postcode, street_number, suffix)
def __init__(self, hass, waste_collector, postcode, street_number, suffix, custom_mapping):
super().__init__(hass, waste_collector, postcode, street_number, suffix, custom_mapping)
self.apikey = '5ef443e778f41c4f75c69459eea6e6ae0c2d92de729aa0fc61653815fbd6a8ca'
self.waste_collector_url = self.waste_collector

Expand Down Expand Up @@ -331,8 +337,8 @@ class BurgerportaalCollector(WasteCollector):
'rest': WASTE_TYPE_GREY,
}

def __init__(self, hass, waste_collector, postcode, street_number, suffix):
super().__init__(hass, waste_collector, postcode, street_number, suffix)
def __init__(self, hass, waste_collector, postcode, street_number, suffix, custom_mapping):
super().__init__(hass, waste_collector, postcode, street_number, suffix, custom_mapping)
self.company_code = BURGERPORTAAL_COLLECTOR_IDS[self.waste_collector]
self.apikey = 'AIzaSyA6NkRqJypTfP-cjWzrZNFJzPUbBaGjOdk'
self.refresh_token = ''
Expand Down Expand Up @@ -448,8 +454,8 @@ class CirculusCollector(WasteCollector):
# 'TREE': WASTE_TYPE_TREE,
}

def __init__(self, hass, waste_collector, postcode, street_number, suffix):
super().__init__(hass, waste_collector, postcode, street_number, suffix)
def __init__(self, hass, waste_collector, postcode, street_number, suffix, custom_mapping):
super().__init__(hass, waste_collector, postcode, street_number, suffix, custom_mapping)
self.main_url = "https://mijn.circulus.nl"

def __get_data(self):
Expand Down Expand Up @@ -547,8 +553,8 @@ class CleanprofsCollector(WasteCollector):
'RST': WASTE_TYPE_GREY,
}

def __init__(self, hass, waste_collector, postcode, street_number, suffix):
super().__init__(hass, waste_collector, postcode, street_number, suffix)
def __init__(self, hass, waste_collector, postcode, street_number, suffix, custom_mapping):
super().__init__(hass, waste_collector, postcode, street_number, suffix, custom_mapping)
self.main_url = "https://cleanprofs.jmsdev.nl/"

def __get_data(self):
Expand Down Expand Up @@ -598,8 +604,8 @@ class DeAfvalAppCollector(WasteCollector):
'kerstboom': WASTE_TYPE_TREE
}

def __init__(self, hass, waste_collector, postcode, street_number, suffix):
super().__init__(hass, waste_collector, postcode, street_number, suffix)
def __init__(self, hass, waste_collector, postcode, street_number, suffix, custom_mapping):
super().__init__(hass, waste_collector, postcode, street_number, suffix, custom_mapping)
self.main_url = "http://dataservice.deafvalapp.nl"

def __get_data(self):
Expand Down Expand Up @@ -662,8 +668,8 @@ class LimburgNetCollector(WasteCollector):
# 'kerstboom': WASTE_TYPE_TREE,
}

def __init__(self, hass, waste_collector, city_name, postcode, street_name, street_number, suffix):
super().__init__(hass, waste_collector, postcode, street_number, suffix)
def __init__(self, hass, waste_collector, city_name, postcode, street_name, street_number, suffix, custom_mapping):
super().__init__(hass, waste_collector, postcode, street_number, suffix, custom_mapping)
self.city_name = city_name
self.street_name = street_name.replace(" ", "+")
self.main_url = "https://limburg.net/api-proxy/public"
Expand Down Expand Up @@ -752,8 +758,8 @@ class MontferlandNetCollector(WasteCollector):
# 'kerstboom': WASTE_TYPE_TREE,
}

def __init__(self, hass, waste_collector, postcode, street_number, suffix):
super().__init__(hass, waste_collector, postcode, street_number, suffix)
def __init__(self, hass, waste_collector, postcode, street_number, suffix, custom_mapping):
super().__init__(hass, waste_collector, postcode, street_number, suffix, custom_mapping)
self.main_url = "http://afvalwijzer.afvaloverzicht.nl/"
self.query_start = "?Username=GSD&Password=gsd$2014"
self.administratie_id = None
Expand Down Expand Up @@ -841,8 +847,8 @@ class OmrinCollector(WasteCollector):
# 'TREE': WASTE_TYPE_TREE,
}

def __init__(self, hass, waste_collector, postcode, street_number, suffix):
super().__init__(hass, waste_collector, postcode, street_number, suffix)
def __init__(self, hass, waste_collector, postcode, street_number, suffix, custom_mapping):
super().__init__(hass, waste_collector, postcode, street_number, suffix, custom_mapping)
self.main_url = "https://api-omrin.freed.nl/Account"
self.appId = uuid.uuid1().__str__()
self.publicKey = None
Expand Down Expand Up @@ -922,8 +928,8 @@ class OpzetCollector(WasteCollector):
'pbd': WASTE_TYPE_PACKAGES,
}

def __init__(self, hass, waste_collector, postcode, street_number, suffix):
super().__init__(hass, waste_collector, postcode, street_number, suffix)
def __init__(self, hass, waste_collector, postcode, street_number, suffix, custom_mapping):
super().__init__(hass, waste_collector, postcode, street_number, suffix, custom_mapping)
self.main_url = OPZET_COLLECTOR_URLS[self.waste_collector]
self.bag_id = None
if waste_collector == "suez":
Expand Down Expand Up @@ -1008,8 +1014,8 @@ class RD4Collector(WasteCollector):
'pmd': WASTE_TYPE_PACKAGES,
}

def __init__(self, hass, waste_collector, postcode, street_number, suffix):
super().__init__(hass, waste_collector, postcode, street_number, suffix)
def __init__(self, hass, waste_collector, postcode, street_number, suffix, custom_mapping):
super().__init__(hass, waste_collector, postcode, street_number, suffix, custom_mapping)
self.main_url = 'https://data.rd4.nl/api/v1/waste-calendar'
self.postcode_split = re.search(r"(\d\d\d\d) ?([A-z][A-z])", self.postcode)
self.postcode = self.postcode_split.group(1) + '+' + self.postcode_split.group(2).upper()
Expand Down Expand Up @@ -1066,8 +1072,8 @@ class ROVACollector(WasteCollector):
'pmd': WASTE_TYPE_PACKAGES,
}

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

def __get_data(self):
Expand Down Expand Up @@ -1137,8 +1143,8 @@ class RecycleApp(WasteCollector):
'omb': WASTE_TYPE_GREY,
}

def __init__(self, hass, waste_collector, postcode, street_name, street_number, suffix):
super().__init__(hass, waste_collector, postcode, street_number, suffix)
def __init__(self, hass, waste_collector, postcode, street_name, street_number, suffix, custom_mapping):
super().__init__(hass, waste_collector, postcode, street_number, suffix, custom_mapping)
self.street_name = street_name
self.main_url = 'https://api.recycleapp.be/api/app/v1/'
self.xsecret = 'Op2tDi2pBmh1wzeC5TaN2U3knZan7ATcfOQgxh4vqC0mDKmnPP2qzoQusmInpglfIkxx8SZrasBqi5zgMSvyHggK9j6xCQNQ8xwPFY2o03GCcQfcXVOyKsvGWLze7iwcfcgk2Ujpl0dmrt3hSJMCDqzAlvTrsvAEiaSzC9hKRwhijQAFHuFIhJssnHtDSB76vnFQeTCCvwVB27DjSVpDmq8fWQKEmjEncdLqIsRnfxLcOjGIVwX5V0LBntVbeiBvcjyKF2nQ08rIxqHHGXNJ6SbnAmTgsPTg7k6Ejqa7dVfTmGtEPdftezDbuEc8DdK66KDecqnxwOOPSJIN0zaJ6k2Ye2tgMSxxf16gxAmaOUqHS0i7dtG5PgPSINti3qlDdw6DTKEPni7X0rxM'
Expand Down Expand Up @@ -1270,8 +1276,8 @@ class XimmioCollector(WasteCollector):
'woerden': "https://wasteprod2api.ximmio.com",
}

def __init__(self, hass, waste_collector, postcode, street_number, suffix, address_id, customer_id):
super().__init__(hass, waste_collector, postcode, street_number, suffix)
def __init__(self, hass, waste_collector, postcode, street_number, suffix, custom_mapping, address_id, customer_id):
super().__init__(hass, waste_collector, postcode, street_number, suffix, custom_mapping)
if self.waste_collector in self.XIMMIO_URLS.keys():
self.main_url = self.XIMMIO_URLS[self.waste_collector]
else:
Expand Down Expand Up @@ -1367,6 +1373,7 @@ def get_wastedata_from_config(hass, config):
print_waste_type = config.get(CONF_PRINT_AVAILABLE_WASTE_TYPES)
update_interval = config.get(CONF_UPDATE_INTERVAL)
customer_id = config.get(CONF_CUSTOMER_ID)
custom_mapping = config.get(CONF_CUSTOM_MAPPING)
config["id"] = _format_id(waste_collector, postcode, street_number)

if waste_collector in DEPRECATED_AND_NEW_WASTECOLLECTORS:
Expand Down Expand Up @@ -1406,6 +1413,7 @@ def get_wastedata_from_config(hass, config):
street_name,
street_number,
suffix,
custom_mapping,
address_id,
print_waste_type,
update_interval,
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.10 20240829
Current Version: 5.4.0 20240906
20230705 - Added support for Afval3xBeter
20230822 - Fix icon for papier-pmd
20230927 - Fix ZRD API
Expand Down Expand Up @@ -29,6 +29,7 @@
20240827 - Add support for Cleanprofs
20240827 - Small bug fix with configs
20240829 - Support for new ROVA API
20240906 - New option for custom mapping
Example config:
Configuration.yaml:
Expand Down Expand Up @@ -65,7 +66,7 @@
from .API import get_wastedata_from_config


__version__ = "5.3.10"
__version__ = "5.4.0"


_LOGGER = logging.getLogger(__name__)
Expand Down
2 changes: 2 additions & 0 deletions custom_components/afvalbeheer/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
CONF_PRINT_AVAILABLE_WASTE_TYPES = 'printwastetypes'
CONF_UPDATE_INTERVAL = 'updateinterval'
CONF_CUSTOMER_ID = 'customerid'
CONF_CUSTOM_MAPPING = 'custommapping'

PLATFORM_SCHEMA = vol.Schema(
{
Expand Down Expand Up @@ -59,6 +60,7 @@
vol.Optional(CONF_PRINT_AVAILABLE_WASTE_TYPES, default=False): cv.boolean,
vol.Optional(CONF_UPDATE_INTERVAL, default=0): cv.positive_int,
vol.Optional(CONF_CUSTOMER_ID, default=""): cv.string,
vol.Optional(CONF_CUSTOM_MAPPING, default={}): dict,
}, extra=vol.ALLOW_EXTRA # Allow extra required due when validating config as sensor (platform key is added to config)
)

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.10"
"version": "5.4.0"
}

0 comments on commit 6fabaf3

Please sign in to comment.