mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 02:07:09 +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])
|
_LOGGER.debug("Connected to server %s using IMAP push", entry.data[CONF_SERVER])
|
||||||
super().__init__(hass, imap_client, entry, None)
|
super().__init__(hass, imap_client, entry, None)
|
||||||
self._push_wait_task: asyncio.Task[None] | None = 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:
|
async def _async_update_data(self) -> int | None:
|
||||||
"""Update the number of unread emails."""
|
"""Update the number of unread emails."""
|
||||||
await self.async_start()
|
await self.async_start()
|
||||||
return None
|
return self.number_of_messages
|
||||||
|
|
||||||
async def async_start(self) -> None:
|
async def async_start(self) -> None:
|
||||||
"""Start coordinator."""
|
"""Start coordinator."""
|
||||||
self._push_wait_task = self.hass.async_create_background_task(
|
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:
|
async def _async_wait_push_loop(self) -> None:
|
||||||
"""Wait for data push from server."""
|
"""Wait for data push from server."""
|
||||||
while True:
|
while True:
|
||||||
try:
|
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:
|
except InvalidAuth as ex:
|
||||||
self.auth_errors += 1
|
self.auth_errors += 1
|
||||||
await self._cleanup()
|
await self._cleanup()
|
||||||
@ -489,7 +490,7 @@ class ImapPushDataUpdateCoordinator(ImapDataUpdateCoordinator):
|
|||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
self.auth_errors = 0
|
self.auth_errors = 0
|
||||||
self.async_set_updated_data(number_of_messages)
|
self.async_set_updated_data(self.number_of_messages)
|
||||||
try:
|
try:
|
||||||
idle: asyncio.Future = await self.imap_client.idle_start()
|
idle: asyncio.Future = await self.imap_client.idle_start()
|
||||||
await self.imap_client.wait_server_push()
|
await self.imap_client.wait_server_push()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user