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

Replace Entity.device_state_attributes with Entity.extra_state_attributes #47304

Merged
merged 4 commits into from
Mar 9, 2021

Conversation

emontnemery
Copy link
Contributor

@emontnemery emontnemery commented Mar 3, 2021

Proposed change

Replace Entity.device_state_attributes with Entity.extra_state_attributes.
The name device_state_attributes is confusing and the actual device attributes are available from Entity.device_info.

To be backwards compatible, Entity.device_state_attributes is still called if it is implemented and Entity.extra_state_attributes returns None.

Planned follow-up PRs:

Suggested plan for deprecation:

  • Start logging a warning in 2021.6
  • Remove backwards compatibility in 2021.10

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

Example entry for configuration.yaml:

# Example configuration.yaml

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

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.
  • 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 probot-home-assistant bot added core small-pr PRs with less than 30 lines. labels Mar 3, 2021
@frenck frenck self-requested a review March 4, 2021 08:26
@frenck
Copy link
Member

frenck commented Mar 8, 2021

I think this makes sense, however, this also opens up the opportunity to do something about

state_attributes versus device_state_attributes/entity_state_attributes.

Out developer documentation does not really help either as it seems 😓

image

And a quick search through our codebase, it is all used mixed up 😢

For example, the twinkly integration actually defines a state_attributes property, while lights is a platform that actually implements that (so it has non-default behavior now, which is not wished for either).

@emontnemery
Copy link
Contributor Author

this also opens up the opportunity to do something about state_attributes versus device_state_attributes/entity_state_attributes.

You mean integrations which override state_attributes instead of device_state_attributes/entity_state_attributes should be updated? Sure, that should be done as well, but maybe not in this PR?

@frenck
Copy link
Member

frenck commented Mar 8, 2021

No, I mean; maybe we can reduce it to a single thing: state_attributes. In that case; it won't be confusing anymore. My concern is that having entity_state_attributes and state_attributes both; would still be confusing.

@emontnemery
Copy link
Contributor Author

emontnemery commented Mar 9, 2021

After some discussion, the conclusion is:

  • Keep state_attributes but make it clearer it should not be overridden
  • Rename Entity.device_state_attributes to Entity.extra_state_attributes

@emontnemery emontnemery changed the title Replace Entity.device_state_attributes with Entity.entity_state_attributes Replace Entity.device_state_attributes with Entity.extra_state_attributes Mar 9, 2021
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.

✅ LGTM

@frenck
Copy link
Member

frenck commented Mar 9, 2021

Created a documentation PR in: home-assistant/developers.home-assistant#837

@frenck frenck merged commit 3a054c3 into home-assistant:dev Mar 9, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Mar 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla-signed core small-pr PRs with less than 30 lines.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants