From 74a58996269d6536a1efd71fb4de687484629e10 Mon Sep 17 00:00:00 2001 From: Mike Degatano Date: Tue, 5 Mar 2024 10:25:15 -0500 Subject: [PATCH] Remove discovery config validation from supervisor (#4937) * Remove discovery config validation from supervisor * Remove invalid test * Change validation to require a dictionary for compatibility --- supervisor/addons/validate.py | 15 ---- supervisor/api/discovery.py | 12 +-- supervisor/discovery/__init__.py | 12 +-- supervisor/discovery/services/__init__.py | 1 - supervisor/discovery/services/adguard.py | 9 -- supervisor/discovery/services/almond.py | 9 -- supervisor/discovery/services/deconz.py | 14 --- supervisor/discovery/services/esphome.py | 9 -- supervisor/discovery/services/homematic.py | 16 ---- supervisor/discovery/services/matter.py | 13 --- supervisor/discovery/services/motioneye.py | 6 -- supervisor/discovery/services/mqtt.py | 26 ------ supervisor/discovery/services/otbr.py | 13 --- supervisor/discovery/services/ozw.py | 15 ---- .../discovery/services/rtsp_to_webrtc.py | 9 -- supervisor/discovery/services/unifi.py | 9 -- supervisor/discovery/services/vlc_telnet.py | 14 --- supervisor/discovery/services/wyoming.py | 25 ------ supervisor/discovery/services/zwave_js.py | 13 --- supervisor/discovery/validate.py | 21 ----- tests/addons/test_config.py | 13 --- tests/api/test_discovery.py | 90 +++++++++++++------ tests/discovery/__init__.py | 1 - tests/discovery/test_adguard.py | 19 ---- tests/discovery/test_almond.py | 19 ---- tests/discovery/test_deconz.py | 22 ----- tests/discovery/test_esphome.py | 25 ------ tests/discovery/test_homematic.py | 22 ----- tests/discovery/test_matter.py | 22 ----- tests/discovery/test_motioneye.py | 17 ---- tests/discovery/test_mqtt.py | 21 ----- tests/discovery/test_otbr.py | 22 ----- tests/discovery/test_ozw.py | 22 ----- tests/discovery/test_rtsp_to_webrtc.py | 21 ----- tests/discovery/test_unifi.py | 19 ---- tests/discovery/test_validate.py | 21 ----- tests/discovery/test_vlc_telnet.py | 22 ----- tests/discovery/test_wyoming.py | 27 ------ tests/discovery/test_zwave_js.py | 22 ----- 39 files changed, 67 insertions(+), 641 deletions(-) delete mode 100644 supervisor/discovery/services/__init__.py delete mode 100644 supervisor/discovery/services/adguard.py delete mode 100644 supervisor/discovery/services/almond.py delete mode 100644 supervisor/discovery/services/deconz.py delete mode 100644 supervisor/discovery/services/esphome.py delete mode 100644 supervisor/discovery/services/homematic.py delete mode 100644 supervisor/discovery/services/matter.py delete mode 100644 supervisor/discovery/services/motioneye.py delete mode 100644 supervisor/discovery/services/mqtt.py delete mode 100644 supervisor/discovery/services/otbr.py delete mode 100644 supervisor/discovery/services/ozw.py delete mode 100644 supervisor/discovery/services/rtsp_to_webrtc.py delete mode 100644 supervisor/discovery/services/unifi.py delete mode 100644 supervisor/discovery/services/vlc_telnet.py delete mode 100644 supervisor/discovery/services/wyoming.py delete mode 100644 supervisor/discovery/services/zwave_js.py delete mode 100644 tests/discovery/__init__.py delete mode 100644 tests/discovery/test_adguard.py delete mode 100644 tests/discovery/test_almond.py delete mode 100644 tests/discovery/test_deconz.py delete mode 100644 tests/discovery/test_esphome.py delete mode 100644 tests/discovery/test_homematic.py delete mode 100644 tests/discovery/test_matter.py delete mode 100644 tests/discovery/test_motioneye.py delete mode 100644 tests/discovery/test_mqtt.py delete mode 100644 tests/discovery/test_otbr.py delete mode 100644 tests/discovery/test_ozw.py delete mode 100644 tests/discovery/test_rtsp_to_webrtc.py delete mode 100644 tests/discovery/test_unifi.py delete mode 100644 tests/discovery/test_validate.py delete mode 100644 tests/discovery/test_vlc_telnet.py delete mode 100644 tests/discovery/test_wyoming.py delete mode 100644 tests/discovery/test_zwave_js.py diff --git a/supervisor/addons/validate.py b/supervisor/addons/validate.py index 1158964568d..000b83f2b98 100644 --- a/supervisor/addons/validate.py +++ b/supervisor/addons/validate.py @@ -99,7 +99,6 @@ AddonStartup, AddonState, ) -from ..discovery.validate import valid_discovery_service from ..docker.const import Capabilities from ..validate import ( docker_image, @@ -190,20 +189,6 @@ def _warn_addon_config(config: dict[str, Any]): name, ) - invalid_services: list[str] = [] - for service in config.get(ATTR_DISCOVERY, []): - try: - valid_discovery_service(service) - except vol.Invalid: - invalid_services.append(service) - - if invalid_services: - _LOGGER.warning( - "Add-on lists the following unknown services for discovery: %s. Please report this to the maintainer of %s", - ", ".join(invalid_services), - name, - ) - return config diff --git a/supervisor/api/discovery.py b/supervisor/api/discovery.py index f3365dd83a7..5069839130d 100644 --- a/supervisor/api/discovery.py +++ b/supervisor/api/discovery.py @@ -15,7 +15,6 @@ AddonState, ) from ..coresys import CoreSysAttributes -from ..discovery.validate import valid_discovery_service from ..exceptions import APIError, APIForbidden from .utils import api_process, api_validate, require_home_assistant @@ -24,7 +23,7 @@ SCHEMA_DISCOVERY = vol.Schema( { vol.Required(ATTR_SERVICE): str, - vol.Optional(ATTR_CONFIG): vol.Maybe(dict), + vol.Required(ATTR_CONFIG): dict, } ) @@ -71,15 +70,6 @@ async def set_discovery(self, request): addon: Addon = request[REQUEST_FROM] service = body[ATTR_SERVICE] - try: - valid_discovery_service(service) - except vol.Invalid: - _LOGGER.warning( - "Received discovery message for unknown service %s from addon %s. Please report this to the maintainer of the add-on", - service, - addon.name, - ) - # Access? if body[ATTR_SERVICE] not in addon.discovery: _LOGGER.error( diff --git a/supervisor/discovery/__init__.py b/supervisor/discovery/__init__.py index b0fbd26cba2..04f5eb86226 100644 --- a/supervisor/discovery/__init__.py +++ b/supervisor/discovery/__init__.py @@ -7,14 +7,12 @@ from uuid import UUID, uuid4 import attr -import voluptuous as vol -from voluptuous.humanize import humanize_error from ..const import ATTR_CONFIG, ATTR_DISCOVERY, FILE_HASSIO_DISCOVERY from ..coresys import CoreSys, CoreSysAttributes -from ..exceptions import DiscoveryError, HomeAssistantAPIError +from ..exceptions import HomeAssistantAPIError from ..utils.common import FileConfiguration -from .validate import SCHEMA_DISCOVERY_CONFIG, valid_discovery_config +from .validate import SCHEMA_DISCOVERY_CONFIG if TYPE_CHECKING: from ..addons.addon import Addon @@ -75,12 +73,6 @@ def list_messages(self) -> list[Message]: def send(self, addon: Addon, service: str, config: dict[str, Any]) -> Message: """Send a discovery message to Home Assistant.""" - try: - config = valid_discovery_config(service, config) - except vol.Invalid as err: - _LOGGER.error("Invalid discovery %s config", humanize_error(config, err)) - raise DiscoveryError() from err - # Create message message = Message(addon.slug, service, config) diff --git a/supervisor/discovery/services/__init__.py b/supervisor/discovery/services/__init__.py deleted file mode 100644 index 5a423090da2..00000000000 --- a/supervisor/discovery/services/__init__.py +++ /dev/null @@ -1 +0,0 @@ -"""Discovery service modules.""" diff --git a/supervisor/discovery/services/adguard.py b/supervisor/discovery/services/adguard.py deleted file mode 100644 index 20faea8039a..00000000000 --- a/supervisor/discovery/services/adguard.py +++ /dev/null @@ -1,9 +0,0 @@ -"""Discovery service for AdGuard.""" -import voluptuous as vol - -from ...validate import network_port -from ..const import ATTR_HOST, ATTR_PORT - -SCHEMA = vol.Schema( - {vol.Required(ATTR_HOST): str, vol.Required(ATTR_PORT): network_port} -) diff --git a/supervisor/discovery/services/almond.py b/supervisor/discovery/services/almond.py deleted file mode 100644 index 6ed2d37f259..00000000000 --- a/supervisor/discovery/services/almond.py +++ /dev/null @@ -1,9 +0,0 @@ -"""Discovery service for Almond.""" -import voluptuous as vol - -from ...validate import network_port -from ..const import ATTR_HOST, ATTR_PORT - -SCHEMA = vol.Schema( - {vol.Required(ATTR_HOST): str, vol.Required(ATTR_PORT): network_port} -) diff --git a/supervisor/discovery/services/deconz.py b/supervisor/discovery/services/deconz.py deleted file mode 100644 index 87307842c3f..00000000000 --- a/supervisor/discovery/services/deconz.py +++ /dev/null @@ -1,14 +0,0 @@ -"""Discovery service for MQTT.""" -import voluptuous as vol - -from ...validate import network_port -from ..const import ATTR_API_KEY, ATTR_HOST, ATTR_PORT, ATTR_SERIAL - -SCHEMA = vol.Schema( - { - vol.Required(ATTR_HOST): str, - vol.Required(ATTR_PORT): network_port, - vol.Required(ATTR_SERIAL): str, - vol.Required(ATTR_API_KEY): str, - } -) diff --git a/supervisor/discovery/services/esphome.py b/supervisor/discovery/services/esphome.py deleted file mode 100644 index f7693e073a3..00000000000 --- a/supervisor/discovery/services/esphome.py +++ /dev/null @@ -1,9 +0,0 @@ -"""Discovery service for the ESPHome Dashboard.""" -import voluptuous as vol - -from ...validate import network_port -from ..const import ATTR_HOST, ATTR_PORT - -SCHEMA = vol.Schema( - {vol.Required(ATTR_HOST): str, vol.Required(ATTR_PORT): network_port} -) diff --git a/supervisor/discovery/services/homematic.py b/supervisor/discovery/services/homematic.py deleted file mode 100644 index 0fc4ed0eafc..00000000000 --- a/supervisor/discovery/services/homematic.py +++ /dev/null @@ -1,16 +0,0 @@ -"""Discovery service for HomeMatic.""" -import voluptuous as vol - -from ...validate import network_port -from ..const import ATTR_HOST, ATTR_PORT - -SCHEMA = vol.Schema( - { - str: vol.Schema( - { - vol.Required(ATTR_HOST): str, - vol.Required(ATTR_PORT): network_port, - } - ) - } -) diff --git a/supervisor/discovery/services/matter.py b/supervisor/discovery/services/matter.py deleted file mode 100644 index b548c217242..00000000000 --- a/supervisor/discovery/services/matter.py +++ /dev/null @@ -1,13 +0,0 @@ -"""Discovery service for Matter Server.""" -import voluptuous as vol - -from ...validate import network_port -from ..const import ATTR_HOST, ATTR_PORT - -# pylint: disable=no-value-for-parameter -SCHEMA = vol.Schema( - { - vol.Required(ATTR_HOST): str, - vol.Required(ATTR_PORT): network_port, - } -) diff --git a/supervisor/discovery/services/motioneye.py b/supervisor/discovery/services/motioneye.py deleted file mode 100644 index 6de5d25889e..00000000000 --- a/supervisor/discovery/services/motioneye.py +++ /dev/null @@ -1,6 +0,0 @@ -"""Discovery service for motionEye.""" -import voluptuous as vol - -from ..const import ATTR_URL - -SCHEMA = vol.Schema({vol.Required(ATTR_URL): str}) diff --git a/supervisor/discovery/services/mqtt.py b/supervisor/discovery/services/mqtt.py deleted file mode 100644 index f8a394e9cd1..00000000000 --- a/supervisor/discovery/services/mqtt.py +++ /dev/null @@ -1,26 +0,0 @@ -"""Discovery service for MQTT.""" -import voluptuous as vol - -from ...validate import network_port -from ..const import ( - ATTR_HOST, - ATTR_PASSWORD, - ATTR_PORT, - ATTR_PROTOCOL, - ATTR_SSL, - ATTR_USERNAME, -) - -# pylint: disable=no-value-for-parameter -SCHEMA = vol.Schema( - { - vol.Required(ATTR_HOST): str, - vol.Required(ATTR_PORT): network_port, - vol.Optional(ATTR_USERNAME): str, - vol.Optional(ATTR_PASSWORD): str, - vol.Optional(ATTR_SSL, default=False): vol.Boolean(), - vol.Optional(ATTR_PROTOCOL, default="3.1.1"): vol.All( - str, vol.In(["3.1", "3.1.1"]) - ), - } -) diff --git a/supervisor/discovery/services/otbr.py b/supervisor/discovery/services/otbr.py deleted file mode 100644 index 24992e59c78..00000000000 --- a/supervisor/discovery/services/otbr.py +++ /dev/null @@ -1,13 +0,0 @@ -"""Discovery service for OpenThread Border Router.""" -import voluptuous as vol - -from ...validate import network_port -from ..const import ATTR_HOST, ATTR_PORT - -# pylint: disable=no-value-for-parameter -SCHEMA = vol.Schema( - { - vol.Required(ATTR_HOST): str, - vol.Required(ATTR_PORT): network_port, - } -) diff --git a/supervisor/discovery/services/ozw.py b/supervisor/discovery/services/ozw.py deleted file mode 100644 index 265b7d5b56f..00000000000 --- a/supervisor/discovery/services/ozw.py +++ /dev/null @@ -1,15 +0,0 @@ -"""Discovery service for OpenZwave MQTT.""" -import voluptuous as vol - -from ...validate import network_port -from ..const import ATTR_HOST, ATTR_PASSWORD, ATTR_PORT, ATTR_USERNAME - -# pylint: disable=no-value-for-parameter -SCHEMA = vol.Schema( - { - vol.Required(ATTR_HOST): str, - vol.Required(ATTR_PORT): network_port, - vol.Required(ATTR_USERNAME): str, - vol.Required(ATTR_PASSWORD): str, - } -) diff --git a/supervisor/discovery/services/rtsp_to_webrtc.py b/supervisor/discovery/services/rtsp_to_webrtc.py deleted file mode 100644 index f24bc1cc7e1..00000000000 --- a/supervisor/discovery/services/rtsp_to_webrtc.py +++ /dev/null @@ -1,9 +0,0 @@ -"""Discovery service for RTSPtoWebRTC.""" -import voluptuous as vol - -from ...validate import network_port -from ..const import ATTR_HOST, ATTR_PORT - -SCHEMA = vol.Schema( - {vol.Required(ATTR_HOST): str, vol.Required(ATTR_PORT): network_port} -) diff --git a/supervisor/discovery/services/unifi.py b/supervisor/discovery/services/unifi.py deleted file mode 100644 index 72f95959585..00000000000 --- a/supervisor/discovery/services/unifi.py +++ /dev/null @@ -1,9 +0,0 @@ -"""Discovery service for UniFi.""" -import voluptuous as vol - -from ...validate import network_port -from ..const import ATTR_HOST, ATTR_PORT - -SCHEMA = vol.Schema( - {vol.Required(ATTR_HOST): str, vol.Required(ATTR_PORT): network_port} -) diff --git a/supervisor/discovery/services/vlc_telnet.py b/supervisor/discovery/services/vlc_telnet.py deleted file mode 100644 index 7217d4b789e..00000000000 --- a/supervisor/discovery/services/vlc_telnet.py +++ /dev/null @@ -1,14 +0,0 @@ -"""Discovery service for VLC Telnet.""" -import voluptuous as vol - -from ...validate import network_port -from ..const import ATTR_HOST, ATTR_PASSWORD, ATTR_PORT - -# pylint: disable=no-value-for-parameter -SCHEMA = vol.Schema( - { - vol.Required(ATTR_HOST): str, - vol.Required(ATTR_PORT): network_port, - vol.Required(ATTR_PASSWORD): str, - } -) diff --git a/supervisor/discovery/services/wyoming.py b/supervisor/discovery/services/wyoming.py deleted file mode 100644 index fc1d571e6fa..00000000000 --- a/supervisor/discovery/services/wyoming.py +++ /dev/null @@ -1,25 +0,0 @@ -"""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}) diff --git a/supervisor/discovery/services/zwave_js.py b/supervisor/discovery/services/zwave_js.py deleted file mode 100644 index 244317741fc..00000000000 --- a/supervisor/discovery/services/zwave_js.py +++ /dev/null @@ -1,13 +0,0 @@ -"""Discovery service for Zwave JS.""" -import voluptuous as vol - -from ...validate import network_port -from ..const import ATTR_HOST, ATTR_PORT - -# pylint: disable=no-value-for-parameter -SCHEMA = vol.Schema( - { - vol.Required(ATTR_HOST): str, - vol.Required(ATTR_PORT): network_port, - } -) diff --git a/supervisor/discovery/validate.py b/supervisor/discovery/validate.py index 17ada59b34e..a577073d893 100644 --- a/supervisor/discovery/validate.py +++ b/supervisor/discovery/validate.py @@ -1,6 +1,4 @@ """Validate services schema.""" -from importlib import import_module -from pathlib import Path import voluptuous as vol @@ -8,25 +6,6 @@ from ..utils.validate import schema_or from ..validate import uuid_match - -def valid_discovery_service(service): - """Validate service name.""" - service_file = Path(__file__).parent.joinpath(f"services/{service}.py") - if not service_file.exists(): - raise vol.Invalid(f"Service {service} not found") from None - return service - - -def valid_discovery_config(service, config): - """Validate service name.""" - try: - service_mod = import_module(f".services.{service}", "supervisor.discovery") - except ImportError: - raise vol.Invalid(f"Service {service} not found") from None - - return service_mod.SCHEMA(config) - - SCHEMA_DISCOVERY = vol.Schema( [ vol.Schema( diff --git a/tests/addons/test_config.py b/tests/addons/test_config.py index fec4b44cd46..5c36757b467 100644 --- a/tests/addons/test_config.py +++ b/tests/addons/test_config.py @@ -1,7 +1,5 @@ """Validate Add-on configs.""" -import logging -from unittest.mock import Mock import pytest import voluptuous as vol @@ -288,14 +286,3 @@ def test_valid_slug(): config["slug"] = "complemento telefónico" with pytest.raises(vol.Invalid): assert vd.SCHEMA_ADDON_CONFIG(config) - - -def test_invalid_discovery(capture_event: Mock, caplog: pytest.LogCaptureFixture): - """Test invalid discovery.""" - config = load_json_fixture("basic-addon-config.json") - config["discovery"] = ["mqtt", "junk", "junk2"] - - assert vd.SCHEMA_ADDON_CONFIG(config) - - with caplog.at_level(logging.WARNING): - assert "unknown services for discovery: junk, junk2" in caplog.text diff --git a/tests/api/test_discovery.py b/tests/api/test_discovery.py index 6dc5f6892f4..16dc0a98eb0 100644 --- a/tests/api/test_discovery.py +++ b/tests/api/test_discovery.py @@ -1,8 +1,7 @@ """Test discovery API.""" import logging -from unittest.mock import ANY, MagicMock, patch -from uuid import uuid4 +from unittest.mock import ANY, AsyncMock, MagicMock, patch from aiohttp.test_utils import TestClient import pytest @@ -10,9 +9,10 @@ from supervisor.addons.addon import Addon from supervisor.const import AddonState from supervisor.coresys import CoreSys -from supervisor.discovery import Discovery, Message +from supervisor.discovery import Message from tests.common import load_json_fixture +from tests.const import TEST_ADDON_SLUG @pytest.mark.parametrize("api_client", ["local_ssh"], indirect=True) @@ -23,7 +23,9 @@ async def test_api_discovery_forbidden( caplog.clear() with caplog.at_level(logging.ERROR): - resp = await api_client.post("/discovery", json={"service": "mqtt"}) + resp = await api_client.post( + "/discovery", json={"service": "mqtt", "config": {}} + ) assert resp.status == 403 result = await resp.json() @@ -35,28 +37,6 @@ async def test_api_discovery_forbidden( assert "Please report this to the maintainer of the add-on" in caplog.text -@pytest.mark.parametrize("api_client", ["local_ssh"], indirect=True) -async def test_api_discovery_unknown_service( - api_client: TestClient, caplog: pytest.LogCaptureFixture, install_addon_ssh: Addon -): - """Test addon sending discovery message for an unkown service.""" - caplog.clear() - install_addon_ssh.data["discovery"] = ["junk"] - - message = MagicMock() - message.uuid = uuid4().hex - - with caplog.at_level(logging.WARNING), patch.object( - Discovery, "send", return_value=message - ): - resp = await api_client.post("/discovery", json={"service": "junk"}) - - assert resp.status == 200 - result = await resp.json() - assert result["data"]["uuid"] == message.uuid - assert "Please report this to the maintainer of the add-on" in caplog.text - - @pytest.mark.parametrize( "skip_state", [AddonState.ERROR, AddonState.STOPPED, AddonState.STARTUP] ) @@ -97,3 +77,61 @@ async def test_api_list_discovery( assert resp.status == 200 result = await resp.json() assert result["data"]["discovery"] == [] + + +@pytest.mark.parametrize("api_client", [TEST_ADDON_SLUG], indirect=True) +async def test_api_send_del_discovery( + api_client: TestClient, coresys: CoreSys, install_addon_ssh: Addon +): + """Test adding and removing discovery.""" + install_addon_ssh.data["discovery"] = ["test"] + coresys.homeassistant.api.ensure_access_token = AsyncMock() + coresys.websession.post = MagicMock() + + resp = await api_client.post("/discovery", json={"service": "test", "config": {}}) + assert resp.status == 200 + result = await resp.json() + uuid = result["data"]["uuid"] + coresys.websession.post.assert_called_once() + assert ( + coresys.websession.post.call_args.args[0] + == f"http://172.30.32.1:8123/api/hassio_push/discovery/{uuid}" + ) + assert coresys.websession.post.call_args.kwargs["json"] == { + "addon": TEST_ADDON_SLUG, + "service": "test", + "uuid": uuid, + } + + message = coresys.discovery.get(uuid) + assert message.addon == TEST_ADDON_SLUG + assert message.service == "test" + assert message.config == {} + + coresys.websession.delete = MagicMock() + resp = await api_client.delete(f"/discovery/{uuid}") + assert resp.status == 200 + coresys.websession.delete.assert_called_once() + assert ( + coresys.websession.delete.call_args.args[0] + == f"http://172.30.32.1:8123/api/hassio_push/discovery/{uuid}" + ) + assert coresys.websession.delete.call_args.kwargs["json"] == { + "addon": TEST_ADDON_SLUG, + "service": "test", + "uuid": uuid, + } + + assert coresys.discovery.get(uuid) is None + + +@pytest.mark.parametrize("api_client", [TEST_ADDON_SLUG], indirect=True) +async def test_api_invalid_discovery(api_client: TestClient, install_addon_ssh: Addon): + """Test invalid discovery messages.""" + install_addon_ssh.data["discovery"] = ["test"] + + resp = await api_client.post("/discovery", json={"service": "test"}) + assert resp.status == 400 + + resp = await api_client.post("/discovery", json={"service": "test", "config": None}) + assert resp.status == 400 diff --git a/tests/discovery/__init__.py b/tests/discovery/__init__.py deleted file mode 100644 index ce066fb26e1..00000000000 --- a/tests/discovery/__init__.py +++ /dev/null @@ -1 +0,0 @@ -"""Tests for discovery.""" diff --git a/tests/discovery/test_adguard.py b/tests/discovery/test_adguard.py deleted file mode 100644 index 0dda003a2ee..00000000000 --- a/tests/discovery/test_adguard.py +++ /dev/null @@ -1,19 +0,0 @@ -"""Test adguard discovery.""" - -import pytest -import voluptuous as vol - -from supervisor.discovery.validate import valid_discovery_config - - -def test_good_config(): - """Test good adguard config.""" - - valid_discovery_config("adguard", {"host": "test", "port": 3812}) - - -def test_bad_config(): - """Test bad adguard config.""" - - with pytest.raises(vol.Invalid): - valid_discovery_config("adguard", {"host": "test"}) diff --git a/tests/discovery/test_almond.py b/tests/discovery/test_almond.py deleted file mode 100644 index 4d969d6b9bc..00000000000 --- a/tests/discovery/test_almond.py +++ /dev/null @@ -1,19 +0,0 @@ -"""Test almond discovery.""" - -import pytest -import voluptuous as vol - -from supervisor.discovery.validate import valid_discovery_config - - -def test_good_config(): - """Test good almond config.""" - - valid_discovery_config("almond", {"host": "test", "port": 3812}) - - -def test_bad_config(): - """Test bad almond config.""" - - with pytest.raises(vol.Invalid): - valid_discovery_config("almond", {"host": "test"}) diff --git a/tests/discovery/test_deconz.py b/tests/discovery/test_deconz.py deleted file mode 100644 index 5eb4eeaf9f5..00000000000 --- a/tests/discovery/test_deconz.py +++ /dev/null @@ -1,22 +0,0 @@ -"""Test DeConz discovery.""" - -import pytest -import voluptuous as vol - -from supervisor.discovery.validate import valid_discovery_config - - -def test_good_config(): - """Test good deconz config.""" - - valid_discovery_config( - "deconz", - {"host": "test", "port": 3812, "api_key": "MY_api_KEY99", "serial": "xyz"}, - ) - - -def test_bad_config(): - """Test bad deconz config.""" - - with pytest.raises(vol.Invalid): - valid_discovery_config("deconz", {"host": "test", "port": 8080}) diff --git a/tests/discovery/test_esphome.py b/tests/discovery/test_esphome.py deleted file mode 100644 index d7bf2eaab68..00000000000 --- a/tests/discovery/test_esphome.py +++ /dev/null @@ -1,25 +0,0 @@ -"""Test ESPHome Dashboard discovery.""" - -import pytest -import voluptuous as vol - -from supervisor.discovery.validate import valid_discovery_config - - -def test_good_config(): - """Test good ESPHome config.""" - - valid_discovery_config("esphome", {"host": "test", "port": 6052}) - - -def test_bad_config(): - """Test bad ESPHome config.""" - - with pytest.raises(vol.Invalid): - valid_discovery_config("esphome", {"host": "test"}) - - with pytest.raises(vol.Invalid): - valid_discovery_config("esphome", {"port": 6052}) - - with pytest.raises(vol.Invalid): - valid_discovery_config("esphome", {"port": -1}) diff --git a/tests/discovery/test_homematic.py b/tests/discovery/test_homematic.py deleted file mode 100644 index dfd191535d0..00000000000 --- a/tests/discovery/test_homematic.py +++ /dev/null @@ -1,22 +0,0 @@ -"""Test HomeMatic discovery.""" - -import pytest -import voluptuous as vol - -from supervisor.discovery.validate import valid_discovery_config - - -def test_good_config(): - """Test good homematic config.""" - - valid_discovery_config( - "homematic", - {"ip": {"host": "test", "port": 3812}, "rf": {"host": "test", "port": 3712}}, - ) - - -def test_bad_config(): - """Test bad homematic config.""" - - with pytest.raises(vol.Invalid): - valid_discovery_config("homematic", {"test": {"bla": "test", "port": 8080}}) diff --git a/tests/discovery/test_matter.py b/tests/discovery/test_matter.py deleted file mode 100644 index 606cd322d90..00000000000 --- a/tests/discovery/test_matter.py +++ /dev/null @@ -1,22 +0,0 @@ -"""Test Matter Server discovery.""" - -import pytest -import voluptuous as vol - -from supervisor.discovery.validate import valid_discovery_config - - -def test_good_config(): - """Test good Matter Server config.""" - - valid_discovery_config( - "matter", - {"host": "test", "port": 3812}, - ) - - -def test_bad_config(): - """Test bad Matter Server config.""" - - with pytest.raises(vol.Invalid): - valid_discovery_config("matter", {"host": "test"}) diff --git a/tests/discovery/test_motioneye.py b/tests/discovery/test_motioneye.py deleted file mode 100644 index 8c9ab2b3f82..00000000000 --- a/tests/discovery/test_motioneye.py +++ /dev/null @@ -1,17 +0,0 @@ -"""Test motionEye discovery.""" - -import pytest -import voluptuous as vol - -from supervisor.discovery.validate import valid_discovery_config - - -def test_good_config() -> None: - """Test good motionEye config.""" - valid_discovery_config("motioneye", {"url": "http://example.com:1234"}) - - -def test_bad_config() -> None: - """Test bad motionEye config.""" - with pytest.raises(vol.Invalid): - valid_discovery_config("motioneye", {}) diff --git a/tests/discovery/test_mqtt.py b/tests/discovery/test_mqtt.py deleted file mode 100644 index 8cfe6421698..00000000000 --- a/tests/discovery/test_mqtt.py +++ /dev/null @@ -1,21 +0,0 @@ -"""Test MQTT discovery.""" - -import pytest -import voluptuous as vol - -from supervisor.discovery.validate import valid_discovery_config - - -def test_good_config(): - """Test good mqtt config.""" - - valid_discovery_config( - "mqtt", {"host": "test", "port": 3812, "username": "bla", "ssl": True} - ) - - -def test_bad_config(): - """Test bad mqtt config.""" - - with pytest.raises(vol.Invalid): - valid_discovery_config("mqtt", {"host": "test", "username": "bla", "ssl": True}) diff --git a/tests/discovery/test_otbr.py b/tests/discovery/test_otbr.py deleted file mode 100644 index 52048cfb4e1..00000000000 --- a/tests/discovery/test_otbr.py +++ /dev/null @@ -1,22 +0,0 @@ -"""Test OTBR discovery.""" - -import pytest -import voluptuous as vol - -from supervisor.discovery.validate import valid_discovery_config - - -def test_good_config(): - """Test good OTBR config.""" - - valid_discovery_config( - "otbr", - {"host": "test", "port": 3812}, - ) - - -def test_bad_config(): - """Test bad OTBR config.""" - - with pytest.raises(vol.Invalid): - valid_discovery_config("otbr", {"host": "test"}) diff --git a/tests/discovery/test_ozw.py b/tests/discovery/test_ozw.py deleted file mode 100644 index b256e53b6ca..00000000000 --- a/tests/discovery/test_ozw.py +++ /dev/null @@ -1,22 +0,0 @@ -"""Test OpenZwave MQTT discovery.""" - -import pytest -import voluptuous as vol - -from supervisor.discovery.validate import valid_discovery_config - - -def test_good_config(): - """Test good zwave mqtt config.""" - - valid_discovery_config( - "ozw", - {"host": "test", "port": 3812, "username": "bla", "password": "test"}, - ) - - -def test_bad_config(): - """Test bad zwave mqtt config.""" - - with pytest.raises(vol.Invalid): - valid_discovery_config("ozw", {"host": "test", "username": "bla", "ssl": True}) diff --git a/tests/discovery/test_rtsp_to_webrtc.py b/tests/discovery/test_rtsp_to_webrtc.py deleted file mode 100644 index 9a4c7a20fd2..00000000000 --- a/tests/discovery/test_rtsp_to_webrtc.py +++ /dev/null @@ -1,21 +0,0 @@ -"""Test rtsp_to_webrtc discovery.""" - -import pytest -import voluptuous as vol - -from supervisor.discovery.validate import valid_discovery_config - -SERVICE = "rtsp_to_webrtc" - - -def test_good_config(): - """Test good config.""" - - valid_discovery_config(SERVICE, {"host": "test", "port": 3812}) - - -def test_bad_config(): - """Test bad config.""" - - with pytest.raises(vol.Invalid): - valid_discovery_config(SERVICE, {"host": "test"}) diff --git a/tests/discovery/test_unifi.py b/tests/discovery/test_unifi.py deleted file mode 100644 index 7ebe23413f9..00000000000 --- a/tests/discovery/test_unifi.py +++ /dev/null @@ -1,19 +0,0 @@ -"""Test unifi discovery.""" - -import pytest -import voluptuous as vol - -from supervisor.discovery.validate import valid_discovery_config - - -def test_good_config(): - """Test good unifi config.""" - - valid_discovery_config("unifi", {"host": "test", "port": 3812}) - - -def test_bad_config(): - """Test bad unifi config.""" - - with pytest.raises(vol.Invalid): - valid_discovery_config("unifi", {"host": "test"}) diff --git a/tests/discovery/test_validate.py b/tests/discovery/test_validate.py deleted file mode 100644 index 34129dfbcf8..00000000000 --- a/tests/discovery/test_validate.py +++ /dev/null @@ -1,21 +0,0 @@ -"""Test validate of discovery.""" - -import pytest -import voluptuous as vol - -from supervisor.discovery import validate - - -def test_valid_services(): - """Validate that service is valid.""" - - for service in ("mqtt", "deconz"): - validate.valid_discovery_service(service) - - -def test_invalid_services(): - """Test that validate is invalid for a service.""" - - for service in ("fadsfasd", "203432"): - with pytest.raises(vol.Invalid): - validate.valid_discovery_service(service) diff --git a/tests/discovery/test_vlc_telnet.py b/tests/discovery/test_vlc_telnet.py deleted file mode 100644 index 3129c49bf08..00000000000 --- a/tests/discovery/test_vlc_telnet.py +++ /dev/null @@ -1,22 +0,0 @@ -"""Test VLC Telnet discovery.""" - -import pytest -import voluptuous as vol - -from supervisor.discovery.validate import valid_discovery_config - - -def test_good_config(): - """Test good vlc telnet config.""" - - valid_discovery_config( - "vlc_telnet", - {"host": "test", "port": 3812, "password": "darksideofthemoon"}, - ) - - -def test_bad_config(): - """Test bad vlc telnet config.""" - - with pytest.raises(vol.Invalid): - valid_discovery_config("vlc_telnet", {"host": "test", "port": 8283}) diff --git a/tests/discovery/test_wyoming.py b/tests/discovery/test_wyoming.py deleted file mode 100644 index f17c0967007..00000000000 --- a/tests/discovery/test_wyoming.py +++ /dev/null @@ -1,27 +0,0 @@ -"""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"}) diff --git a/tests/discovery/test_zwave_js.py b/tests/discovery/test_zwave_js.py deleted file mode 100644 index fb1d6cffde5..00000000000 --- a/tests/discovery/test_zwave_js.py +++ /dev/null @@ -1,22 +0,0 @@ -"""Test Zwave JS discovery.""" - -import pytest -import voluptuous as vol - -from supervisor.discovery.validate import valid_discovery_config - - -def test_good_config(): - """Test good zwave js config.""" - - valid_discovery_config( - "zwave_js", - {"host": "test", "port": 3812}, - ) - - -def test_bad_config(): - """Test bad zwave js config.""" - - with pytest.raises(vol.Invalid): - valid_discovery_config("zwave_js", {"host": "test"})