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

Add check that sensors don't have EntityCategory.CONFIG set #101471

Merged
merged 4 commits into from
Oct 9, 2023

Conversation

edenhaus
Copy link
Contributor

@edenhaus edenhaus commented Oct 5, 2023

Breaking change

Proposed change

Sensors cannot have EntityCategory.CONFIG as they cannot change anything.
Add a check for it and fix nextcloud, mqtt and esphome

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

  • 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
  • I have followed the perfect PR recommendations
  • 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.

To help with the load of incoming pull requests:

@home-assistant
Copy link

home-assistant bot commented Oct 5, 2023

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

Code owner commands

Code owners of nextcloud 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 nextcloud Removes the current integration label and assignees on the pull request, add the integration domain after the command.

@home-assistant
Copy link

home-assistant bot commented Oct 5, 2023

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

Code owner commands

Code owners of sensor 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 sensor Removes the current integration label and assignees on the pull request, add the integration domain after the command.

@edenhaus edenhaus changed the title Add check that sensor don't have EntityCategory.CONFIG set Add check that sensors don't have EntityCategory.CONFIG set Oct 5, 2023
@edenhaus edenhaus marked this pull request as draft October 5, 2023 14:26
jbouwh
jbouwh previously requested changes Oct 5, 2023
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.

The entity_category is a settable attribute for MQTT entities. That includes MQTT sensors.
So If we want to correct this we should deprecate the setting for use on sensor and binary sensors.
I am not sure about this change.

tests/components/mqtt/test_common.py Outdated Show resolved Hide resolved
@frenck
Copy link
Member

frenck commented Oct 6, 2023

The entity_category is a settable attribute for MQTT entities. That includes MQTT sensors.

That is not going away. It only raises in case an CONFIG entity category is used for an sensor entity.

The reason is because, the configuration category is for read/write entities that control things. A sensor can never control things (and thus the change triggering because of this change are incorrect to begin with). The function of the entity categories has been documented correctly from the start.

../Frenck

@jbouwh jbouwh dismissed their stale review October 6, 2023 18:01

no reason to hold the PR

Copy link
Contributor

@mib1185 mib1185 left a comment

Choose a reason for hiding this comment

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

I'm fine with the changes in nextcloud 👍

@edenhaus edenhaus marked this pull request as ready for review October 9, 2023 11:32
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, @edenhaus 👍

../Frenck

@frenck frenck merged commit f7292d5 into dev Oct 9, 2023
31 checks passed
@frenck frenck deleted the edenhaus-sensor-entity-category-config branch October 9, 2023 11:37
@github-actions github-actions bot locked and limited conversation to collaborators Oct 10, 2023
@elupus
Copy link
Contributor

elupus commented Nov 5, 2023

This is a breaking change in my opinion. It really should have been a warning with a depreciation period. Next integration with issue being z2m: #103414

Ps. Its not explicitly stated its illegal to set on sensor entities. It make sense for readonly settings (controlled on device only).

Im not against the change, just that its a change that break existing setups. We could just have ignored the value.

@frenck
Copy link
Member

frenck commented Nov 5, 2023

It is not, this has been correctly documented as well. Diagnostic entities are read only, while config can write, as per dev docs. Sensor entities are thus never configured as they are read only.

Z2M has been adjusted upstream accordingly and the maintainers informed prior stable release.

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.

5 participants