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

Clarify state attributes rules for entity #2437

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/core/entity.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ The following properties are also available on entities. However, they are for a
| state_attributes | <code>dict &#124; None</code> | `None` | State attributes of a base domain. This property is implemented by the domain base entity and should not be implemented by integrations.
| unit_of_measurement | <code>str &#124; None</code> | The unit of measurement that the entity's state is expressed in. In most cases, for example for the `number` and `sensor` domains, this is implemented by the domain base entity and should not be implemented by integrations.

## State attributes

Entities can provide additional state attributes besides the built-in ones, to provide further details to it's state.
gjohansson-ST marked this conversation as resolved.
Show resolved Hide resolved
This should be done by providing a dictionary with keys and values to the `extra_state_attributes` property.

Providing additional state attributes comes with some rules:
gjohansson-ST marked this conversation as resolved.
Show resolved Hide resolved

- If an attribute is expected, it should be in the dictionary. Attributes should not "come and go".
- If an attribute is expected, but it's not providing a value right now, its value should be `None` and remain in the dictionary
gjohansson-ST marked this conversation as resolved.
Show resolved Hide resolved
- If an attributes is not expected, it should not be in the dictionary. As example, only some attributes might provide additional context to the state when the entity runs with a certain configuration.
gjohansson-ST marked this conversation as resolved.
Show resolved Hide resolved

## System properties

The following properties are used and controlled by Home Assistant, and should not be overridden by integrations.
Expand Down