mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
parent
c63bdd5afe
commit
fa4aa2244e
@ -8,8 +8,7 @@ import os
|
|||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
|
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.const import HTTP_NOT_FOUND
|
from homeassistant.components import api
|
||||||
from homeassistant.components import api, group
|
|
||||||
from homeassistant.components.http import HomeAssistantView
|
from homeassistant.components.http import HomeAssistantView
|
||||||
from homeassistant.components.http.auth import is_trusted_ip
|
from homeassistant.components.http.auth import is_trusted_ip
|
||||||
from homeassistant.components.http.const import KEY_DEVELOPMENT
|
from homeassistant.components.http.const import KEY_DEVELOPMENT
|
||||||
@ -138,6 +137,8 @@ def register_panel(hass, component_name, path, md5=None, sidebar_title=None,
|
|||||||
if index_view:
|
if index_view:
|
||||||
hass.http.app.router.add_route(
|
hass.http.app.router.add_route(
|
||||||
'get', '/{}'.format(url_path), index_view.get)
|
'get', '/{}'.format(url_path), index_view.get)
|
||||||
|
hass.http.app.router.add_route(
|
||||||
|
'get', '/{}/{{extra:.+}}'.format(url_path), index_view.get)
|
||||||
|
|
||||||
|
|
||||||
def add_manifest_json_key(key, val):
|
def add_manifest_json_key(key, val):
|
||||||
@ -172,8 +173,10 @@ def setup(hass, config):
|
|||||||
# Now register their urls.
|
# Now register their urls.
|
||||||
if DATA_PANELS in hass.data:
|
if DATA_PANELS in hass.data:
|
||||||
for url_path in hass.data[DATA_PANELS]:
|
for url_path in hass.data[DATA_PANELS]:
|
||||||
hass.http.app.router.add_route('get', '/{}'.format(url_path),
|
hass.http.app.router.add_route(
|
||||||
index_view.get)
|
'get', '/{}'.format(url_path), index_view.get)
|
||||||
|
hass.http.app.router.add_route(
|
||||||
|
'get', '/{}/{{extra:.+}}'.format(url_path), index_view.get)
|
||||||
else:
|
else:
|
||||||
hass.data[DATA_PANELS] = {}
|
hass.data[DATA_PANELS] = {}
|
||||||
|
|
||||||
@ -212,7 +215,7 @@ class IndexView(HomeAssistantView):
|
|||||||
url = '/'
|
url = '/'
|
||||||
name = 'frontend:index'
|
name = 'frontend:index'
|
||||||
requires_auth = False
|
requires_auth = False
|
||||||
extra_urls = ['/states', '/states/{entity_id}']
|
extra_urls = ['/states', '/states/{extra}']
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""Initialize the frontend view."""
|
"""Initialize the frontend view."""
|
||||||
@ -225,17 +228,10 @@ class IndexView(HomeAssistantView):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def get(self, request, entity_id=None):
|
def get(self, request, extra=None):
|
||||||
"""Serve the index view."""
|
"""Serve the index view."""
|
||||||
hass = request.app['hass']
|
hass = request.app['hass']
|
||||||
|
|
||||||
if entity_id is not None:
|
|
||||||
state = hass.states.get(entity_id)
|
|
||||||
|
|
||||||
if (not state or state.domain != 'group' or
|
|
||||||
not state.attributes.get(group.ATTR_VIEW)):
|
|
||||||
return self.json_message('Entity not found', HTTP_NOT_FOUND)
|
|
||||||
|
|
||||||
if request.app[KEY_DEVELOPMENT]:
|
if request.app[KEY_DEVELOPMENT]:
|
||||||
core_url = '/static/home-assistant-polymer/build/core.js'
|
core_url = '/static/home-assistant-polymer/build/core.js'
|
||||||
compatibility_url = \
|
compatibility_url = \
|
||||||
|
@ -61,9 +61,5 @@ def test_states_routes(hass, mock_http_client):
|
|||||||
resp = yield from mock_http_client.get('/states')
|
resp = yield from mock_http_client.get('/states')
|
||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
|
|
||||||
resp = yield from mock_http_client.get('/states/group.non_existing')
|
|
||||||
assert resp.status == 404
|
|
||||||
|
|
||||||
hass.states.async_set('group.existing', 'on', {'view': True})
|
|
||||||
resp = yield from mock_http_client.get('/states/group.existing')
|
resp = yield from mock_http_client.get('/states/group.existing')
|
||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
|
Loading…
x
Reference in New Issue
Block a user