Add Glances sensors dynamically#28639
Conversation
| "docker_memory_use": ["Containers RAM used", "MiB", "mdi:docker"], | ||
| } | ||
| TEMP_SENSORS = {"cpu_temp": ["CPU Temp", TEMP_CELSIUS, "mdi:thermometer"]} | ||
| CPU_TEMP = "cpu_temp" |
There was a problem hiding this comment.
I don't see a benefit to break it out of the existing dict in a new one.
There was a problem hiding this comment.
I broke it out because I don't want to create only one sensor for this type. I want to create multiple sensors.
There was a problem hiding this comment.
You are doing a lookup for every sensor that will be created thus it doesn't matter if you stick with SENSOR_TYPES or use the new TEMP_SENSORS dict. The lookup is performed for the same key but for different dicts.
There was a problem hiding this comment.
I have updated the code so that sensors are added dynamically based on the collected data from glances_api.
For fs in case of multiple detected disks all will be added.
For sensors also all sensors are added.
For sensor_types whose key doesn't have values the sensor is not added at all.
| for sensor in glances_data.api.data["sensors"]: | ||
| dev.append( | ||
| GlancesSensor( | ||
| glances_data, name, sensor["label"], CPU_TEMP, TEMP_SENSORS[CPU_TEMP] |
There was a problem hiding this comment.
We should adjust the naming as we are no longer only working with CPU temperatures but chipsets and other peripheral hardware.
There was a problem hiding this comment.
Ok, I can change this to sensor_temp. Or do you recommend another naming?
|
The docs should be updated as well. I think that Integration Entities Now, it looks like a "breaking change". |
| GlancesSensor( | ||
| client, | ||
| name, | ||
| disk["mnt_point"], |
There was a problem hiding this comment.
Can we somehow also put this in SENSOR_TYPES ? Maybe a lambda with extract info: lambda item: item["mnt_point"]
There was a problem hiding this comment.
I need to keep it as perfix because i use the prefix value when updating the entity in async_update
…into glances-temp-sensors
…into glances-temp-sensors
Breaking Change:
Glances sensors are now dynamically added. Especially sensors for mounted disks and temperature sensors.
Description:
This PR adds Glances sensors dynamically based on the collected data from glances_api.
Also unsubscribe from signal updates when entity is disabled.
Related issue (if applicable): fixes #28480, fixes #28441
Pull request with documentation for home-assistant.io (if applicable): home-assistant/home-assistant.io#11352
Checklist:
tox. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
python3 -m script.hassfest.requirements_all.txtby runningpython3 -m script.gen_requirements_all..coveragerc.If the code does not interact with devices: