Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicate unique id in System Monitor (again) #107947

Merged
merged 1 commit into from
Jan 13, 2024

Conversation

gjohansson-ST
Copy link
Member

Proposed change

Fixes the duplicate unique id issue in System Monitor.
Need to slugify the combined type and argument or it might return unknown on argument only when the result is ""

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

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.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

Copy link
Contributor

@jbouwh jbouwh left a comment

Choose a reason for hiding this comment

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

Not seeing issues in the logs. I was not able to reproduce the issue. But the change is okay imo.
Thnx @gjohansson-ST 👍

@gjohansson-ST
Copy link
Member Author

It only produce this error on root mount points / and if you have YAML imported so therefore I missed it also in the previous case.

@gjohansson-ST gjohansson-ST merged commit c49246d into dev Jan 13, 2024
23 checks passed
@gjohansson-ST gjohansson-ST deleted the systemmonitor-fix-duplicates branch January 13, 2024 12:48
@glcos
Copy link
Contributor

glcos commented Jan 13, 2024

@gjohansson-ST

It only produce this error on root mount points / and if you have YAML imported so therefore I missed it also in the previous case.

This is my exact case.
I replaced sensor.py with latest version but still have the same error in the log file

2024-01-13 14:29:30.089 ERROR (SyncWorker_4) [homeassistant.components.systemmonitor.sensor] Error updating sensor: disk_use_percent (/run/user/1000)
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/components/systemmonitor/sensor.py", line 523, in _update_sensors
    state, value, update_time = _update(type_, data)
                                ^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/components/systemmonitor/sensor.py", line 632, in _update
    state = _disk_usage(data.argument).percent
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/components/systemmonitor/sensor.py", line 724, in _disk_usage
    return psutil.disk_usage(path)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.11/site-packages/psutil/__init__.py", line 2012, in disk_usage
    return _psplatform.disk_usage(path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.11/site-packages/psutil/_psposix.py", line 177, in disk_usage
    st = os.statvfs(path)
         ^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/run/user/1000'

@gjohansson-ST
Copy link
Member Author

@gjohansson-ST

It only produce this error on root mount points / and if you have YAML imported so therefore I missed it also in the previous case.

This is my exact case. I replaced sensor.py with latest version but still have the same error in the log file

Sure, as it's using util.py for which sensors it should create.
It also says File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/components/systemmonitor/sensor.py", line 724 and that's not on line 724 anymore so you're not using the latest file.
But if you have issues please make an issue and don't dilute the PR's!

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.

System Monitor - Unique ID for disk sensor
4 participants