8000 0.118.5 by frenck · Pull Request #43964 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

0.118.5 #43964

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 5, 2020
Merged

0.118.5 #43964

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
run: |
python -m venv venv
. venv/bin/activate
pip install -U pip setuptools
pip install -U "pip<20.3" setuptools
pip install -r requirements.txt -r requirements_test.txt
- name: Restore pre-commit environment from cache
id: cache-precommit
Expand Down Expand Up @@ -611,7 +611,7 @@ jobs:
run: |
python -m venv venv
. venv/bin/activate
pip install -U pip setuptools wheel
pip install -U "pip<20.3" setuptools wheel
pip install -r requirements_all.txt
pip install -r requirements_test.txt
pip install -e .
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/google_translate/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"domain": "google_translate",
"name": "Google Translate Text-to-Speech",
"documentation": "https://www.home-assistant.io/integrations/google_translate",
"requirements": ["gTTS-token==1.1.4"],
"requirements": ["gTTS==2.2.1"],
"codeowners": []
}
174 changes: 62 additions & 112 deletions homeassistant/components/google_translate/tts.py
Original file line number Diff line number Diff line change
@@ -1,78 +1,95 @@
"""Support for the Google speech service."""
import asyncio
from io import BytesIO
import logging
import re

import aiohttp
from aiohttp.hdrs import REFERER, USER_AGENT
import async_timeout
from gtts_token import gtts_token
from gtts import gTTS, gTTSError
import voluptuous as vol

from homeassistant.components.tts import CONF_LANG, PLATFORM_SCHEMA, Provider
from homeassistant.const import HTTP_OK
from homeassistant.helpers.aiohttp_client import async_get_clientsession

_LOGGER = logging.getLogger(__name__)

GOOGLE_SPEECH_URL = "https://translate.google.com/translate_tts"
MESSAGE_SIZE = 148

SUPPORT_LANGUAGES = [
"af",
"sq",
"ar",
"hy",
"bn",
"bs",
"ca",
"zh",
"zh-cn",
"zh-tw",
"zh-yue",
"hr",
"cs",
"cy",
"da",
"nl",
"de",
"el",
"en",
"en-au",
"en-uk",
"en-us",
"eo",
"es",
"et",
"fi",
"fr",
"de",
"el",
"gu",
"hi",
"hr",
"hu",
"is",
"hy",
"id",
"is",
"it",
"ja",
"jw",
"km",
"kn",
"ko",
"la",
"lv",
"mk",
"ml",
"mr",
"my",
"ne",
"nl",
"no",
"pl",
"pt",
"pt-br",
"ro",
"ru",
"sr",
"si",
"sk",
"es",
"es-es",
"es-mx",
"es-us",
"sw",
"sq",
"sr",
"su",
"sv",
"sw",
"ta",
"te",
"th",
"tl",
"tr",
"vi",
"cy",
"uk",
"bg-BG",
"ur",
"vi",
# dialects
"zh-CN",
"zh-cn",
"zh-tw",
"en-us",
"en-ca",
"en-uk",
"en-gb",
"en-au",
"en-gh",
"en-in",
"en-ie",
"en-nz",
"en-ng",
"en-ph",
"en-za",
"en-tz",
"fr-ca",
"fr-fr",
"pt-br",
"pt-pt",
"es-es",
"es-us",
]

DEFAULT_LANG = "en"
Expand All @@ -94,14 +111,6 @@ def __init__(self, hass, lang):
"""Init Google TTS service."""
self.hass = hass
self._lang = lang
self.headers = {
REFERER: "http://translate.google.com/",
USER_AGENT: (
"Mozilla/5.0 (Windows NT 10.0; WOW64) "
"AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/47.0.2526.106 Safari/537.36"
),
}
self.name = "Google"

@property
Expand All @@ -114,74 +123,15 @@ def supported_languages(self):
"""Return list of supported languages."""
return SUPPORT_LANGUAGES

async def async_get_tts_audio(self, message, language, options=None):
def get_tts_audio(self, message, language, options=None):
"""Load TTS from google."""
tts = gTTS(text=message, lang=language)
mp3_data = BytesIO()

try:
tts.write_to_fp(mp3_data)
except gTTSError as exc:
_LOGGER.exception("Error during processing of TTS request %s", exc)
return None, None

token = gtts_token.Token()
websession = async_get_clientsession(self.hass)
message_parts = self._split_message_to_parts(message)

data = b""
for idx, part in enumerate(message_parts):
try:
part_token = await self.hass.async_add_executor_job(
token.calculate_token, part
)
except ValueError as err:
# If token seed fetching fails.
_LOGGER.warning(err)
return None, None

