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
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 1 addition & 3 deletions homeassistant/components/huawei_lte/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,8 @@ def entity_registry_enabled_default(self) -> bool:
@property
def device_state_attributes(self) -> Optional[Dict[str, Any]]:
"""Get additional attributes related to connection status."""
attributes = super().device_state_attributes
attributes = {}
if self._raw_state in CONNECTION_STATE_ATTRIBUTES:
if attributes is None:
attributes = {}
attributes["additional_state"] = CONNECTION_STATE_ATTRIBUTES[
self._raw_state
]
Expand Down
22 changes: 18 additions & 4 deletions homeassistant/helpers/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,23 @@ def capability_attributes(self) -> Optional[Dict[str, Any]]:
def state_attributes(self) -> Optional[Dict[str, Any]]:
"""Return the state attributes.

Implemented by component base class. Convention for attribute names
is lowercase snake_case.
Implemented by component base class, should not be extended by integrations.
Convention for attribute names is lowercase snake_case.
"""
return None

@property
def device_state_attributes(self) -> Optional[Dict[str, Any]]:
"""Return device specific state attributes.
"""Return entity specific state attributes.

This method is deprecated, platform classes should implement
extra_state_attributes instead.
"""
return None

@property
def extra_state_attributes(self) -> Optional[Dict[str, Any]]:
"""Return entity specific state attributes.

Implemented by platform classes. Convention for attribute names
is lowercase snake_case.
Expand Down Expand Up @@ -319,7 +328,12 @@ def _async_write_ha_state(self) -> None:
sstate = self.state
state = STATE_UNKNOWN if sstate is None else str(sstate)
attr.update(self.state_attributes or {})
attr.update(self.device_state_attributes or {})
extra_state_attributes = self.extra_state_attributes
# Backwards compatibility for "device_state_attributes" deprecated in 2021.4
# Add warning in 2021.6, remove in 2021.10
if extra_state_attributes is None:
extra_state_attributes = self.device_state_attributes
attr.update(extra_state_attributes or {})

unit_of_measurement = self.unit_of_measurement
if unit_of_measurement is not None:
Expand Down