Removed deprecated "device_state_attributes" for Amberelectric (#59672)

* Removed deprecated "device_state_attributes"

* Cleanup

* Postpone removal

* log deprecation warning

* Update homeassistant/helpers/entity.py

Co-authored-by: Erik Montnemery <erik@montnemery.com>

Co-authored-by: Erik Montnemery <erik@montnemery.com>
pull/59787/head
Simone Chemelli 2021-11-16 16:11:46 +01:00 committed by GitHub
parent 4387bbfb94
commit 8a02d87a17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 5 deletions

View File

@ -61,7 +61,7 @@ class AmberPriceSpikeBinarySensor(AmberPriceGridSensor):
return self.coordinator.data["grid"]["price_spike"] == "spike"
@property
def device_state_attributes(self) -> Mapping[str, Any] | None:
def extra_state_attributes(self) -> Mapping[str, Any] | None:
"""Return additional pieces of information about the price spike."""
spike_status = self.coordinator.data["grid"]["price_spike"]

View File

@ -86,7 +86,7 @@ class AmberPriceSensor(AmberSensor):
return format_cents_to_dollars(interval.per_kwh)
@property
def device_state_attributes(self) -> Mapping[str, Any] | None:
def extra_state_attributes(self) -> Mapping[str, Any] | None:
"""Return additional pieces of information about the price."""
interval = self.coordinator.data[self.entity_description.key][self.channel_type]
@ -133,7 +133,7 @@ class AmberForecastSensor(AmberSensor):
return format_cents_to_dollars(interval.per_kwh)
@property
def device_state_attributes(self) -> Mapping[str, Any] | None:
def extra_state_attributes(self) -> Mapping[str, Any] | None:
"""Return additional pieces of information about the price."""
intervals = self.coordinator.data[self.entity_description.key].get(
self.channel_type

View File

@ -515,7 +515,15 @@ class Entity(ABC):
attr.update(self.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
# Warning added in 2021.12, will be removed in 2022.4
if self.device_state_attributes is not None:
report_issue = self._suggest_report_issue()
_LOGGER.warning(
"Entity %s (%s) implements device_state_attributes. Please %s",
self.entity_id,
type(self),
report_issue,
)
if extra_state_attributes is None:
extra_state_attributes = self.device_state_attributes
attr.update(extra_state_attributes or {})

View File

@ -164,7 +164,6 @@ async def test_general_and_feed_in_price_sensor(
) -> None:
"""Test the Feed In sensor."""
assert len(hass.states.async_all()) == 6
print(hass.states)
price = hass.states.get("sensor.mock_title_feed_in_price")
assert price
assert price.state == "-0.08"