Clean attributes in pvpc hourly pricing ElecPriceSensor (#85688)

♻️ Remove unnecessary private attrs and fix typing for sensor entity
This commit is contained in:
Eugenio Panadero 2023-01-12 03:21:16 +01:00 committed by GitHub
parent 2757f97114
commit 05590f63c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -148,8 +148,6 @@ class ElecPriceSensor(CoordinatorEntity[ElecPricesDataUpdateCoordinator], Sensor
manufacturer="REE", manufacturer="REE",
name="ESIOS API", name="ESIOS API",
) )
self._state: StateType = None
self._attrs: Mapping[str, Any] = {}
async def async_added_to_hass(self) -> None: async def async_added_to_hass(self) -> None:
"""Handle entity which will be added.""" """Handle entity which will be added."""
@ -179,18 +177,16 @@ class ElecPriceSensor(CoordinatorEntity[ElecPricesDataUpdateCoordinator], Sensor
@property @property
def native_value(self) -> StateType: def native_value(self) -> StateType:
"""Return the state of the sensor.""" """Return the state of the sensor."""
self._state = self.coordinator.api.states.get(self.entity_description.key) return self.coordinator.api.states.get(self.entity_description.key)
return self._state
@property @property
def extra_state_attributes(self) -> Mapping[str, Any] | None: def extra_state_attributes(self) -> Mapping[str, Any]:
"""Return the state attributes.""" """Return the state attributes."""
sensor_attributes = self.coordinator.api.sensor_attributes.get( sensor_attributes = self.coordinator.api.sensor_attributes.get(
self.entity_description.key, {} self.entity_description.key, {}
) )
self._attrs = { return {
_PRICE_SENSOR_ATTRIBUTES_MAP[key]: value _PRICE_SENSOR_ATTRIBUTES_MAP[key]: value
for key, value in sensor_attributes.items() for key, value in sensor_attributes.items()
if key in _PRICE_SENSOR_ATTRIBUTES_MAP if key in _PRICE_SENSOR_ATTRIBUTES_MAP
} }
return self._attrs