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 KeyError from zwave_js diagnostics #74579

Merged
merged 1 commit into from
Jul 8, 2022

Conversation

kpine
Copy link
Contributor

@kpine kpine commented Jul 7, 2022

Proposed change

Fixes an issue when attempting to download the Device diagnostics for a Z-Wave JS Device. If one of the Device's entities has a missing primary value, a KeyError is raised and the file fails to download. This change prevents the error and allows the file to be downloaded as usual.

If the primary value is unknown, the "primary_value" in the diagnostic data is replaced with None, to signify the information is missing.

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)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

I discovered this problem in my own production system while investigating the related issue.

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
  • The code has been formatted using Black (black --fast 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.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

@probot-home-assistant
Copy link

Hey there @home-assistant/z-wave, mind taking a look at this pull request as it has been labeled with an integration (zwave_js) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

"property_key_name": value.property_key_name,
}

# make the entity's primary value go missing
Copy link
Member

Choose a reason for hiding this comment

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

When does this happen normally?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reasons I can think of:

  1. A driver update that removes previous functionality. This happened in the past with alarm level and type values, that were removed by the driver in favor of notification values.
  2. A re-interview that failed. When you re-interview a device, the driver removes all of the values. If the interview fails in any way, the device still becomes ready but the previous values won't be recreated.
  3. A firmware upgrade or device-reconfiguration, which could disable previous functionality (I have a rely that can change exposed sensors based on configuration). Upon re-interview, the values would be lost.

Case 1 is the problem in my production system, as mentioned in the linked issue. This sensor has been included since first using Z-Wave JS, and I've never pruned the entities.

Case 2 is likely the cause for another of my Zooz water sensors as some of their devices are known to have interview failures. I'm pretty sure I was re-interviewing nodes during testing, and this happened.

Also, I'm only using the "value removed" event to cause the problem in the test. In most real-life cases, it's just going to be the node state dump on connection is missing the value. I could also just delete the value directly from the Node instance, but manipulating these data structures directly doesn't seem to be common in the tests.

Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Thanks!

@MartinHjelmare MartinHjelmare merged commit c27fbce into home-assistant:dev Jul 8, 2022
@MartinHjelmare MartinHjelmare added this to the 2022.7.2 milestone Jul 8, 2022
bachya pushed a commit to bachya/home-assistant that referenced this pull request Jul 9, 2022
@kpine kpine deleted the diagnostic-key-error branch July 9, 2022 20:06
@MartinHjelmare MartinHjelmare modified the milestones: 2022.7.2, 2022.7.3 Jul 10, 2022
@balloob balloob mentioned this pull request Jul 10, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jul 11, 2022
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.

4 participants