mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Simplify native value property for WattTime (#56664)
This commit is contained in:
parent
4f5d6b8ba1
commit
56b94d6809
@ -17,8 +17,9 @@ from homeassistant.const import (
|
|||||||
MASS_POUNDS,
|
MASS_POUNDS,
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
from homeassistant.helpers.typing import StateType
|
||||||
from homeassistant.helpers.update_coordinator import (
|
from homeassistant.helpers.update_coordinator import (
|
||||||
CoordinatorEntity,
|
CoordinatorEntity,
|
||||||
DataUpdateCoordinator,
|
DataUpdateCoordinator,
|
||||||
@ -115,20 +116,7 @@ class RealtimeEmissionsSensor(CoordinatorEntity, SensorEntity):
|
|||||||
self._attr_unique_id = f"{coordinator.config_entry.entry_id}_{description.key}"
|
self._attr_unique_id = f"{coordinator.config_entry.entry_id}_{description.key}"
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
|
|
||||||
@callback
|
@property
|
||||||
def _handle_coordinator_update(self) -> None:
|
def native_value(self) -> StateType:
|
||||||
"""Respond to a DataUpdateCoordinator update."""
|
"""Return the value reported by the sensor."""
|
||||||
self.update_from_latest_data()
|
return self.coordinator.data[self.entity_description.data_key]
|
||||||
self.async_write_ha_state()
|
|
||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
|
||||||
"""Handle entity which will be added."""
|
|
||||||
await super().async_added_to_hass()
|
|
||||||
self.update_from_latest_data()
|
|
||||||
|
|
||||||
@callback
|
|
||||||
def update_from_latest_data(self) -> None:
|
|
||||||
"""Update the state."""
|
|
||||||
self._attr_native_value = self.coordinator.data[
|
|
||||||
self.entity_description.data_key
|
|
||||||
]
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user