Skip to content

Commit

Permalink
Add SSL support
Browse files Browse the repository at this point in the history
  • Loading branch information
definitio committed Jan 8, 2021
1 parent d35a34c commit 375f5dd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ tts:

*Default value: `8080`*

- **ssl:** *(boolean) (Optional)*

Use HTTPS instead of HTTP to connect.

*Default value: `false`*

- **verify_ssl:** *(boolean) (Optional)*

Enable or disable SSL certificate verification. Set to false if you have a self-signed SSL certificate and haven't installed the CA certificate to enable verification.

*Default value: `true`*

- **format:** *(string) (Optional)*

This is the file format used for the TTS files created.
Expand Down
20 changes: 17 additions & 3 deletions custom_components/rhvoice/tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@
import voluptuous as vol
from aiohttp import ClientError
from homeassistant.components.tts import PLATFORM_SCHEMA, Provider
from homeassistant.const import CONF_HOST, CONF_PORT, CONF_TIMEOUT, HTTP_OK
from homeassistant.const import (
CONF_HOST,
CONF_PORT,
CONF_SSL,
CONF_TIMEOUT,
CONF_VERIFY_SSL,
HTTP_OK,
)
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.aiohttp_client import async_get_clientsession

Expand Down Expand Up @@ -54,6 +61,8 @@
vol.Optional(CONF_RATE, default=DEFAULT_RATE): vol.All(
vol.Coerce(int), vol.Range(0, 100)
),
vol.Optional(CONF_SSL, default=False): cv.boolean,
vol.Optional(CONF_VERIFY_SSL, default=True): cv.boolean,
vol.Optional(CONF_VOICE, default=DEFAULT_VOICE): vol.All(
cv.string, vol.In(list(chain(*SUPPORTED_LANGUAGES.values())))
),
Expand All @@ -76,7 +85,10 @@ def __init__(self, hass, conf):
"""Init RHVoice TTS service."""
self.name = 'RHVoice'
self.hass = hass
self._url = f'http://{conf.get(CONF_HOST)}:{conf.get(CONF_PORT)}/say'
host, port, ssl = conf.get(CONF_HOST), conf.get(CONF_PORT), conf.get(CONF_SSL)
self._url = f"http{'s' if ssl else ''}://{host}:{port}/say"
self._verify_ssl = conf.get(CONF_VERIFY_SSL)

self._codec = conf.get(CONF_FORMAT)
self._pitch = conf.get(CONF_PITCH)
self._rate = conf.get(CONF_RATE)
Expand Down Expand Up @@ -120,7 +132,9 @@ async def async_get_tts_audio(self, message, language, options=None):
'volume': self._volume,
}

request = await websession.get(self._url, params=url_param)
request = await websession.get(
self._url, params=url_param, verify_ssl=self._verify_ssl
)

if request.status != HTTP_OK:
_LOGGER.error(
Expand Down

0 comments on commit 375f5dd

Please sign in to comment.