mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Switch imap push coordinator to use eager_start (#115454)
When I turned on eager_start here the data would always end up being None because _async_update_data always returned None. To fix this it now returns the value from the push loop. It appears this race would happen in production so this may be a bugfix but since I do not use this integration it could use a second set of eyes
This commit is contained in:
parent
9bf87329da
commit
f3a3e6821b
@ -443,23 +443,24 @@ class ImapPushDataUpdateCoordinator(ImapDataUpdateCoordinator):
|
||||
_LOGGER.debug("Connected to server %s using IMAP push", entry.data[CONF_SERVER])
|
||||
super().__init__(hass, imap_client, entry, None)
|
||||
self._push_wait_task: asyncio.Task[None] | None = None
|
||||
self.number_of_messages: int | None = None
|
||||
|
||||
async def _async_update_data(self) -> int | None:
|
||||
"""Update the number of unread emails."""
|
||||
await self.async_start()
|
||||
return None
|
||||
return self.number_of_messages
|
||||
|
||||
async def async_start(self) -> None:
|
||||
"""Start coordinator."""
|
||||
self._push_wait_task = self.hass.async_create_background_task(
|
||||
self._async_wait_push_loop(), "Wait for IMAP data push", eager_start=False
|
||||
self._async_wait_push_loop(), "Wait for IMAP data push"
|
||||
)
|
||||
|
||||
async def _async_wait_push_loop(self) -> None:
|
||||
"""Wait for data push from server."""
|
||||
while True:
|
||||
try:
|
||||
number_of_messages = await self._async_fetch_number_of_messages()
|
||||
self.number_of_messages = await self._async_fetch_number_of_messages()
|
||||
except InvalidAuth as ex:
|
||||
self.auth_errors += 1
|
||||
await self._cleanup()
|
||||
@ -489,7 +490,7 @@ class ImapPushDataUpdateCoordinator(ImapDataUpdateCoordinator):
|
||||
continue
|
||||
else:
|
||||
self.auth_errors = 0
|
||||
self.async_set_updated_data(number_of_messages)
|
||||
self.async_set_updated_data(self.number_of_messages)
|
||||
try:
|
||||
idle: asyncio.Future = await self.imap_client.idle_start()
|
||||
await self.imap_client.wait_server_push()
|
||||
|
Loading…
x
Reference in New Issue
Block a user