2013-12-11 08:07:30 +00:00
|
|
|
"""
|
2016-02-26 22:52:54 +00:00
|
|
|
Provides functionality to launch a web browser on the host machine.
|
2015-11-09 12:12:18 +00:00
|
|
|
|
|
|
|
For more details about this component, please refer to the documentation at
|
|
|
|
https://home-assistant.io/components/browser/
|
2013-12-11 08:07:30 +00:00
|
|
|
"""
|
2016-04-13 16:57:47 +00:00
|
|
|
import voluptuous as vol
|
2013-12-11 08:07:30 +00:00
|
|
|
|
2014-01-05 01:55:05 +00:00
|
|
|
DOMAIN = "browser"
|
2013-12-11 08:07:30 +00:00
|
|
|
SERVICE_BROWSE_URL = "browse_url"
|
|
|
|
|
2016-04-13 16:57:47 +00:00
|
|
|
ATTR_URL = 'url'
|
|
|
|
ATTR_URL_DEFAULT = 'https://www.google.com'
|
|
|
|
|
|
|
|
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(),
|
2016-04-13 16:57:47 +00:00
|
|
|
})
|
|
|
|
|
2013-12-11 08:07:30 +00:00
|
|
|
|
2014-08-13 12:28:45 +00:00
|
|
|
def setup(hass, config):
|
2016-03-08 16:55:57 +00:00
|
|
|
"""Listen for browse_url events."""
|
2013-12-11 08:07:30 +00:00
|
|
|
import webbrowser
|
|
|
|
|
2014-04-24 07:40:45 +00:00
|
|
|
hass.services.register(DOMAIN, SERVICE_BROWSE_URL,
|
|
|
|
lambda service:
|
2016-04-13 16:57:47 +00:00
|
|
|
webbrowser.open(service.data[ATTR_URL]),
|
|
|
|
schema=SERVICE_BROWSE_URL_SCHEMA)
|
2013-12-11 08:07:30 +00:00
|
|
|
|
|
|
|
return True
|