mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-08 17:56:33 +00:00
Add Wyoming Protocol add-on/integration discovery (#4248)
* Add Wyoming Protocol add-on/integration discovery * Use URIs instead * Use unix socket in bad test * Address pylint warning
This commit is contained in:
parent
744cd4ea39
commit
ed2f57f3ca
@ -7,5 +7,6 @@ ATTR_PORT = "port"
|
||||
ATTR_PROTOCOL = "protocol"
|
||||
ATTR_SERIAL = "serial"
|
||||
ATTR_SSL = "ssl"
|
||||
ATTR_URI = "uri"
|
||||
ATTR_URL = "url"
|
||||
ATTR_USERNAME = "username"
|
||||
|
25
supervisor/discovery/services/wyoming.py
Normal file
25
supervisor/discovery/services/wyoming.py
Normal file
@ -0,0 +1,25 @@
|
||||
"""Discovery service for the Wyoming Protocol integration."""
|
||||
from typing import Any, cast
|
||||
from urllib.parse import urlparse
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from ..const import ATTR_URI
|
||||
|
||||
|
||||
def validate_uri(value: Any) -> str:
|
||||
"""Validate an Wyoming URI.
|
||||
|
||||
Currently accepts TCP URIs, can extended
|
||||
to accept UNIX sockets in the future.
|
||||
"""
|
||||
uri_value = str(value)
|
||||
|
||||
if urlparse(uri_value).scheme == "tcp":
|
||||
# pylint: disable-next=no-value-for-parameter
|
||||
return cast(str, vol.Schema(vol.Url())(uri_value))
|
||||
|
||||
raise vol.Invalid("invalid Wyoming Protocol URI")
|
||||
|
||||
|
||||
SCHEMA = vol.Schema({vol.Required(ATTR_URI): validate_uri})
|
27
tests/discovery/test_wyoming.py
Normal file
27
tests/discovery/test_wyoming.py
Normal file
@ -0,0 +1,27 @@
|
||||
"""Test wyoming discovery."""
|
||||
|
||||
import pytest
|
||||
import voluptuous as vol
|
||||
|
||||
from supervisor.discovery.validate import valid_discovery_config
|
||||
|
||||
|
||||
def test_good_config():
|
||||
"""Test good wyoming config."""
|
||||
|
||||
valid_discovery_config("wyoming", {"uri": "tcp://core-wyoming"})
|
||||
|
||||
valid_discovery_config("wyoming", {"uri": "tcp://core-wyoming:1234"})
|
||||
|
||||
|
||||
def test_bad_config():
|
||||
"""Test bad wyoming config."""
|
||||
|
||||
with pytest.raises(vol.Invalid):
|
||||
valid_discovery_config("wyoming", {"host": "test"})
|
||||
|
||||
with pytest.raises(vol.Invalid):
|
||||
valid_discovery_config("wyoming", {"uri": "https://also.an.uri.com"})
|
||||
|
||||
with pytest.raises(vol.Invalid):
|
||||
valid_discovery_config("wyoming", {"uri": "unix://not/supported/yet.socket"})
|
Loading…
x
Reference in New Issue
Block a user