From 05590f63c96de55812962a34eb355bdc8206876d Mon Sep 17 00:00:00 2001 From: Eugenio Panadero Date: Thu, 12 Jan 2023 03:21:16 +0100 Subject: [PATCH] Clean attributes in pvpc hourly pricing ElecPriceSensor (#85688) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ♻️ Remove unnecessary private attrs and fix typing for sensor entity --- homeassistant/components/pvpc_hourly_pricing/sensor.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/pvpc_hourly_pricing/sensor.py b/homeassistant/components/pvpc_hourly_pricing/sensor.py index 4792b6d9269..56b77dec401 100644 --- a/homeassistant/components/pvpc_hourly_pricing/sensor.py +++ b/homeassistant/components/pvpc_hourly_pricing/sensor.py @@ -148,8 +148,6 @@ class ElecPriceSensor(CoordinatorEntity[ElecPricesDataUpdateCoordinator], Sensor manufacturer="REE", name="ESIOS API", ) - self._state: StateType = None - self._attrs: Mapping[str, Any] = {} async def async_added_to_hass(self) -> None: """Handle entity which will be added.""" @@ -179,18 +177,16 @@ class ElecPriceSensor(CoordinatorEntity[ElecPricesDataUpdateCoordinator], Sensor @property def native_value(self) -> StateType: """Return the state of the sensor.""" - self._state = self.coordinator.api.states.get(self.entity_description.key) - return self._state + return self.coordinator.api.states.get(self.entity_description.key) @property - def extra_state_attributes(self) -> Mapping[str, Any] | None: + def extra_state_attributes(self) -> Mapping[str, Any]: """Return the state attributes.""" sensor_attributes = self.coordinator.api.sensor_attributes.get( self.entity_description.key, {} ) - self._attrs = { + return { _PRICE_SENSOR_ATTRIBUTES_MAP[key]: value for key, value in sensor_attributes.items() if key in _PRICE_SENSOR_ATTRIBUTES_MAP } - return self._attrs