mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Clean attributes in pvpc hourly pricing ElecPriceSensor (#85688)
♻️ Remove unnecessary private attrs and fix typing for sensor entity
This commit is contained in:
parent
2757f97114
commit
05590f63c9
@ -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
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user