Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions homeassistant/components/frontend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from homeassistant.helpers import service
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.translation import async_get_translations
from homeassistant.loader import bind_hass
from homeassistant.loader import async_get_integration, bind_hass

from .storage import async_setup_frontend_storage

Expand Down Expand Up @@ -248,6 +248,7 @@ async def async_setup(hass, config):
hass.components.websocket_api.async_register_command(websocket_get_panels)
hass.components.websocket_api.async_register_command(websocket_get_themes)
hass.components.websocket_api.async_register_command(websocket_get_translations)
hass.components.websocket_api.async_register_command(websocket_get_version)
hass.http.register_view(ManifestJSONView)

conf = config.get(DOMAIN, {})
Expand Down Expand Up @@ -486,10 +487,7 @@ def get(self, request): # pylint: disable=no-self-use
@callback
@websocket_api.websocket_command({"type": "get_panels"})
def websocket_get_panels(hass, connection, msg):
"""Handle get panels command.

Async friendly.
"""
"""Handle get panels command."""
user_is_admin = connection.user.is_admin
panels = {
panel_key: panel.to_response()
Expand All @@ -503,10 +501,7 @@ def websocket_get_panels(hass, connection, msg):
@callback
@websocket_api.websocket_command({"type": "frontend/get_themes"})
def websocket_get_themes(hass, connection, msg):
"""Handle get themes command.

Async friendly.
"""
"""Handle get themes command."""
if hass.config.safe_mode:
connection.send_message(
websocket_api.result_message(
Expand Down Expand Up @@ -546,10 +541,7 @@ def websocket_get_themes(hass, connection, msg):
)
@websocket_api.async_response
async def websocket_get_translations(hass, connection, msg):
"""Handle get translations command.

Async friendly.
"""
"""Handle get translations command."""
resources = await async_get_translations(
hass,
msg["language"],
Expand All @@ -560,3 +552,21 @@ async def websocket_get_translations(hass, connection, msg):
connection.send_message(
websocket_api.result_message(msg["id"], {"resources": resources})
)


@websocket_api.websocket_command({"type": "frontend/get_version"})
@websocket_api.async_response
async def websocket_get_version(hass, connection, msg):
"""Handle get version command."""
integration = await async_get_integration(hass, "frontend")

frontend = None

for req in integration.requirements:
if req.startswith("home-assistant-frontend=="):
frontend = req.split("==", 1)[1]

if frontend is None:
connection.send_error(msg["id"], "unknown_version", "Version not found")
else:
connection.send_result(msg["id"], {"version": frontend})
22 changes: 22 additions & 0 deletions tests/components/frontend/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
)
from homeassistant.components.websocket_api.const import TYPE_RESULT
from homeassistant.const import HTTP_NOT_FOUND
from homeassistant.loader import async_get_integration
from homeassistant.setup import async_setup_component

from tests.common import async_capture_events
Expand Down Expand Up @@ -336,3 +337,24 @@ async def test_auth_authorize(mock_http_client):
resp = await mock_http_client.get(authorizejs.groups(0)[0])
assert resp.status == 200
assert "public" in resp.headers.get("cache-control")


async def test_get_version(hass, hass_ws_client):
"""Test get_version command."""
frontend = await async_get_integration(hass, "frontend")
cur_version = next(
req.split("==", 1)[1]
for req in frontend.requirements
if req.startswith("home-assistant-frontend==")
)

await async_setup_component(hass, "frontend", {})
client = await hass_ws_client(hass)

await client.send_json({"id": 5, "type": "frontend/get_version"})
msg = await client.receive_json()

assert msg["id"] == 5
assert msg["type"] == TYPE_RESULT
assert msg["success"]
assert msg["result"] == {"version": cur_version}