Skip to content

Add Glances sensors dynamically#28639

Merged
balloob merged 10 commits into
home-assistant:devfrom
engrbm87:glances-temp-sensors
Feb 10, 2020
Merged

Add Glances sensors dynamically#28639
balloob merged 10 commits into
home-assistant:devfrom
engrbm87:glances-temp-sensors

Conversation

@engrbm87
Copy link
Copy Markdown
Contributor

@engrbm87 engrbm87 commented Nov 8, 2019

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:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly. Update and include derived files by running python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

@probot-home-assistant
Copy link
Copy Markdown

Hey there @fabaff, mind taking a look at this pull request as its been labeled with a integration (glances) you are listed as a codeowner for? Thanks!

"docker_memory_use": ["Containers RAM used", "MiB", "mdi:docker"],
}
TEMP_SENSORS = {"cpu_temp": ["CPU Temp", TEMP_CELSIUS, "mdi:thermometer"]}
CPU_TEMP = "cpu_temp"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a benefit to break it out of the existing dict in a new one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I broke it out because I don't want to create only one sensor for this type. I want to create multiple sensors.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should adjust the naming as we are no longer only working with CPU temperatures but chipsets and other peripheral hardware.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I can change this to sensor_temp. Or do you recommend another naming?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with sensor_temp.

@engrbm87 engrbm87 changed the title Add temp_sensors to glances dynamically Add Glances sensors dynamically Nov 19, 2019
@fabaff
Copy link
Copy Markdown
Member

fabaff commented Nov 28, 2019

The docs should be updated as well. I think that Integration Entities
should be adjusted or maybe better removed.

Now, it looks like a "breaking change".

Comment thread homeassistant/components/glances/sensor.py
GlancesSensor(
client,
name,
disk["mnt_point"],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we somehow also put this in SENSOR_TYPES ? Maybe a lambda with extract info: lambda item: item["mnt_point"]

Copy link
Copy Markdown
Contributor Author

@engrbm87 engrbm87 Feb 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to keep it as perfix because i use the prefix value when updating the entity in async_update

Comment thread homeassistant/components/glances/sensor.py
Comment thread homeassistant/components/glances/sensor.py
@balloob balloob merged commit c66106e into home-assistant:dev Feb 10, 2020
@lock lock Bot locked and limited conversation to collaborators Feb 12, 2020
@engrbm87 engrbm87 deleted the glances-temp-sensors branch September 16, 2022 09:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Glances sensor does not report correct CPU temp Glances is attempting to update disabled entities

4 participants