-
-
Notifications
You must be signed in to change notification settings - Fork 37.2k
Extract lovelace to it's own component #16816
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| """Lovelace UI.""" | ||
| import voluptuous as vol | ||
|
|
||
| from homeassistant.components import websocket_api | ||
| from homeassistant.util.yaml import load_yaml | ||
| from homeassistant.exceptions import HomeAssistantError | ||
|
|
||
| DOMAIN = 'lovelace' | ||
|
|
||
| OLD_WS_TYPE_GET_LOVELACE_UI = 'frontend/lovelace_config' | ||
| WS_TYPE_GET_LOVELACE_UI = 'lovelace/config' | ||
| SCHEMA_GET_LOVELACE_UI = websocket_api.BASE_COMMAND_MESSAGE_SCHEMA.extend({ | ||
| vol.Required('type'): vol.Any(WS_TYPE_GET_LOVELACE_UI, | ||
| OLD_WS_TYPE_GET_LOVELACE_UI), | ||
| }) | ||
|
|
||
|
|
||
| async def async_setup(hass, config): | ||
| """Set up the Lovelace commands.""" | ||
| # Backwards compat. Added in 0.80. Remove after 0.85 | ||
| hass.components.websocket_api.async_register_command( | ||
| OLD_WS_TYPE_GET_LOVELACE_UI, websocket_lovelace_config, | ||
| SCHEMA_GET_LOVELACE_UI) | ||
|
|
||
| hass.components.websocket_api.async_register_command( | ||
| WS_TYPE_GET_LOVELACE_UI, websocket_lovelace_config, | ||
| SCHEMA_GET_LOVELACE_UI) | ||
|
|
||
| return True | ||
|
|
||
|
|
||
| @websocket_api.async_response | ||
| async def websocket_lovelace_config(hass, connection, msg): | ||
| """Send lovelace UI config over websocket config.""" | ||
| error = None | ||
| try: | ||
| config = await hass.async_add_job( | ||
| load_yaml, hass.config.path('ui-lovelace.yaml')) | ||
| message = websocket_api.result_message( | ||
| msg['id'], config | ||
| ) | ||
| except FileNotFoundError: | ||
| error = ('file_not_found', | ||
| 'Could not find ui-lovelace.yaml in your config dir.') | ||
| except HomeAssistantError as err: | ||
| error = 'load_error', str(err) | ||
|
|
||
| if error is not None: | ||
| message = websocket_api.error_message(msg['id'], *error) | ||
|
|
||
| connection.send_message_outside(message) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| """Tests for Lovelace.""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| """Test the Lovelace initialization.""" | ||
| from unittest.mock import patch | ||
|
|
||
| from homeassistant.exceptions import HomeAssistantError | ||
| from homeassistant.setup import async_setup_component | ||
| from homeassistant.components import websocket_api as wapi | ||
|
|
||
|
|
||
| async def test_deprecated_lovelace_ui(hass, hass_ws_client): | ||
| """Test lovelace_ui command.""" | ||
| await async_setup_component(hass, 'lovelace') | ||
| client = await hass_ws_client(hass) | ||
|
|
||
| with patch('homeassistant.components.lovelace.load_yaml', | ||
| return_value={'hello': 'world'}): | ||
| await client.send_json({ | ||
| 'id': 5, | ||
| 'type': 'frontend/lovelace_config', | ||
| }) | ||
| msg = await client.receive_json() | ||
|
|
||
| assert msg['id'] == 5 | ||
| assert msg['type'] == wapi.TYPE_RESULT | ||
| assert msg['success'] | ||
| assert msg['result'] == {'hello': 'world'} | ||
|
|
||
|
|
||
| async def test_deprecated_lovelace_ui_not_found(hass, hass_ws_client): | ||
| """Test lovelace_ui command cannot find file.""" | ||
| await async_setup_component(hass, 'lovelace') | ||
| client = await hass_ws_client(hass) | ||
|
|
||
| with patch('homeassistant.components.lovelace.load_yaml', | ||
| side_effect=FileNotFoundError): | ||
| await client.send_json({ | ||
| 'id': 5, | ||
| 'type': 'frontend/lovelace_config', | ||
| }) | ||
| msg = await client.receive_json() | ||
|
|
||
| assert msg['id'] == 5 | ||
| assert msg['type'] == wapi.TYPE_RESULT | ||
| assert msg['success'] is False | ||
| assert msg['error']['code'] == 'file_not_found' | ||
|
|
||
|
|
||
| async def test_deprecated_lovelace_ui_load_err(hass, hass_ws_client): | ||
| """Test lovelace_ui command cannot find file.""" | ||
| await async_setup_component(hass, 'lovelace') | ||
| client = await hass_ws_client(hass) | ||
|
|
||
| with patch('homeassistant.components.lovelace.load_yaml', | ||
| side_effect=HomeAssistantError): | ||
| await client.send_json({ | ||
| 'id': 5, | ||
| 'type': 'frontend/lovelace_config', | ||
| }) | ||
| msg = await client.receive_json() | ||
|
|
||
| assert msg['id'] == 5 | ||
| assert msg['type'] == wapi.TYPE_RESULT | ||
| assert msg['success'] is False | ||
| assert msg['error']['code'] == 'load_error' | ||
|
|
||
|
|
||
| async def test_lovelace_ui(hass, hass_ws_client): | ||
| """Test lovelace_ui command.""" | ||
| await async_setup_component(hass, 'lovelace') | ||
| client = await hass_ws_client(hass) | ||
|
|
||
| with patch('homeassistant.components.lovelace.load_yaml', | ||
| return_value={'hello': 'world'}): | ||
| await client.send_json({ | ||
| 'id': 5, | ||
| 'type': 'lovelace/config', | ||
| }) | ||
| msg = await client.receive_json() | ||
|
|
||
| assert msg['id'] == 5 | ||
| assert msg['type'] == wapi.TYPE_RESULT | ||
| assert msg['success'] | ||
| assert msg['result'] == {'hello': 'world'} | ||
|
|
||
|
|
||
| async def test_lovelace_ui_not_found(hass, hass_ws_client): | ||
| """Test lovelace_ui command cannot find file.""" | ||
| await async_setup_component(hass, 'lovelace') | ||
| client = await hass_ws_client(hass) | ||
|
|
||
| with patch('homeassistant.components.lovelace.load_yaml', | ||
| side_effect=FileNotFoundError): | ||
| await client.send_json({ | ||
| 'id': 5, | ||
| 'type': 'lovelace/config', | ||
| }) | ||
| msg = await client.receive_json() | ||
|
|
||
| assert msg['id'] == 5 | ||
| assert msg['type'] == wapi.TYPE_RESULT | ||
| assert msg['success'] is False | ||
| assert msg['error']['code'] == 'file_not_found' | ||
|
|
||
|
|
||
| async def test_lovelace_ui_load_err(hass, hass_ws_client): | ||
| """Test lovelace_ui command cannot find file.""" | ||
| await async_setup_component(hass, 'lovelace') | ||
| client = await hass_ws_client(hass) | ||
|
|
||
| with patch('homeassistant.components.lovelace.load_yaml', | ||
| side_effect=HomeAssistantError): | ||
| await client.send_json({ | ||
| 'id': 5, | ||
| 'type': 'lovelace/config', | ||
| }) | ||
| msg = await client.receive_json() | ||
|
|
||
| assert msg['id'] == 5 | ||
| assert msg['type'] == wapi.TYPE_RESULT | ||
| assert msg['success'] is False | ||
| assert msg['error']['code'] == 'load_error' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
async_add_executor_job.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦♂️