Simplify native value property for WattTime ()

This commit is contained in:
Aaron Bach 2021-09-27 03:58:51 -06:00 committed by GitHub
parent 4f5d6b8ba1
commit 56b94d6809
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -17,8 +17,9 @@ from homeassistant.const import (
MASS_POUNDS,
PERCENTAGE,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
DataUpdateCoordinator,
@ -115,20 +116,7 @@ class RealtimeEmissionsSensor(CoordinatorEntity, SensorEntity):
self._attr_unique_id = f"{coordinator.config_entry.entry_id}_{description.key}"
self.entity_description = description
@callback
def _handle_coordinator_update(self) -> None:
"""Respond to a DataUpdateCoordinator update."""
self.update_from_latest_data()
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
]
@property
def native_value(self) -> StateType:
"""Return the value reported by the sensor."""
return self.coordinator.data[self.entity_description.data_key]