mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +00:00
Fix lingering timers in tts (#90834)
* Fix lingering timers in tts * Improve * Use HassJob with cancel_on_shutdown
This commit is contained in:
parent
c1b7aa084c
commit
c40836b49f
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from collections.abc import Mapping
|
from collections.abc import Mapping
|
||||||
|
from datetime import datetime
|
||||||
import functools as ft
|
import functools as ft
|
||||||
import hashlib
|
import hashlib
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
@ -36,10 +37,11 @@ from homeassistant.const import (
|
|||||||
CONF_PLATFORM,
|
CONF_PLATFORM,
|
||||||
PLATFORM_FORMAT,
|
PLATFORM_FORMAT,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
from homeassistant.core import HassJob, HomeAssistant, ServiceCall, callback
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers import config_per_platform, discovery
|
from homeassistant.helpers import config_per_platform, discovery
|
||||||
import homeassistant.helpers.config_validation as cv
|
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.network import get_url
|
||||||
from homeassistant.helpers.service import async_set_service_schema
|
from homeassistant.helpers.service import async_set_service_schema
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
@ -645,11 +647,19 @@ class SpeechManager:
|
|||||||
}
|
}
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_remove_from_mem() -> None:
|
def async_remove_from_mem(_: datetime) -> None:
|
||||||
"""Cleanup memcache."""
|
"""Cleanup memcache."""
|
||||||
self.mem_cache.pop(cache_key, None)
|
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]:
|
async def async_read_tts(self, filename: str) -> tuple[str | None, bytes]:
|
||||||
"""Read a voice file and return binary.
|
"""Read a voice file and return binary.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user