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/g
pull/35724/head
J. Nick Koston 2020-05-16 16:34:34 -05:00 committed by GitHub
parent 98523fbb61
commit fca96799a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View File

@ -1,4 +1,5 @@
"""Support to check for available updates."""
import asyncio
from datetime import timedelta
from distutils.version import StrictVersion
import logging
@ -105,7 +106,8 @@ async def async_setup(hass, config):
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(
discovery.async_load_platform(hass, "binary_sensor", DOMAIN, {}, config)

View File

@ -33,6 +33,8 @@ class UpdaterBinary(BinarySensorEntity):
@property
def is_on(self) -> bool:
"""Return true if the binary sensor is on."""
if not self.coordinator.data:
return None
return self.coordinator.data.update_available
@property
@ -48,6 +50,8 @@ class UpdaterBinary(BinarySensorEntity):
@property
def device_state_attributes(self) -> dict:
"""Return the optional state attributes."""
if not self.coordinator.data:
return None
data = {}
if 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):
"""Register update dispatcher."""
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)
self.async_on_remove(
self.coordinator.async_add_listener(self.async_write_ha_state)
)
async def async_update(self):
"""Update the entity.