diff --git a/homeassistant/components/huawei_lte/binary_sensor.py b/homeassistant/components/huawei_lte/binary_sensor.py index 9a5f148d1388d7..ea9d68bc843e54 100644 --- a/homeassistant/components/huawei_lte/binary_sensor.py +++ b/homeassistant/components/huawei_lte/binary_sensor.py @@ -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 ] diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index 7d0e38ab119bff..7afe1b2ad25293 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -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. @@ -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: