From b23eacc7addd45c56cfc7d6a2bb6dc8b4327f19c Mon Sep 17 00:00:00 2001 From: Erik Date: Mon, 11 Nov 2024 13:23:52 +0100 Subject: [PATCH] Add cloud preference for backup sync --- homeassistant/components/cloud/const.py | 1 + homeassistant/components/cloud/http_api.py | 2 ++ homeassistant/components/cloud/prefs.py | 11 +++++++++++ tests/components/cloud/test_http_api.py | 4 ++++ 4 files changed, 18 insertions(+) diff --git a/homeassistant/components/cloud/const.py b/homeassistant/components/cloud/const.py index 4392bf94827..d94d3c93388 100644 --- a/homeassistant/components/cloud/const.py +++ b/homeassistant/components/cloud/const.py @@ -31,6 +31,7 @@ PREF_GOOGLE_REPORT_STATE = "google_report_state" PREF_ALEXA_ENTITY_CONFIGS = "alexa_entity_configs" PREF_ALEXA_REPORT_STATE = "alexa_report_state" PREF_DISABLE_2FA = "disable_2fa" +PREF_ENABLE_BACKUP_SYNC = "backup_sync_enabled" PREF_INSTANCE_ID = "instance_id" PREF_SHOULD_EXPOSE = "should_expose" PREF_GOOGLE_LOCAL_WEBHOOK_ID = "google_local_webhook_id" diff --git a/homeassistant/components/cloud/http_api.py b/homeassistant/components/cloud/http_api.py index 4f2ad0ddcf7..4b305c86a9c 100644 --- a/homeassistant/components/cloud/http_api.py +++ b/homeassistant/components/cloud/http_api.py @@ -42,6 +42,7 @@ from .const import ( PREF_ALEXA_REPORT_STATE, PREF_DISABLE_2FA, PREF_ENABLE_ALEXA, + PREF_ENABLE_BACKUP_SYNC, PREF_ENABLE_CLOUD_ICE_SERVERS, PREF_ENABLE_GOOGLE, PREF_GOOGLE_REPORT_STATE, @@ -442,6 +443,7 @@ def validate_language_voice(value: tuple[str, str]) -> tuple[str, str]: vol.Required("type"): "cloud/update_prefs", vol.Optional(PREF_ALEXA_REPORT_STATE): bool, vol.Optional(PREF_ENABLE_ALEXA): bool, + vol.Optional(PREF_ENABLE_BACKUP_SYNC): bool, vol.Optional(PREF_ENABLE_CLOUD_ICE_SERVERS): bool, vol.Optional(PREF_ENABLE_GOOGLE): bool, vol.Optional(PREF_GOOGLE_REPORT_STATE): bool, diff --git a/homeassistant/components/cloud/prefs.py b/homeassistant/components/cloud/prefs.py index ae4b2794e1b..07d75cb2432 100644 --- a/homeassistant/components/cloud/prefs.py +++ b/homeassistant/components/cloud/prefs.py @@ -32,6 +32,7 @@ from .const import ( PREF_CLOUD_USER, PREF_CLOUDHOOKS, PREF_ENABLE_ALEXA, + PREF_ENABLE_BACKUP_SYNC, PREF_ENABLE_CLOUD_ICE_SERVERS, PREF_ENABLE_GOOGLE, PREF_ENABLE_REMOTE, @@ -166,6 +167,7 @@ class CloudPreferences: alexa_enabled: bool | UndefinedType = UNDEFINED, alexa_report_state: bool | UndefinedType = UNDEFINED, alexa_settings_version: int | UndefinedType = UNDEFINED, + backup_sync_enabled: bool | UndefinedType = UNDEFINED, cloud_ice_servers_enabled: bool | UndefinedType = UNDEFINED, cloud_user: str | UndefinedType = UNDEFINED, cloudhooks: dict[str, dict[str, str | bool]] | UndefinedType = UNDEFINED, @@ -191,6 +193,7 @@ class CloudPreferences: (PREF_CLOUD_USER, cloud_user), (PREF_CLOUDHOOKS, cloudhooks), (PREF_ENABLE_ALEXA, alexa_enabled), + (PREF_ENABLE_BACKUP_SYNC, backup_sync_enabled), (PREF_ENABLE_CLOUD_ICE_SERVERS, cloud_ice_servers_enabled), (PREF_ENABLE_GOOGLE, google_enabled), (PREF_ENABLE_REMOTE, remote_enabled), @@ -242,6 +245,7 @@ class CloudPreferences: PREF_ALEXA_REPORT_STATE: self.alexa_report_state, PREF_CLOUDHOOKS: self.cloudhooks, PREF_ENABLE_ALEXA: self.alexa_enabled, + PREF_ENABLE_BACKUP_SYNC: self.backup_sync_enabled, PREF_ENABLE_CLOUD_ICE_SERVERS: self.cloud_ice_servers_enabled, PREF_ENABLE_GOOGLE: self.google_enabled, PREF_ENABLE_REMOTE: self.remote_enabled, @@ -374,6 +378,12 @@ class CloudPreferences: ) return cloud_ice_servers_enabled + @property + def backup_sync_enabled(self) -> bool: + """Return if backup sync is enabled.""" + backup_sync_enabled: bool = self._prefs.get(PREF_ENABLE_BACKUP_SYNC, False) + return backup_sync_enabled + async def get_cloud_user(self) -> str: """Return ID of Home Assistant Cloud system user.""" user = await self._load_cloud_user() @@ -419,6 +429,7 @@ class CloudPreferences: PREF_CLOUD_USER: None, PREF_CLOUDHOOKS: {}, PREF_ENABLE_ALEXA: True, + PREF_ENABLE_BACKUP_SYNC: True, PREF_ENABLE_GOOGLE: True, PREF_ENABLE_REMOTE: False, PREF_ENABLE_CLOUD_ICE_SERVERS: True, diff --git a/tests/components/cloud/test_http_api.py b/tests/components/cloud/test_http_api.py index 216fc77db48..7d37391c19c 100644 --- a/tests/components/cloud/test_http_api.py +++ b/tests/components/cloud/test_http_api.py @@ -786,6 +786,7 @@ async def test_websocket_status( "remote_enabled": False, "cloud_ice_servers_enabled": True, "tts_default_voice": ["en-US", "JennyNeural"], + "backup_sync_enabled": True, }, "alexa_entities": { "include_domains": [], @@ -905,6 +906,7 @@ async def test_websocket_update_preferences( assert cloud.client.prefs.google_secure_devices_pin is None assert cloud.client.prefs.remote_allow_remote_enable is True assert cloud.client.prefs.cloud_ice_servers_enabled is True + assert cloud.client.prefs.backup_sync_enabled is True client = await hass_ws_client(hass) @@ -917,6 +919,7 @@ async def test_websocket_update_preferences( "tts_default_voice": ["en-GB", "RyanNeural"], "remote_allow_remote_enable": False, "cloud_ice_servers_enabled": False, + "backup_sync_enabled": False, } ) response = await client.receive_json() @@ -927,6 +930,7 @@ async def test_websocket_update_preferences( assert cloud.client.prefs.google_secure_devices_pin == "1234" assert cloud.client.prefs.remote_allow_remote_enable is False assert cloud.client.prefs.cloud_ice_servers_enabled is False + assert cloud.client.prefs.backup_sync_enabled is False assert cloud.client.prefs.tts_default_voice == ("en-GB", "RyanNeural")