home-assistant-ecosystem / python-glances-api

Python API for interacting with Glances
MIT License
4 stars 8 forks source link

Glances v4 changes the containers structure, breaks get_ha_sensor_data #41

Closed wittypluck closed 4 months ago

wittypluck commented 4 months ago

Containers API has changed again in Glances v4: The dictionary becomes a list, which breaks get_ha_sensor_data

In v3.4: "containers":{"version":{},"version_podman":{},"containers":[ { <CONTAINER1> }, { <CONTAINER2> } ]},

In v4: "containers":[ { <CONTAINER1> }, { <CONTAINER2> } ],

https://github.com/home-assistant/core/issues/118632

On line : https://github.com/home-assistant-ecosystem/python-glances-api/blob/e2b55722b638fc3afa900b86ed724a17d2a9fbcf/glances_api/__init__.py#L173C9-L173C11

Error :

  File "/usr/local/lib/python3.12/site-packages/glances_api/__init__.py", line 173, in get_ha_sensor_data
    if data and (containers_data := data.get("containers")):
                                    ^^^^^^^^
AttributeError: 'list' object has no attribute 'get'
wittypluck commented 4 months ago

I'll see if I can submit a patch.

The workaround is to disable temporarily the containers plugin on the server side in the glances.conf: [containers] disable=True

wittypluck commented 4 months ago

Fixed in home assistant 2024.6.2: https://www.home-assistant.io/blog/2024/06/05/release-20246/#202462---june-11