mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 13:57:10 +00:00
Update emulated_hue to allow getting bridge config without username (#38986)
* Allow bridge config without username * Updated emulated_hue tests * Test cleanup
This commit is contained in:
parent
1af6c04111
commit
1505343b4b
@ -111,6 +111,7 @@ async def async_setup(hass, yaml_config):
|
|||||||
|
|
||||||
DescriptionXmlView(config).register(app, app.router)
|
DescriptionXmlView(config).register(app, app.router)
|
||||||
HueUsernameView().register(app, app.router)
|
HueUsernameView().register(app, app.router)
|
||||||
|
HueConfigView(config).register(app, app.router)
|
||||||
HueUnauthorizedUser().register(app, app.router)
|
HueUnauthorizedUser().register(app, app.router)
|
||||||
HueAllLightsStateView(config).register(app, app.router)
|
HueAllLightsStateView(config).register(app, app.router)
|
||||||
HueOneLightStateView(config).register(app, app.router)
|
HueOneLightStateView(config).register(app, app.router)
|
||||||
@ -118,7 +119,6 @@ async def async_setup(hass, yaml_config):
|
|||||||
HueAllGroupsStateView(config).register(app, app.router)
|
HueAllGroupsStateView(config).register(app, app.router)
|
||||||
HueGroupView(config).register(app, app.router)
|
HueGroupView(config).register(app, app.router)
|
||||||
HueFullStateView(config).register(app, app.router)
|
HueFullStateView(config).register(app, app.router)
|
||||||
HueConfigView(config).register(app, app.router)
|
|
||||||
|
|
||||||
upnp_listener = UPNPResponderThread(
|
upnp_listener = UPNPResponderThread(
|
||||||
config.host_ip_addr,
|
config.host_ip_addr,
|
||||||
|
@ -246,6 +246,7 @@ class HueConfigView(HomeAssistantView):
|
|||||||
"""Return config view of emulated hue."""
|
"""Return config view of emulated hue."""
|
||||||
|
|
||||||
url = "/api/{username}/config"
|
url = "/api/{username}/config"
|
||||||
|
extra_urls = ["/api/config"]
|
||||||
name = "emulated_hue:username:config"
|
name = "emulated_hue:username:config"
|
||||||
requires_auth = False
|
requires_auth = False
|
||||||
|
|
||||||
@ -254,12 +255,10 @@ class HueConfigView(HomeAssistantView):
|
|||||||
self.config = config
|
self.config = config
|
||||||
|
|
||||||
@core.callback
|
@core.callback
|
||||||
def get(self, request, username):
|
def get(self, request, username=""):
|
||||||
"""Process a request to get the configuration."""
|
"""Process a request to get the configuration."""
|
||||||
if not is_local(ip_address(request.remote)):
|
if not is_local(ip_address(request.remote)):
|
||||||
return self.json_message("only local IPs allowed", HTTP_UNAUTHORIZED)
|
return self.json_message("only local IPs allowed", HTTP_UNAUTHORIZED)
|
||||||
if username != HUE_API_USERNAME:
|
|
||||||
return self.json(UNAUTHORIZED_USER)
|
|
||||||
|
|
||||||
json_response = create_config_model(self.config, request)
|
json_response = create_config_model(self.config, request)
|
||||||
|
|
||||||
|
@ -467,6 +467,24 @@ async def test_discover_config(hue_client):
|
|||||||
assert "linkbutton" in config_json
|
assert "linkbutton" in config_json
|
||||||
assert config_json["linkbutton"] is True
|
assert config_json["linkbutton"] is True
|
||||||
|
|
||||||
|
# Test without username
|
||||||
|
result = await hue_client.get("/api/config")
|
||||||
|
|
||||||
|
assert result.status == 200
|
||||||
|
assert "application/json" in result.headers["content-type"]
|
||||||
|
|
||||||
|
config_json = await result.json()
|
||||||
|
assert "error" not in config_json
|
||||||
|
|
||||||
|
# Test with wrong username username
|
||||||
|
result = await hue_client.get("/api/wronguser/config")
|
||||||
|
|
||||||
|
assert result.status == 200
|
||||||
|
assert "application/json" in result.headers["content-type"]
|
||||||
|
|
||||||
|
config_json = await result.json()
|
||||||
|
assert "error" not in config_json
|
||||||
|
|
||||||
|
|
||||||
async def test_get_light_state(hass_hue, hue_client):
|
async def test_get_light_state(hass_hue, hue_client):
|
||||||
"""Test the getting of light state."""
|
"""Test the getting of light state."""
|
||||||
@ -1177,7 +1195,6 @@ async def test_unauthorized_user_blocked(hue_client):
|
|||||||
"""Test unauthorized_user blocked."""
|
"""Test unauthorized_user blocked."""
|
||||||
getUrls = [
|
getUrls = [
|
||||||
"/api/wronguser",
|
"/api/wronguser",
|
||||||
"/api/wronguser/config",
|
|
||||||
]
|
]
|
||||||
for getUrl in getUrls:
|
for getUrl in getUrls:
|
||||||
result = await hue_client.get(getUrl)
|
result = await hue_client.get(getUrl)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user