-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
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
Make WS command backup/generate send events #130524
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 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 |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
from homeassistant.core import HomeAssistant, callback | ||
|
||
from .const import DATA_MANAGER, LOGGER | ||
from .manager import BackupProgress | ||
|
||
|
||
@callback | ||
|
@@ -40,7 +41,7 @@ async def handle_info( | |
msg["id"], | ||
{ | ||
"backups": list(backups.values()), | ||
"backing_up": manager.backing_up, | ||
"backing_up": manager.backup_task is not None, | ||
}, | ||
) | ||
|
||
|
@@ -113,7 +114,11 @@ async def handle_create( | |
msg: dict[str, Any], | ||
) -> None: | ||
"""Generate a backup.""" | ||
backup = await hass.data[DATA_MANAGER].async_create_backup() | ||
|
||
def on_progress(progress: BackupProgress) -> None: | ||
connection.send_message(websocket_api.event_message(msg["id"], progress)) | ||
|
||
backup = await hass.data[DATA_MANAGER].async_create_backup(on_progress=on_progress) | ||
connection.send_result(msg["id"], backup) | ||
|
||
|
||
|
@@ -127,7 +132,6 @@ async def handle_backup_start( | |
) -> None: | ||
"""Backup start notification.""" | ||
manager = hass.data[DATA_MANAGER] | ||
manager.backing_up = True | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This did not seem to be needed. |
||
LOGGER.debug("Backup start notification") | ||
|
||
try: | ||
|
@@ -149,7 +153,6 @@ async def handle_backup_end( | |
) -> None: | ||
"""Backup end notification.""" | ||
manager = hass.data[DATA_MANAGER] | ||
manager.backing_up = False | ||
LOGGER.debug("Backup end notification") | ||
|
||
try: | ||
|
This file contains 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,73 @@ | ||
"""Test fixtures for the Backup integration.""" | ||
|
||
from __future__ import annotations | ||
|
||
from collections.abc import Generator | ||
from pathlib import Path | ||
from unittest.mock import MagicMock, Mock, patch | ||
|
||
import pytest | ||
|
||
from homeassistant.core import HomeAssistant | ||
|
||
|
||
@pytest.fixture(name="mocked_json_bytes") | ||
def mocked_json_bytes_fixture() -> Generator[Mock]: | ||
"""Mock json_bytes.""" | ||
with patch( | ||
"homeassistant.components.backup.manager.json_bytes", | ||
return_value=b"{}", # Empty JSON | ||
) as mocked_json_bytes: | ||
yield mocked_json_bytes | ||
|
||
|
||
@pytest.fixture(name="mocked_tarfile") | ||
def mocked_tarfile_fixture() -> Generator[Mock]: | ||
"""Mock tarfile.""" | ||
with patch( | ||
"homeassistant.components.backup.manager.SecureTarFile" | ||
) as mocked_tarfile: | ||
yield mocked_tarfile | ||
|
||
|
||
@pytest.fixture(name="mock_backup_generation") | ||
def mock_backup_generation_fixture( | ||
hass: HomeAssistant, mocked_json_bytes: Mock, mocked_tarfile: Mock | ||
) -> Generator[None]: | ||
"""Mock backup generator.""" | ||
|
||
def _mock_iterdir(path: Path) -> list[Path]: | ||
if not path.name.endswith("testing_config"): | ||
return [] | ||
return [ | ||
Path("test.txt"), | ||
Path(".DS_Store"), | ||
Path(".storage"), | ||
] | ||
|
||
with ( | ||
patch("pathlib.Path.iterdir", _mock_iterdir), | ||
patch("pathlib.Path.stat", MagicMock(st_size=123)), | ||
patch("pathlib.Path.is_file", lambda x: x.name != ".storage"), | ||
patch( | ||
"pathlib.Path.is_dir", | ||
lambda x: x.name == ".storage", | ||
), | ||
patch( | ||
"pathlib.Path.exists", | ||
lambda x: x != Path(hass.config.path("backups")), | ||
), | ||
patch( | ||
"pathlib.Path.is_symlink", | ||
lambda _: False, | ||
), | ||
patch( | ||
"pathlib.Path.mkdir", | ||
MagicMock(), | ||
), | ||
patch( | ||
"homeassistant.components.backup.manager.HAVERSION", | ||
"2025.1.0", | ||
), | ||
): | ||
yield |
This file contains 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
Oops, something went wrong.
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.
This is inspired by backup job progress fired by supervisor: