core/homeassistant/components/browser/__init__.py

27 lines
694 B
Python
Raw Normal View History

"""Support for launching a web browser on the host machine."""
import voluptuous as vol
ATTR_URL = 'url'
ATTR_URL_DEFAULT = 'https://www.google.com'
DOMAIN = 'browser'
SERVICE_BROWSE_URL = 'browse_url'
SERVICE_BROWSE_URL_SCHEMA = vol.Schema({
2016-07-17 06:45:38 +00:00
# pylint: disable=no-value-for-parameter
vol.Required(ATTR_URL, default=ATTR_URL_DEFAULT): vol.Url(),
})
def setup(hass, config):
2016-03-08 16:55:57 +00:00
"""Listen for browse_url events."""
import webbrowser
hass.services.register(DOMAIN, SERVICE_BROWSE_URL,
lambda service:
webbrowser.open(service.data[ATTR_URL]),
schema=SERVICE_BROWSE_URL_SCHEMA)
return True