url_param = {
"ie": "UTF-8",
"tl": language,
"q": part,
"tk": part_token,
"total": len(message_parts),
"idx": idx,
"client": "tw-ob",
"textlen": len(part),
}

try:
with async_timeout.timeout(10):
request = await websession.get(
GOOGLE_SPEECH_URL, params=url_param, headers=self.headers
)

if request.status != HTTP_OK:
_LOGGER.error(
"Error %d on load URL %s", request.status, request.url
)
return None, None
data += await request.read()

except (asyncio.TimeoutError, aiohttp.ClientError):
_LOGGER.error("Timeout for google speech")
return None, None

return "mp3", data

@staticmethod
def _split_messag 1E0A e_to_parts(message):
"""Split message into single parts."""
if len(message) <= MESSAGE_SIZE:
return [message]

punc = "!()[]?.,;:"
punc_list = [re.escape(c) for c in punc]
pattern = "|".join(punc_list)
parts = re.split(pattern, message)

def split_by_space(fullstring):
"""Split a string by space."""
if len(fullstring) > MESSAGE_SIZE:
idx = fullstring.rfind(" ", 0, MESSAGE_SIZE)
return [fullstring[:idx]] + split_by_space(fullstring[idx:])
return [fullstring]

msg_parts = []
for part in parts:
msg_parts += split_by_space(part)

return [msg for msg in msg_parts if len(msg) > 0]
return "mp3", mp3_data.getvalue()
4 changes: 3 additions & 1 deletion homeassistant/components/hassio/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ async def _command_proxy(
This method is a coroutine.
"""
read_timeout = _get_timeout(path)
client_timeout = 10
data = None
headers = _init_header(request)
if path == "snapshots/new/upload":
Expand All @@ -89,9 +90,10 @@ async def _command_proxy(
request._client_max_size = ( # pylint: disable=protected-access
MAX_UPLOAD_SIZE
)
client_timeout = 300

try:
with async_timeout.timeout(10):
with async_timeout.timeout(client_timeout):
data = await request.read()

method = getattr(self._websession, request.method.lower())
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/netatmo/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Netatmo",
"documentation": "https://www.home-assistant.io/integrations/netatmo",
"requirements": [
"pyatmo==4.2.0"
"pyatmo==4.2.1"
],
"after_dependencies": [
"cloud",
Expand Down
2 changes: 10000 1 addition & 1 deletion homeassistant/const.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Constants used by Home Assistant components."""
MAJOR_VERSION = 0
MINOR_VERSION = 118
PATCH_VERSION = "4"
PATCH_VERSION = "5"
__short_version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}"
__version__ = f"{__short_version__}.{PATCH_VERSION}"
REQUIRED_PYTHON_VER = (3, 7, 1)
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/package_constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jinja2>=2.11.2
netdisco==2.8.2
paho-mqtt==1.5.1
pillow==7.2.0
pip>=8.0.3
pip>=8.0.3,<20.3
python-slugify==4.0.1
pytz>=2020.1
pyyaml==5.3.1
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ importlib-metadata==1.6.0;python_version<'3.8'
jinja2>=2.11.2
PyJWT==1.7.1
cryptography==3.2
pip>=8.0.3
pip>=8.0.3,<20.3
python-slugify==4.0.1
pytz>=2020.1
pyyaml==5.3.1
Expand Down
4 changes: 2 additions & 2 deletions requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ freesms==0.1.2
fritzconnection==1.3.4

# homeassistant.components.google_translate
gTTS-token==1.1.4
gTTS==2.2.1

# homeassistant.components.garmin_connect
garminconnect==0.1.16
Expand Down Expand Up @@ -1274,7 +1274,7 @@ pyarlo==0.2.3
pyatag==0.3.4.4

# homeassistant.components.netatmo
pyatmo==4.2.0
pyatmo==4.2.1

# homeassistant.components.atome
pyatome==0.1.1
Expand Down
4 changes: 2 additions & 2 deletions requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ fnvhash==0.1.0
foobot_async==0.3.2

# homeassistant.components.google_translate
gTTS-token==1.1.4
gTTS==2.2.1

# homeassistant.components.garmin_connect
garminconnect==0.1.16
Expand Down Expand Up @@ -640,7 +640,7 @@ pyarlo==0.2.3
pyatag==0.3.4.4

# homeassistant.components.netatmo
pyatmo==4.2.0
pyatmo==4.2.1

# homeassistant.components.blackbird
pyblackbird==0.5
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"PyJWT==1.7.1",
# PyJWT has loose dependency. We want the latest one.
"cryptography==3.2",
"pip>=8.0.3",
"pip>=8.0.3,<20.3",
"python-slugify==4.0.1",
"pytz>=2020.1",
"pyyaml==5.3.1",
Expand Down
Loading
0