Replace Entity.device_state_attributes with Entity.extra_state_attributes (#837)

Co-authored-by: Erik Montnemery <erik@montnemery.com>
This commit is contained in:
Franck Nijhof 2021-03-09 15:05:23 +01:00 committed by GitHub
parent 69047ad792
commit dd7b026064
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 6 deletions

View File

@ -104,7 +104,7 @@ Properties should always only return information from memory and not do I/O (lik
| assumed_state | boolean | `False` | Return `True` if the state is based on our assumption instead of reading it from the device. |
| available | boolean | `True` | Indicate if Home Assistant is able to read the state and control the underlying device. |
| device_class | string | `None` | Extra classification of what the device is. Each domain specifies their own. Device classes can come with extra requirements for unit of measurement and supported features. |
| device_state_attributes | dict | `None` | Extra information to store in the state machine. It needs to be information that further explains the state, it should not be static information like firmware version. |
| extra_state_attributes | dict | `None` | Extra information to store in the state machine. It needs to be information that further explains the state, it should not be static information like firmware version. |
| entity_picture | URL | `None` | Url of a picture to show for the entity. |
| name | string | `None` | Name of the entity |
| should_poll | boolean | `True` | Should Home Assistant check with the entity for an updated state. If set to `False`, entity will need to notify Home Assistant of new updates by calling one of the [schedule update methods](#methods). |

View File

@ -114,16 +114,17 @@ After a start or a restart of Home Assistant the component will be visible in th
<img src='/img/en/development/create-component01.png' />
</p>
In order to expose attributes for a platform, you will need to define a property called `device_state_attributes` on the entity class, which will return a dictionary of attributes:
In order to expose attributes for a platform, you will need to define a property called `extra_state_attributes` on the entity class, which will return a dictionary of attributes:
```python
@property
def device_state_attributes(self):
"""Return device specific state attributes."""
def extra_state_attributes(self):
"""Return entity specific state attributes."""
return self._attributes
```
:::tip
Entities also have a similar property `state_attributes`, which normally doesn't need to be defined by new platforms. This property is used by base components to add standard sets of attributes to a state. Example: The light component uses `state_attributes` to add brightness to the state dictionary. If you are designing a new component, you should define `state_attributes` instead.
Entities also have a similar property `state_attributes`, which should not be overridden by integrations. This property is used by base entity components to add standard sets of attributes to a state. Example: The light component uses `state_attributes` to add brightness to the state dictionary. If you are designing a new integration, you should define `extra_state_attributes` instead.
:::
To get your component included in the Home Assistant releases, follow the steps described in the [Submit your work](development_submitting.md) section. Basically you only need to move your component into the `homeassistant/component/` directory of your fork and create a Pull Request.
To get your integration included in the Home Assistant releases, follow the steps described in the [Submit your work](development_submitting.md) section. Basically you only need to move your integration into the `homeassistant/component/` directory of your fork and create a Pull Request.