Wait for Home Assistant start in here_travel_time (#68757)
* Wait for Home Assistant to fully start. * Update homeassistant/components/here_travel_time/sensor.py Co-authored-by: Erik Montnemery <erik@montnemery.com> * Define callback for _update_at_start Co-authored-by: Erik Montnemery <erik@montnemery.com>pull/68840/head
parent
5830481a53
commit
dc71ecf67e
|
@ -23,6 +23,7 @@ from homeassistant.const import (
|
|||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.start import async_at_start
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
|
@ -196,7 +197,6 @@ async def async_setup_platform(
|
|||
here_client,
|
||||
here_travel_time_config,
|
||||
)
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
|
||||
sensor = HERETravelTimeSensor(name, traffic_mode, coordinator)
|
||||
|
||||
|
@ -240,6 +240,15 @@ class HERETravelTimeSensor(SensorEntity, CoordinatorEntity):
|
|||
self._attr_native_unit_of_measurement = TIME_MINUTES
|
||||
self._attr_name = name
|
||||
|
||||
async def async_added_to_hass(self) -> None:
|
||||
"""Wait for start so origin and destination entities can be resolved."""
|
||||
await super().async_added_to_hass()
|
||||
|
||||
async def _update_at_start(_):
|
||||
await self.async_update()
|
||||
|
||||
async_at_start(self.hass, _update_at_start)
|
||||
|
||||
@property
|
||||
def native_value(self) -> str | None:
|
||||
"""Return the state of the sensor."""
|
||||
|
@ -274,6 +283,7 @@ class HERETravelTimeSensor(SensorEntity, CoordinatorEntity):
|
|||
@property
|
||||
def attribution(self) -> str | None:
|
||||
"""Return the attribution."""
|
||||
if self.coordinator.data is not None:
|
||||
return self.coordinator.data.get(ATTR_ATTRIBUTION)
|
||||
|
||||
@property
|
||||
|
|
Loading…
Reference in New Issue