mirror of
https://github.com/home-assistant/core.git
synced 2025-08-04 05:05:09 +02:00
Service validation for browser component.
This commit is contained in:
@@ -4,10 +4,18 @@ Provides functionality to launch a web browser on the host machine.
|
|||||||
For more details about this component, please refer to the documentation at
|
For more details about this component, please refer to the documentation at
|
||||||
https://home-assistant.io/components/browser/
|
https://home-assistant.io/components/browser/
|
||||||
"""
|
"""
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
DOMAIN = "browser"
|
DOMAIN = "browser"
|
||||||
SERVICE_BROWSE_URL = "browse_url"
|
SERVICE_BROWSE_URL = "browse_url"
|
||||||
|
|
||||||
|
ATTR_URL = 'url'
|
||||||
|
ATTR_URL_DEFAULT = 'https://www.google.com'
|
||||||
|
|
||||||
|
SERVICE_BROWSE_URL_SCHEMA = vol.Schema({
|
||||||
|
vol.Required(ATTR_URL, default=ATTR_URL_DEFAULT): vol.Url,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
def setup(hass, config):
|
def setup(hass, config):
|
||||||
"""Listen for browse_url events."""
|
"""Listen for browse_url events."""
|
||||||
@@ -15,8 +23,7 @@ def setup(hass, config):
|
|||||||
|
|
||||||
hass.services.register(DOMAIN, SERVICE_BROWSE_URL,
|
hass.services.register(DOMAIN, SERVICE_BROWSE_URL,
|
||||||
lambda service:
|
lambda service:
|
||||||
webbrowser.open(
|
webbrowser.open(service.data[ATTR_URL]),
|
||||||
service.data.get(
|
schema=SERVICE_BROWSE_URL_SCHEMA)
|
||||||
'url', 'https://www.google.com')))
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
Reference in New Issue
Block a user