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 yolink entity descriptions #106649

Merged
merged 1 commit into from Dec 29, 2023
Merged

Fix yolink entity descriptions #106649

merged 1 commit into from Dec 29, 2023

Conversation

emontnemery
Copy link
Contributor

@emontnemery emontnemery commented Dec 29, 2023

Proposed change

Fix yolink entity descriptions

I'm not able to test this live. However, the dataclass creation fails by just importing:

$ python3
>>> from homeassistant.components.yolink import sensor
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/erik/development/home-assistant_fork/homeassistant/components/yolink/sensor.py", line 58, in <module>
    @dataclass(frozen=True)
     ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/erik/.pyenv/versions/3.11.5/lib/python3.11/dataclasses.py", line 1224, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/erik/.pyenv/versions/3.11.5/lib/python3.11/dataclasses.py", line 1031, in _process_class
    _init_fn(all_init_fields,
  File "/home/erik/.pyenv/versions/3.11.5/lib/python3.11/dataclasses.py", line 549, in _init_fn
    raise TypeError(f'non-default argument {f.name!r} '
TypeError: non-default argument 'key' follows default argument

With the fix in this PR, the dataclass creation works fine.

The problem is that the mixin has a field with a default value. Mixin classes are normally added to EntityDescription subclasses to make it possible to add fields without default values.

yolink is the only integration in core I could find which has such a mixin.

It's possible to make the yolink pattern work by relying on dataclass inheritance if a parent adds a field with a default value.

However, relying on dataclass inheritance means it's no longer possible to create mutable dataclasses, so I'm not sure there's any benefit; any custom integration relying on the same pattern would still break unless the author change to frozen entity descriptions and we might break additional custom integrations.

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:

@home-assistant
Copy link

Hey there @matrixd2, mind taking a look at this pull request as it has been labeled with an integration (yolink) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of yolink can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign yolink Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

Copy link
Member

@frenck frenck left a comment

Choose a reason for hiding this comment

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

Thanks, @emontnemery 👍

../Frenck

@frenck frenck merged commit 95d7a66 into dev Dec 29, 2023
23 checks passed
@frenck frenck deleted the yolink_fix_entity_descriptions branch December 29, 2023 12:22
@github-actions github-actions bot locked and limited conversation to collaborators Dec 30, 2023
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.

YoLink sensors missing after HA core update
2 participants