Prevent updater from delaying startup (#35708)
* Prevent updater from delaying startup The updater sometimes times out as seen in #33833 and the linked issues. The issue was presenting again today as it appears the service is overloaded again. * s/hass.loop/asyncio/gpull/35724/head
parent
98523fbb61
commit
fca96799a0
|
@ -1,4 +1,5 @@
|
||||||
"""Support to check for available updates."""
|
"""Support to check for available updates."""
|
||||||
|
import asyncio
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from distutils.version import StrictVersion
|
from distutils.version import StrictVersion
|
||||||
import logging
|
import logging
|
||||||
|
@ -105,7 +106,8 @@ async def async_setup(hass, config):
|
||||||
update_interval=timedelta(days=1),
|
update_interval=timedelta(days=1),
|
||||||
)
|
)
|
||||||
|
|
||||||
await coordinator.async_refresh()
|
# This can take up to 15s which can delay startup
|
||||||
|
asyncio.create_task(coordinator.async_refresh())
|
||||||
|
|
||||||
hass.async_create_task(
|
hass.async_create_task(
|
||||||
discovery.async_load_platform(hass, "binary_sensor", DOMAIN, {}, config)
|
discovery.async_load_platform(hass, "binary_sensor", DOMAIN, {}, config)
|
||||||
|
|
|
@ -33,6 +33,8 @@ class UpdaterBinary(BinarySensorEntity):
|
||||||
@property
|
@property
|
||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool:
|
||||||
"""Return true if the binary sensor is on."""
|
"""Return true if the binary sensor is on."""
|
||||||
|
if not self.coordinator.data:
|
||||||
|
return None
|
||||||
return self.coordinator.data.update_available
|
return self.coordinator.data.update_available
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -48,6 +50,8 @@ class UpdaterBinary(BinarySensorEntity):
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self) -> dict:
|
def device_state_attributes(self) -> dict:
|
||||||
"""Return the optional state attributes."""
|
"""Return the optional state attributes."""
|
||||||
|
if not self.coordinator.data:
|
||||||
|
return None
|
||||||
data = {}
|
data = {}
|
||||||
if self.coordinator.data.release_notes:
|
if self.coordinator.data.release_notes:
|
||||||
data[ATTR_RELEASE_NOTES] = self.coordinator.data.release_notes
|
data[ATTR_RELEASE_NOTES] = self.coordinator.data.release_notes
|
||||||
|
@ -57,11 +61,9 @@ class UpdaterBinary(BinarySensorEntity):
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self):
|
||||||
"""Register update dispatcher."""
|
"""Register update dispatcher."""
|
||||||
self.coordinator.async_add_listener(self.async_write_ha_state)
|
self.async_on_remove(
|
||||||
|
self.coordinator.async_add_listener(self.async_write_ha_state)
|
||||||
async def async_will_remove_from_hass(self):
|
)
|
||||||
"""When removed from hass."""
|
|
||||||
self.coordinator.async_remove_listener(self.async_write_ha_state)
|
|
||||||
|
|
||||||
async def async_update(self):
|
async def async_update(self):
|
||||||
"""Update the entity.
|
"""Update the entity.
|
||||||
|
|
Loading…
Reference in New Issue