Blank out discovery info (#56097)

This commit is contained in:
Joakim Sørensen 2021-09-11 21:34:19 +02:00 committed by GitHub
parent 64fd496932
commit bcb3c426f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 31 deletions

View File

@ -1,6 +1,5 @@
"""Rest API for Home Assistant."""
import asyncio
from contextlib import suppress
import json
import logging
@ -30,15 +29,12 @@ from homeassistant.const import (
URL_API_STATES,
URL_API_STREAM,
URL_API_TEMPLATE,
__version__,
)
import homeassistant.core as ha
from homeassistant.exceptions import ServiceNotFound, TemplateError, Unauthorized
from homeassistant.helpers import template
from homeassistant.helpers.json import JSONEncoder
from homeassistant.helpers.network import NoURLAvailableError, get_url
from homeassistant.helpers.service import async_get_all_descriptions
from homeassistant.helpers.system_info import async_get_system_info
_LOGGER = logging.getLogger(__name__)
@ -173,7 +169,11 @@ class APIConfigView(HomeAssistantView):
class APIDiscoveryView(HomeAssistantView):
"""View to provide Discovery information."""
"""
View to provide Discovery information.
DEPRECATED: To be removed in 2022.1
"""
requires_auth = False
url = URL_API_DISCOVERY_INFO
@ -181,32 +181,18 @@ class APIDiscoveryView(HomeAssistantView):
async def get(self, request):
"""Get discovery information."""
hass = request.app["hass"]
uuid = await hass.helpers.instance_id.async_get()
system_info = await async_get_system_info(hass)
data = {
ATTR_UUID: uuid,
ATTR_BASE_URL: None,
ATTR_EXTERNAL_URL: None,
ATTR_INTERNAL_URL: None,
ATTR_LOCATION_NAME: hass.config.location_name,
ATTR_INSTALLATION_TYPE: system_info[ATTR_INSTALLATION_TYPE],
# always needs authentication
ATTR_REQUIRES_API_PASSWORD: True,
ATTR_VERSION: __version__,
}
with suppress(NoURLAvailableError):
data["external_url"] = get_url(hass, allow_internal=False)
with suppress(NoURLAvailableError):
data["internal_url"] = get_url(hass, allow_external=False)
# Set old base URL based on external or internal
data["base_url"] = data["external_url"] or data["internal_url"]
return self.json(data)
return self.json(
{
ATTR_UUID: "",
ATTR_BASE_URL: "",
ATTR_EXTERNAL_URL: "",
ATTR_INTERNAL_URL: "",
ATTR_LOCATION_NAME: "",
ATTR_INSTALLATION_TYPE: "",
ATTR_REQUIRES_API_PASSWORD: True,
ATTR_VERSION: "",
}
)
class APIStatesView(HomeAssistantView):

View File

@ -559,3 +559,20 @@ async def test_api_call_service_bad_data(hass, mock_api_client):
"/api/services/test_domain/test_service", json={"hello": 5}
)
assert resp.status == 400
async def test_api_get_discovery_info(hass, mock_api_client):
"""Test the return of discovery info."""
resp = await mock_api_client.get(const.URL_API_DISCOVERY_INFO)
result = await resp.json()
assert result == {
"base_url": "",
"external_url": "",
"installation_type": "",
"internal_url": "",
"location_name": "",
"requires_api_password": True,
"uuid": "",
"version": "",
}