8000 Allow MQTT entities to be disabled by default by emontnemery · Pull Request #48284 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Allow MQTT entities to be disabled by default 8000 #48284

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

Merged
merged 2 commits into from
Mar 29, 2021

Conversation

emontnemery
Copy link
Contributor
@emontnemery emontnemery commented Mar 24, 2021

Proposed change

Allow MQTT entities to be disabled by default

The purpose is to allow sub entities, for example a signal strength sensor for a zigbee light, to be hidden until actively enabled by the use.

Any disabled entities will be removed together with the device when the last enabled entity is removed through MQTT discovery.

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 discovery message:

{
  "platform": "mqtt",
  "name": "RSSI sensor",
  "state_topic": "test-topic",
  "device": {"identifiers": ["123"]},
  "enabled_by_default": false,
  "unique_id": "veryunique"
}

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:

@emontnemery
Copy link
Contributor Author

@Koenkk can you comment on if this would be useful for zigbee2mqtt? the idea is that the signal strength sensor (for example) is announced Home Assistant, but the user has to opt-in by enabling it

@Koenkk
Copy link
Contributor
Koenkk commented Mar 24, 2021

@emontnemery the feature looks useful but I haven't seen anyone requesting this yet.

@frenck
Copy link
Member
frenck commented Mar 24, 2021

@Koenkk It is a relatively recent feature. We try to disable/hide the less common things by default. It helps with things like performance, reduces the amount of historical data and keeps the state engine cleaner.

@Koenkk
Copy link
Contributor
Koenkk commented Mar 24, 2021

I guess this indeed makes sense for e.g. the linkquality sensor, the values changes often while probably (almost) nobody looks at it. For the Zigbee2MQTT use case this linkquality can also be viewed via the "main" entity of the device (e.g. light) since the linkquality is included in the json_attributes_topic.

@frenck
Copy link
Member
frenck commented Mar 24, 2021

For the Zigbee2MQTT use case this linkquality can also be viewed via the "main" entity of the device (e.g. light) since the linkquality is included in the json_attributes_topic.

That should actually be removed... as that is a different measurement and should have its own entity (disabled by default 😉 ). We are phasing out state attributes that should have been their own sensor in general. Those attributes still trigger unneeded state changes for their entities.

@Koenkk
Copy link
Contributor
Koenkk commented Mar 24, 2021

@frenck will json_attributes_topic become deprecated?

@emontnemery
Copy li 8000 nk
Contributor Author

will json_attributes_topic become deprecated

There's no such plan (that I'm aware of), but the attributes are not meant for providing sub sensors, stuff like signal quality etc. should live in their own sensors

@frenck
Copy link
Member
frenck commented Mar 24, 2021

No direct plan on deprecating those. We, however, reject "sensors" hidden in state attributes for new integrations or integrations that are refactored. It's simply harder for the end-user to control/use them (+ all the other stuff mentioned before).

With the introduction of the concept of devices, it became no needed anymore as well.

@property
def entity_registry_enabled_default(self) -> bool:
"""Return if the entity should be enabled when first added to the entity registry."""
return self._config.get(CONF_ENABLED_BY_DEFAULT)
Copy link
Member

Choose a reason for hidi 8000 ng this comment

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

Since the key is always there, use square brackets. If you want to have teh default live here and not in the config schema, remove default=True from MQTT_ENTITY_COMMON_SCHEMA

@emontnemery emontnemery merged commit 8ad3c65 into home-assistant:dev Mar 29, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Mar 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
403B
Development

Successfully merging this pull request may close these issues.

5 participants
0