1919from homeassistant .helpers import service
2020import homeassistant .helpers .config_validation as cv
2121from homeassistant .helpers .translation import async_get_translations
22- from homeassistant .loader import bind_hass
22+ from homeassistant .loader import async_get_integration , bind_hass
2323
2424from .storage import async_setup_frontend_storage
2525
@@ -248,6 +248,7 @@ async def async_setup(hass, config):
248248 hass .components .websocket_api .async_register_command (websocket_get_panels )
249249 hass .components .websocket_api .async_register_command (websocket_get_themes )
250250 hass .components .websocket_api .async_register_command (websocket_get_translations )
251+ hass .components .websocket_api .async_register_command (websocket_get_version )
251252 hass .http .register_view (ManifestJSONView )
252253
253254 conf = config .get (DOMAIN , {})
@@ -486,10 +487,7 @@ def get(self, request): # pylint: disable=no-self-use
486487@callback
487488@websocket_api .websocket_command ({"type" : "get_panels" })
488489def websocket_get_panels (hass , connection , msg ):
489- """Handle get panels command.
490-
491- Async friendly.
492- """
490+ """Handle get panels command."""
493491 user_is_admin = connection .user .is_admin
494492 panels = {
495493 panel_key : panel .to_response ()
@@ -503,10 +501,7 @@ def websocket_get_panels(hass, connection, msg):
503501@callback
504502@websocket_api .websocket_command ({"type" : "frontend/get_themes" })
505503def websocket_get_themes (hass , connection , msg ):
506- """Handle get themes command.
507-
508- Async friendly.
509- """
504+ """Handle get themes command."""
510505 if hass .config .safe_mode :
511506 connection .send_message (
512507 websocket_api .result_message (
@@ -546,10 +541,7 @@ def websocket_get_themes(hass, connection, msg):
546541)
547542@websocket_api .async_response
548543async def websocket_get_translations (hass , connection , msg ):
549- """Handle get translations command.
550-
551- Async friendly.
552- """
544+ """Handle get translations command."""
553545 resources = await async_get_translations (
554546 hass ,
555547 msg ["language" ],
@@ -560,3 +552,21 @@ async def websocket_get_translations(hass, connection, msg):
560552 connection .send_message (
561553 websocket_api .result_message (msg ["id" ], {"resources" : resources })
562554 )
555+
556+
557+ @websocket_api .websocket_command ({"type" : "frontend/get_version" })
558+ @websocket_api .async_response
559+ async def websocket_get_version (hass , connection , msg ):
560+ """Handle get version command."""
561+ integration = await async_get_integration (hass , "frontend" )
562+
563+ frontend = None
564+
565+ for req in integration .requirements :
566+ if req .startswith ("home-assistant-frontend==" ):
567+ frontend = req .split ("==" , 1 )[1 ]
568+
569+ if frontend is None :
570+ connection .send_error (msg ["id" ], "unknown_version" , "Version not found" )
571+ else :
572+ connection .send_result (msg ["id" ], {"version" : frontend })
0 commit comments