mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Fix CORS error in emulated_hue (#59570)
This commit is contained in:
parent
8de0c7204a
commit
6ef64f6b1c
@ -94,11 +94,15 @@ class HomeAssistantView:
|
|||||||
for url in urls:
|
for url in urls:
|
||||||
routes.append(router.add_route(method, url, handler))
|
routes.append(router.add_route(method, url, handler))
|
||||||
|
|
||||||
allow_cors = (
|
# Use `get` because CORS middleware is not be loaded in emulated_hue
|
||||||
app["allow_all_cors"] if self.cors_allowed else app["allow_configured_cors"]
|
if self.cors_allowed:
|
||||||
)
|
allow_cors = app.get("allow_all_cors")
|
||||||
for route in routes:
|
else:
|
||||||
allow_cors(route)
|
allow_cors = app.get("allow_configured_cors")
|
||||||
|
|
||||||
|
if allow_cors:
|
||||||
|
for route in routes:
|
||||||
|
allow_cors(route)
|
||||||
|
|
||||||
|
|
||||||
def request_handler_factory(
|
def request_handler_factory(
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
"""Test the Emulated Hue component."""
|
"""Test the Emulated Hue component."""
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
from homeassistant.components.emulated_hue import (
|
from homeassistant.components.emulated_hue import (
|
||||||
DATA_KEY,
|
DATA_KEY,
|
||||||
@ -7,6 +8,7 @@ from homeassistant.components.emulated_hue import (
|
|||||||
SAVE_DELAY,
|
SAVE_DELAY,
|
||||||
Config,
|
Config,
|
||||||
)
|
)
|
||||||
|
from homeassistant.setup import async_setup_component
|
||||||
from homeassistant.util import utcnow
|
from homeassistant.util import utcnow
|
||||||
|
|
||||||
from tests.common import async_fire_time_changed
|
from tests.common import async_fire_time_changed
|
||||||
@ -113,3 +115,12 @@ def test_config_alexa_entity_id_to_number():
|
|||||||
|
|
||||||
entity_id = conf.number_to_entity_id("light.test")
|
entity_id = conf.number_to_entity_id("light.test")
|
||||||
assert entity_id == "light.test"
|
assert entity_id == "light.test"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_setup_works(hass):
|
||||||
|
"""Test setup works."""
|
||||||
|
hass.config.components.add("network")
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.emulated_hue.create_upnp_datagram_endpoint"
|
||||||
|
), patch("homeassistant.components.emulated_hue.async_get_source_ip"):
|
||||||
|
assert await async_setup_component(hass, "emulated_hue", {})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user