mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Simplify state update for Flu Near You (#56650)
This commit is contained in:
parent
fabf5204be
commit
d4ebcf2ba5
@ -130,7 +130,7 @@ async def async_setup_entry(
|
|||||||
for description in USER_SENSOR_DESCRIPTIONS
|
for description in USER_SENSOR_DESCRIPTIONS
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
async_add_entities(sensors)
|
async_add_entities(sensors, True)
|
||||||
|
|
||||||
|
|
||||||
class FluNearYouSensor(CoordinatorEntity, SensorEntity):
|
class FluNearYouSensor(CoordinatorEntity, SensorEntity):
|
||||||
@ -156,26 +156,14 @@ class FluNearYouSensor(CoordinatorEntity, SensorEntity):
|
|||||||
@callback
|
@callback
|
||||||
def _handle_coordinator_update(self) -> None:
|
def _handle_coordinator_update(self) -> None:
|
||||||
"""Handle updated data from the coordinator."""
|
"""Handle updated data from the coordinator."""
|
||||||
self.update_from_latest_data()
|
self.async_schedule_update_ha_state(force_refresh=True)
|
||||||
self.async_write_ha_state()
|
|
||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
|
||||||
"""Register callbacks."""
|
|
||||||
await super().async_added_to_hass()
|
|
||||||
self.update_from_latest_data()
|
|
||||||
|
|
||||||
@callback
|
|
||||||
def update_from_latest_data(self) -> None:
|
|
||||||
"""Update the sensor."""
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
|
|
||||||
class CdcSensor(FluNearYouSensor):
|
class CdcSensor(FluNearYouSensor):
|
||||||
"""Define a sensor for CDC reports."""
|
"""Define a sensor for CDC reports."""
|
||||||
|
|
||||||
@callback
|
async def async_update(self) -> None:
|
||||||
def update_from_latest_data(self) -> None:
|
"""Update the state."""
|
||||||
"""Update the sensor."""
|
|
||||||
self._attr_extra_state_attributes.update(
|
self._attr_extra_state_attributes.update(
|
||||||
{
|
{
|
||||||
ATTR_REPORTED_DATE: self.coordinator.data["week_date"],
|
ATTR_REPORTED_DATE: self.coordinator.data["week_date"],
|
||||||
@ -188,9 +176,8 @@ class CdcSensor(FluNearYouSensor):
|
|||||||
class UserSensor(FluNearYouSensor):
|
class UserSensor(FluNearYouSensor):
|
||||||
"""Define a sensor for user reports."""
|
"""Define a sensor for user reports."""
|
||||||
|
|
||||||
@callback
|
async def async_update(self) -> None:
|
||||||
def update_from_latest_data(self) -> None:
|
"""Update the state."""
|
||||||
"""Update the sensor."""
|
|
||||||
self._attr_extra_state_attributes.update(
|
self._attr_extra_state_attributes.update(
|
||||||
{
|
{
|
||||||
ATTR_CITY: self.coordinator.data["local"]["city"].split("(")[0],
|
ATTR_CITY: self.coordinator.data["local"]["city"].split("(")[0],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user