Skip to content

Commit

Permalink
Fix lingering timers in tts (#90834)
Browse files Browse the repository at this point in the history
* Fix lingering timers in tts

* Improve

* Use HassJob with cancel_on_shutdown
  • Loading branch information
epenet authored Apr 13, 2023
1 parent c1b7aa0 commit c40836b
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions homeassistant/components/tts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import asyncio
from collections.abc import Mapping
from datetime import datetime
import functools as ft
import hashlib
from http import HTTPStatus
Expand Down Expand Up @@ -36,10 +37,11 @@
CONF_PLATFORM,
PLATFORM_FORMAT,
)
from homeassistant.core import HomeAssistant, ServiceCall, callback
from homeassistant.core import HassJob, HomeAssistant, ServiceCall, callback
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import config_per_platform, discovery
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.event import async_call_later
from homeassistant.helpers.network import get_url
from homeassistant.helpers.service import async_set_service_schema
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
Expand Down Expand Up @@ -645,11 +647,19 @@ def _async_store_to_memcache(
}

@callback
def async_remove_from_mem() -> None:
def async_remove_from_mem(_: datetime) -> None:
"""Cleanup memcache."""
self.mem_cache.pop(cache_key, None)

self.hass.loop.call_later(self.time_memory, async_remove_from_mem)
async_call_later(
self.hass,
self.time_memory,
HassJob(
async_remove_from_mem,
name="tts remove_from_mem",
cancel_on_shutdown=True,
),
)

async def async_read_tts(self, filename: str) -> tuple[str | None, bytes]:
"""Read a voice file and return binary.
Expand Down

0 comments on commit c40836b

Please sign in to comment.