Skip to content

Commit

Permalink
Add backup config update method
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinHjelmare committed Nov 18, 2024
1 parent 0bcbeda commit 0abb521
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 11 additions & 1 deletion homeassistant/components/backup/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from homeassistant.core import HomeAssistant
from homeassistant.helpers.storage import Store
from homeassistant.helpers.typing import UNDEFINED, UndefinedType

from .const import DOMAIN

Expand Down Expand Up @@ -51,7 +52,6 @@ class BackupConfig:
def __init__(self, hass: HomeAssistant) -> None:
"""Initialize backup config."""
self.data = BackupConfigData()
self._hass = hass
self._store: Store[StoredBackupConfig] = Store(
hass, STORAGE_VERSION, STORAGE_KEY
)
Expand All @@ -65,3 +65,13 @@ async def load(self) -> None:
async def save(self) -> None:
"""Save config."""
await self._store.async_save(self.data.to_dict())

async def update(
self, *, max_copies: int | None | UndefinedType = UNDEFINED
) -> None:
"""Update config."""
for param_name, param_value in {"max_copies": max_copies}.items():
if param_value is not UNDEFINED:
setattr(self.data, param_name, param_value)

await self.save()
6 changes: 4 additions & 2 deletions homeassistant/components/backup/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ async def handle_config_update(
) -> None:
"""Update the stored backup config."""
manager = hass.data[DATA_MANAGER]
manager.config.data.max_copies = msg.get("max_copies")
await manager.config.save()
changes = dict(msg)
changes.pop("id")
changes.pop("type")
await manager.config.update(**changes)
connection.send_result(msg["id"])

0 comments on commit 0abb521

Please sign in to comment.