core/homeassistant/components/browser/__init__.py

40 lines
888 B
Python
Raw Normal View History

"""Support for launching a web browser on the host machine."""
2019-10-12 05:18:47 +00:00
import webbrowser
import voluptuous as vol
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"
2019-07-31 19:25:30 +00:00
DOMAIN = "browser"
2019-07-31 19:25:30 +00:00
SERVICE_BROWSE_URL = "browse_url"
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()
}
)
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."""
2019-07-31 19:25:30 +00:00
hass.services.register(
DOMAIN,
SERVICE_BROWSE_URL,
_browser_url,
2019-07-31 19:25:30 +00:00
schema=SERVICE_BROWSE_URL_SCHEMA,
)
return True