home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.64k stars 30.79k forks source link

Rova integration stopped working since latest release #110806

Closed reneposthumus closed 8 months ago

reneposthumus commented 8 months ago

The problem

Hi, it seems that the Rova integration stopped working since the latest update, but I cannot put my finger on it exactly. It comes back with an error in the logs and the sensors are gone:

`rova: Error on device update! Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 599, in _async_add_entity await entity.async_device_update(warning=False) File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1261, in async_device_update await hass.async_add_executor_job(self.update) File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, *self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/rova/sensor.py", line 116, in update self.data_service.update() File "/usr/src/homeassistant/homeassistant/util/init.py", line 190, in wrapper result = method(args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/rova/sensor.py", line 135, in update items = self.api.get_calendar_items() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/rova/rova.py", line 80, in get_calendar_items garbage_type = item["garbageTypeCode"].upper()


KeyError: 'garbageTypeCode'`

It looks like Rova changed garbageTypeCodes or the place in the JSON? Don't know exactly.

Any help would be appreciated.

René

### What version of Home Assistant Core has the issue?

core-2024.2.2

### What was the last working version of Home Assistant Core?

core-2024.2.1

### What type of installation are you running?

Home Assistant OS

### Integration causing the issue

Rova

### Link to integration documentation on our website

https://www.home-assistant.io/integrations/rova/

### Diagnostics information

_No response_

### Example YAML snippet

```yaml
- platform: rova
    zip_code: xxxxCR
    house_number: xx
    name: Rova
    monitored_conditions:
      - bio
      - plastic
      - residual
```

### Anything in the logs that might be useful for us?

```txt
rova: Error on device update!
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 599, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1261, in async_device_update
    await hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/rova/sensor.py", line 116, in update
    self.data_service.update()
  File "/usr/src/homeassistant/homeassistant/util/__init__.py", line 190, in wrapper
    result = method(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/rova/sensor.py", line 135, in update
    items = self.api.get_calendar_items()
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/rova/rova.py", line 80, in get_calendar_items
    garbage_type = item["garbageTypeCode"].upper()
                   ~~~~^^^^^^^^^^^^^^^^^^^
KeyError: 'garbageTypeCode'
```

### Additional information

_No response_
home-assistant[bot] commented 8 months ago

rova documentation rova source

niesink commented 8 months ago

It looks like Rova might've changed their json format:

  {
    "id": 311447,
    "date": "2024-02-21T00:00:00Z",
    "wasteType": {
      "id": 2,
      "code": "GFT",
      "title": "Gft",
      "icon": "gft",
      "notificationTitle": "Herinnering gft",
      "notificationText": "Morgen komen we bij je langs om jouw gft op te halen. ",
      "notificationTitleSameDay": "Herinnering gft",
      "notificationTextSameDay": "Vandaag komen we bij je langs om jouw gft op te halen. "
    },
    "isIrregular": false
  },
  {
    "id": 311448,
    "date": "2024-03-06T00:00:00Z",
    "wasteType": {
      "id": 2,
      "code": "GFT",
      "title": "Gft",
      "icon": "gft",
      "notificationTitle": "Herinnering gft",
      "notificationText": "Morgen komen we bij je langs om jouw gft op te halen. ",
      "notificationTitleSameDay": "Herinnering gft",
      "notificationTextSameDay": "Vandaag komen we bij je langs om jouw gft op te halen. "
    },
    "isIrregular": false
  },
  {
    "id": 311472,
    "date": "2024-03-12T00:00:00Z",
    "wasteType": {
      "id": 6,
      "code": "PMD",
      "title": "Pmd",
      "icon": "pmd",
      "notificationTitle": "Herinnering pmd",
      "notificationText": "Morgen komen we bij je langs om jouw pmd op te halen. ",
      "notificationTitleSameDay": "Herinnering pmd",
      "notificationTextSameDay": "Vandaag komen we bij je langs om jouw pmd op te halen. "
    },
    "isIrregular": false
  }
]

I'm not sure what the old format was and I'm not a python coder, but perhaps instead of item["garbageTypeCode"] we need to look for something like item["wasteType"]["code"] around this line?

joostlek commented 8 months ago

Happy to look into this if I have a zipcode and house number I can use

reneposthumus commented 8 months ago

Hi Luke, it indeed seems like it. I know the API is not supported by Rova at all but I think the creator of the Rova HA integration can easily change the code to match the new API response. Hopefully he is willing to do so.

reneposthumus commented 8 months ago

Happy to look into this if I have a zipcode and house number I can use

That would be great, this is a random zipcode and housenumber: 8381BE, 13

rkruisselbrink commented 8 months ago

There is a pull request that fixes this in the python library for the ROVA API, used by this integration (https://pypi.org/project/rova/): https://github.com/GidoHakvoort/rova/pull/7

ghger commented 8 months ago

I have updateted Home assistant but I have still the same error with the same log as above. Is there something else I have to do to get it working again?

PieterBoeren commented 8 months ago

It was released yesterday as part of 2024.3 (it is in the release notes), since then it's working again for me.

rkruisselbrink commented 8 months ago

The dependency update in 2024.3 did fix it!

I was working on some other features for this integration and therefore used a custom version where i didn't update the rova package 😅

ghger commented 8 months ago

Working again. Thank you!

LukasdeBoer commented 8 months ago

Unfortunately it doesn't seem to be working for Residual yet. Bio and plastic/PMD works fine but residual is still set to Unknown. image

My config:

- platform: rova
  zip_code: <redacted>
  house_number: <redacted>
  monitored_conditions:
    - bio
    - plastic
    - residual

Example JSON for residual:

        "id": 446804,
        "date": "2024-03-08T00:00:00Z",
        "wasteType": {
            "id": 1,
            "code": "RST",
            "title": "Restafval",
            "icon": "restafval",
            "notificationTitle": "Herinnering restafval",
            "notificationText": "Morgen komen we bij je langs om jouw restafval op te halen.",
            "notificationTitleSameDay": "Herinnering restafval",
            "notificationTextSameDay": "Vandaag komen we bij je langs om jouw restafval op te halen."
        },
        "isIrregular": false
    }

We probably need to add another line like this one: https://github.com/GidoHakvoort/rova/blob/master/rova/rova.py#L83 for RST. Also created https://github.com/GidoHakvoort/rova/issues/9 for consistency.

LukasdeBoer commented 8 months ago

I made a PR for Rova with a fix (https://github.com/GidoHakvoort/rova/pull/10), and got it merged into Home Assistant (https://github.com/home-assistant/core/pull/113066). The fix should be in 2024.3.1, and already is in the current dev docker image, and it's working again for residual trash here: image

LukasdeBoer commented 8 months ago

Can confirm, Home Assistant 2024.3.1 is released and it is now working for residual trash too. :tada: