mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 06:07:17 +00:00
Adjust tts default_options type hints (#90053)
* Adjust tts default_options type hints * Improve other components * Adjust * Revert component changes * Adjust get_tts_audio in amazon_polly
This commit is contained in:
parent
8c519e1abb
commit
94a52d5cca
@ -2,7 +2,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from typing import Final
|
from typing import Any, Final
|
||||||
|
|
||||||
import boto3
|
import boto3
|
||||||
import botocore
|
import botocore
|
||||||
@ -166,8 +166,8 @@ class AmazonPollyProvider(Provider):
|
|||||||
def get_tts_audio(
|
def get_tts_audio(
|
||||||
self,
|
self,
|
||||||
message: str,
|
message: str,
|
||||||
language: str | None = None,
|
language: str,
|
||||||
options: dict[str, str] | None = None,
|
options: dict[str, Any] | None = None,
|
||||||
) -> TtsAudioType:
|
) -> TtsAudioType:
|
||||||
"""Request TTS file from Polly."""
|
"""Request TTS file from Polly."""
|
||||||
if options is None or language is None:
|
if options is None or language is None:
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
from collections.abc import Mapping
|
||||||
import functools as ft
|
import functools as ft
|
||||||
import hashlib
|
import hashlib
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
@ -380,11 +381,12 @@ class SpeechManager:
|
|||||||
raise HomeAssistantError(f"Not supported language {language}")
|
raise HomeAssistantError(f"Not supported language {language}")
|
||||||
|
|
||||||
# Options
|
# Options
|
||||||
if provider.default_options and options:
|
if (default_options := provider.default_options) and options:
|
||||||
merged_options = provider.default_options.copy()
|
merged_options = dict(default_options)
|
||||||
merged_options.update(options)
|
merged_options.update(options)
|
||||||
options = merged_options
|
options = merged_options
|
||||||
options = options or provider.default_options
|
if not options:
|
||||||
|
options = None if default_options is None else dict(default_options)
|
||||||
|
|
||||||
if options is not None:
|
if options is not None:
|
||||||
supported_options = provider.supported_options or []
|
supported_options = provider.supported_options or []
|
||||||
@ -665,8 +667,8 @@ class Provider:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def default_options(self) -> dict[str, Any] | None:
|
def default_options(self) -> Mapping[str, Any] | None:
|
||||||
"""Return a dict include default options."""
|
"""Return a mapping with the default options."""
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_tts_audio(
|
def get_tts_audio(
|
||||||
|
@ -2366,7 +2366,7 @@ _INHERITANCE_MATCH: dict[str, list[ClassTypeHintMatch]] = {
|
|||||||
),
|
),
|
||||||
TypeHintMatch(
|
TypeHintMatch(
|
||||||
function_name="default_options",
|
function_name="default_options",
|
||||||
return_type=["dict[str, Any]", None],
|
return_type=["Mapping[str, Any]", None],
|
||||||
),
|
),
|
||||||
TypeHintMatch(
|
TypeHintMatch(
|
||||||
function_name="get_tts_audio",
|
function_name="get_tts_audio",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user