Skip to content

Commit

Permalink
Adjust tts default_options type hints (home-assistant#90053)
Browse files Browse the repository at this point in the history
* Adjust tts default_options type hints

* Improve other components

* Adjust

* Revert component changes

* Adjust get_tts_audio in amazon_polly
  • Loading branch information
epenet authored Mar 27, 2023
1 parent 8c519e1 commit 94a52d5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions homeassistant/components/amazon_polly/tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import annotations

import logging
from typing import Final
from typing import Any, Final

import boto3
import botocore
Expand Down Expand Up @@ -166,8 +166,8 @@ def supported_options(self) -> list[str]:
def get_tts_audio(
self,
message: str,
language: str | None = None,
options: dict[str, str] | None = None,
language: str,
options: dict[str, Any] | None = None,
) -> TtsAudioType:
"""Request TTS file from Polly."""
if options is None or language is None:
Expand Down
12 changes: 7 additions & 5 deletions homeassistant/components/tts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import annotations

import asyncio
from collections.abc import Mapping
import functools as ft
import hashlib
from http import HTTPStatus
Expand Down Expand Up @@ -380,11 +381,12 @@ def process_options(
raise HomeAssistantError(f"Not supported language {language}")

# Options
if provider.default_options and options:
merged_options = provider.default_options.copy()
if (default_options := provider.default_options) and options:
merged_options = dict(default_options)
merged_options.update(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:
supported_options = provider.supported_options or []
Expand Down Expand Up @@ -665,8 +667,8 @@ def supported_options(self) -> list[str] | None:
return None

@property
def default_options(self) -> dict[str, Any] | None:
"""Return a dict include default options."""
def default_options(self) -> Mapping[str, Any] | None:
"""Return a mapping with the default options."""
return None

def get_tts_audio(
Expand Down
2 changes: 1 addition & 1 deletion pylint/plugins/hass_enforce_type_hints.py
Original file line number Diff line number Diff line change
Expand Up @@ -2366,7 +2366,7 @@ class ClassTypeHintMatch:
),
TypeHintMatch(
function_name="default_options",
return_type=["dict[str, Any]", None],
return_type=["Mapping[str, Any]", None],
),
TypeHintMatch(
function_name="get_tts_audio",
Expand Down

0 comments on commit 94a52d5

Please sign in to comment.