2019-02-13 20:21:14 +00:00
|
|
|
"""Support for launching a web browser on the host machine."""
|
2019-10-12 05:18:47 +00:00
|
|
|
import webbrowser
|
2019-12-09 12:52:18 +00:00
|
|
|
|
2016-04-13 16:57:47 +00:00
|
|
|
import voluptuous as vol
|
2013-12-11 08:07:30 +00:00
|
|
|
|
2022-01-10 03:02:50 +00:00
|
|
|
from homeassistant.core import HomeAssistant, ServiceCall
|
|
|
|
from homeassistant.helpers.typing import ConfigType
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
ATTR_URL = "url"
|
|
|
|
ATTR_URL_DEFAULT = "https://www.google.com"
|
2016-04-13 16:57:47 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
DOMAIN = "browser"
|
2019-02-13 20:21:14 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
SERVICE_BROWSE_URL = "browse_url"
|
2019-02-13 20:21:14 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
SERVICE_BROWSE_URL_SCHEMA = vol.Schema(
|
|
|
|
{
|
|
|
|
# pylint: disable=no-value-for-parameter
|
|
|
|
vol.Required(ATTR_URL, default=ATTR_URL_DEFAULT): vol.Url()
|
|
|
|
}
|
|
|
|
)
|
2016-04-13 16:57:47 +00:00
|
|
|
|
2013-12-11 08:07:30 +00:00
|
|
|
|
2022-01-10 03:02:50 +00:00
|
|
|
def _browser_url(service: ServiceCall) -> None:
|
|
|
|
"""Browse to URL."""
|
|
|
|
webbrowser.open(service.data[ATTR_URL])
|
|
|
|
|
|
|
|
|
|
|
|
def setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
2016-03-08 16:55:57 +00:00
|
|
|
"""Listen for browse_url events."""
|
2013-12-11 08:07:30 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
hass.services.register(
|
|
|
|
DOMAIN,
|
|
|
|
SERVICE_BROWSE_URL,
|
2022-01-10 03:02:50 +00:00
|
|
|
_browser_url,
|
2019-07-31 19:25:30 +00:00
|
|
|
schema=SERVICE_BROWSE_URL_SCHEMA,
|
|
|
|
)
|
2013-12-11 08:07:30 +00:00
|
|
|
|
|
|
|
return True
|