Remove YAML import from PicoTTS integration (#183300)

This commit is contained in:
Manu
2026-09-27 14:46:41 +02:00
committed by GitHub
parent dafd99ca58
commit 2125b81943
5 changed files with 3 additions and 154 deletions
@@ -41,8 +41,3 @@ class PicoTTSConfigFlow(ConfigFlow, domain=DOMAIN):
}
return self.async_create_entry(title=title, data=data)
async def async_step_import(self, import_info: dict[str, Any]) -> ConfigFlowResult:
"""Import Pico TTS config from yaml."""
return await self.async_step_user(import_info)
-25
View File
@@ -1,25 +0,0 @@
"""Issues for Pico TTS integration."""
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
from .const import DOMAIN
@callback
def deprecate_yaml_issue(hass: HomeAssistant) -> None:
"""Deprecate yaml issue."""
async_create_issue(
hass,
DOMAIN,
f"deprecated_yaml_{DOMAIN}",
is_fixable=False,
issue_domain=DOMAIN,
breaks_in_ha_version="2026.10.0",
severity=IssueSeverity.WARNING,
translation_key="deprecated_yaml",
translation_placeholders={
"domain": DOMAIN,
"integration_title": "Pico TTS",
},
)
@@ -28,11 +28,5 @@
"timeout_error": {
"message": "Timeout running pico2wave"
}
},
"issues": {
"deprecated_yaml": {
"description": "Configuring {integration_title} using YAML is being removed.\n\nYour existing YAML configuration has been imported into the UI automatically.\n\nThe actions `tts.{domain}_*_say` will be removed and automations should be updated to use the `tts.speak` action with the new tts entities. Then remove the `{domain}` configuration from your configuration.yaml file and restart Home Assistant to fix this issue.",
"title": "[%key:component::homeassistant::issues::deprecated_yaml::title%]"
}
}
}
+3 -89
View File
@@ -3,57 +3,21 @@
import contextlib
import logging
import os
import shutil
import subprocess
import tempfile
from typing import Any, override
import probatio
from homeassistant.components.tts import (
CONF_LANG,
PLATFORM_SCHEMA as TTS_PLATFORM_SCHEMA,
Provider,
TextToSpeechEntity,
TtsAudioType,
)
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.components.tts import CONF_LANG, TextToSpeechEntity, TtsAudioType
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from .const import DEFAULT_LANG, DOMAIN, SUPPORT_LANGUAGES
from .issue import deprecate_yaml_issue
from .const import DOMAIN, SUPPORT_LANGUAGES
_LOGGER = logging.getLogger(__name__)
PLATFORM_SCHEMA = TTS_PLATFORM_SCHEMA.extend(
{probatio.Optional(CONF_LANG, default=DEFAULT_LANG): probatio.In(SUPPORT_LANGUAGES)}
)
async def async_get_engine(
hass: HomeAssistant,
config: ConfigType,
discovery_info: DiscoveryInfoType | None = None,
) -> Provider | None:
"""Set up Pico speech component."""
if await hass.async_add_executor_job(shutil.which, "pico2wave") is None:
_LOGGER.error("'pico2wave' was not found")
return None
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_IMPORT}, data=config
)
)
deprecate_yaml_issue(hass)
return PicoProvider(config[CONF_LANG])
async def async_setup_entry(
hass: HomeAssistant,
@@ -117,53 +81,3 @@ class PicoTTSEntity(TextToSpeechEntity):
os.remove(fname)
return "wav", data
class PicoProvider(Provider):
"""The Pico TTS API provider."""
def __init__(self, lang: str) -> None:
"""Initialize Pico TTS provider."""
self._lang = lang
self.name = "PicoTTS"
@property
@override
def default_language(self) -> str:
"""Return the default language."""
return self._lang
@property
@override
def supported_languages(self) -> list[str]:
"""Return list of supported languages."""
return SUPPORT_LANGUAGES
@override
def get_tts_audio(
self, message: str, language: str, options: dict[str, Any]
) -> TtsAudioType:
"""Load TTS using pico2wave."""
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmpf:
fname = tmpf.name
cmd = ["pico2wave", "--wave", fname, "-l", language]
result = subprocess.run(cmd, text=True, input=message, check=False)
data = None
try:
if result.returncode != 0:
_LOGGER.error(
"Error running pico2wave, return code: %s", result.returncode
)
return None, None
with open(fname, "rb") as voice:
data = voice.read()
except OSError:
_LOGGER.error("Error trying to read %s", fname)
return None, None
finally:
os.remove(fname)
if data:
return ("wav", data)
return None, None
@@ -5,14 +5,10 @@ from unittest.mock import AsyncMock, patch
import pytest
from homeassistant import config_entries
from homeassistant.components import tts
from homeassistant.components.picotts.const import DOMAIN
from homeassistant.components.tts import CONF_LANG
from homeassistant.const import CONF_PLATFORM
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
from homeassistant.helpers import issue_registry as ir
from homeassistant.setup import async_setup_component
from tests.common import MockConfigEntry
@@ -88,28 +84,3 @@ async def test_already_configured(
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "already_configured"
assert len(mock_setup_entry.mock_calls) == 0
async def test_import_flow(
hass: HomeAssistant,
issue_registry: ir.IssueRegistry,
) -> None:
"""Test the import flow."""
with patch(
"homeassistant.components.picotts.shutil.which",
return_value="/usr/local/bin/pico2wave",
):
assert not hass.config_entries.async_entries(DOMAIN)
assert await async_setup_component(
hass,
tts.DOMAIN,
{tts.DOMAIN: {CONF_PLATFORM: DOMAIN}},
)
await hass.async_block_till_done()
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
config_entry = hass.config_entries.async_entries(DOMAIN)[0]
assert config_entry.state is config_entries.ConfigEntryState.LOADED
assert issue_registry.async_get_issue(
domain=DOMAIN,
issue_id=f"deprecated_yaml_{DOMAIN}",
)