mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
Replace Entity.device_state_attributes with Entity.extra_state_attributes (#47304)
This commit is contained in:
parent
19f67335ec
commit
3a054c3be7
@ -144,10 +144,8 @@ class HuaweiLteMobileConnectionBinarySensor(HuaweiLteBaseBinarySensor):
|
|||||||
@property
|
@property
|
||||||
def device_state_attributes(self) -> Optional[Dict[str, Any]]:
|
def device_state_attributes(self) -> Optional[Dict[str, Any]]:
|
||||||
"""Get additional attributes related to connection status."""
|
"""Get additional attributes related to connection status."""
|
||||||
attributes = super().device_state_attributes
|
attributes = {}
|
||||||
if self._raw_state in CONNECTION_STATE_ATTRIBUTES:
|
if self._raw_state in CONNECTION_STATE_ATTRIBUTES:
|
||||||
if attributes is None:
|
|
||||||
attributes = {}
|
|
||||||
attributes["additional_state"] = CONNECTION_STATE_ATTRIBUTES[
|
attributes["additional_state"] = CONNECTION_STATE_ATTRIBUTES[
|
||||||
self._raw_state
|
self._raw_state
|
||||||
]
|
]
|
||||||
|
@ -160,14 +160,23 @@ class Entity(ABC):
|
|||||||
def state_attributes(self) -> Optional[Dict[str, Any]]:
|
def state_attributes(self) -> Optional[Dict[str, Any]]:
|
||||||
"""Return the state attributes.
|
"""Return the state attributes.
|
||||||
|
|
||||||
Implemented by component base class. Convention for attribute names
|
Implemented by component base class, should not be extended by integrations.
|
||||||
is lowercase snake_case.
|
Convention for attribute names is lowercase snake_case.
|
||||||
"""
|
"""
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self) -> Optional[Dict[str, Any]]:
|
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
|
Implemented by platform classes. Convention for attribute names
|
||||||
is lowercase snake_case.
|
is lowercase snake_case.
|
||||||
@ -319,7 +328,12 @@ class Entity(ABC):
|
|||||||
sstate = self.state
|
sstate = self.state
|
||||||
state = STATE_UNKNOWN if sstate is None else str(sstate)
|
state = STATE_UNKNOWN if sstate is None else str(sstate)
|
||||||
attr.update(self.state_attributes or {})
|
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
|
unit_of_measurement = self.unit_of_measurement
|
||||||
if unit_of_measurement is not None:
|
if unit_of_measurement is not None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user