pippyn / Home-Assistant-Sensor-Afvalbeheer

Provides Home Assistant sensors for multiple Dutch and Belgium waste collectors
Apache License 2.0
287 stars 87 forks source link

Almere: Support "GFT and Rest" combined container #433

Closed brodock closed 10 months ago

brodock commented 11 months ago

Almere uses the ximmio provider. See the snippet from the GetCalendar response below:

{
    "userMessage": {
        "type": null,
        "messageCode": 0,
        "description": null
    },
    "ExtraOption": {
        "$type": "System.Dynamic.ExpandoObject, System.Core"
    },
    "dataList": [
        {
            "pickupDates": [
                "..."
            ],
            "pickupType": 18,
            "_pickupType": 18,
            "_pickupTypeText": "GREENGREY",
            "description": "DUO vrijdag even 2"
        },
    ],
    "intDataList": null,
    "data": null,
    "status": true,
    "messageCode": 107,
    "pdfResponse": null,
    "token": null,
    "ID": null,
    "invalidParameters": null,
    "total": 0,
    "messageToString": null
}

This is currently not supported.

imagem
pippyn commented 11 months ago

Did you try the print waste types option this sensor has? Because all fractions should be supported

brodock commented 11 months ago

@pippyn Thanks, it seems the combined is being handled as GFT

Available waste types: gft, papier, pmd, restafval

It seems they are going to replace the combined GFT and Restafval by separate ones in 2024... this are the items I see in the almere afvalkalendar

imagem

I couldn't find in the code where it is handling the "GREENGREY" as "GREEN", perhaps its doing a partial match?

brodock commented 11 months ago

I think this is the case indeed:

    def map_waste_type(self, name):
        for from_type, to_type in self.WASTE_TYPE_MAPPING.items():
            if from_type.lower() in name.lower():
                return to_type
        return name.lower()

I've tried to add the GREENGREY here:

class XimmioCollector(WasteCollector):
    WASTE_TYPE_MAPPING = {
        'BRANCHES': WASTE_TYPE_BRANCHES,
        'BULKLITTER': WASTE_TYPE_BULKLITTER,
        'BULKYGARDENWASTE': WASTE_TYPE_BULKYGARDENWASTE,
        'GLASS': WASTE_TYPE_GLASS,
        'GREEN': WASTE_TYPE_GREEN,
        'GREENGREY': WASTE_TYPE_GREENGREY,
        'GREY': WASTE_TYPE_GREY,
        'KCA': WASTE_TYPE_KCA,
        'PLASTIC': WASTE_TYPE_PACKAGES,
        'PACKAGES': WASTE_TYPE_PACKAGES,
        'PAPER': WASTE_TYPE_PAPER,
        'REMAINDER': WASTE_TYPE_REMAINDER,
        'TEXTILE': WASTE_TYPE_TEXTILE,
        'TREE': WASTE_TYPE_TREE,
    }

and it still flags it as GFT

brodock commented 11 months ago

Considering all the waste types:

WASTE_TYPE_BRANCHES = 'takken'
WASTE_TYPE_BULKLITTER = 'grofvuil'
WASTE_TYPE_GLASS = 'glas'
WASTE_TYPE_GREEN = 'gft'
WASTE_TYPE_GREENGREY = 'duobak'
WASTE_TYPE_GREY = 'restafval'
WASTE_TYPE_GREY_BAGS = 'restafvalzakken'
WASTE_TYPE_SORTI = 'sortibak'
WASTE_TYPE_KCA = 'chemisch'
WASTE_TYPE_KCA_LOCATION = 'chemisch-brengen'
WASTE_TYPE_MILIEUB = 'milieuboer'
WASTE_TYPE_PAPER_PMD = 'papier-pmd'
WASTE_TYPE_PMD_GREY = 'pmd-restafval'
WASTE_TYPE_PACKAGES = 'pmd'
WASTE_TYPE_PAPER = 'papier'
WASTE_TYPE_PLASTIC = 'plastic'
WASTE_TYPE_SOFT_PLASTIC = 'zacht-plastic'
WASTE_TYPE_REMAINDER = 'restwagen'
WASTE_TYPE_TEXTILE = 'textiel'
WASTE_TYPE_TREE = 'kerstbomen'
WASTE_TYPE_BULKYGARDENWASTE = 'tuinafval'

I think those are the ones that will not work when using in to compare:

WASTE_TYPE_GREEN = 'gft'
WASTE_TYPE_GREENGREY = 'duobak' # this will never match because `WASTE_TYPE_GREEN` matches first
WASTE_TYPE_GREY = 'restafval'
WASTE_TYPE_GREY_BAGS = 'restafvalzakken' # this will never match because `WASTE_TYPE_GREY` matches first

as long as they are in the "wrong order" they will fail

pippyn commented 10 months ago

This will be included in the next release