@@ -133,6 +133,8 @@ class Component:
133
133
template : Component, default: None
134
134
Template to create this component from. This creates an
135
135
instance component that shares a master with the template component.
136
+ instance_name: str, default: None
137
+ User defined optional name for the component instance.
136
138
preexisting_id : str, default: None
137
139
ID of a component pre-existing on the server side to use to create the component
138
140
on the client-side data model. If an ID is specified, a new component is not
@@ -160,6 +162,7 @@ def __init__(
160
162
parent_component : Union ["Component" , None ],
161
163
grpc_client : GrpcClient ,
162
164
template : Optional ["Component" ] = None ,
165
+ instance_name : Optional [str ] = None ,
163
166
preexisting_id : str | None = None ,
164
167
master_component : MasterComponent | None = None ,
165
168
read_existing_comp : bool = False ,
@@ -171,21 +174,33 @@ def __init__(
171
174
self ._bodies_stub = BodiesStub (self ._grpc_client .channel )
172
175
self ._commands_stub = CommandsStub (self ._grpc_client .channel )
173
176
177
+ # Align instance name behavior with the server - empty string if None
178
+ instance_name = instance_name if instance_name else ""
179
+
174
180
if preexisting_id :
175
181
self ._name = name
176
182
self ._id = preexisting_id
183
+ self ._instance_name = instance_name
177
184
else :
178
185
if parent_component :
179
186
template_id = template .id if template else ""
180
187
new_component = self ._component_stub .Create (
181
- CreateRequest (name = name , parent = parent_component .id , template = template_id )
188
+ CreateRequest (
189
+ name = name ,
190
+ parent = parent_component .id ,
191
+ template = template_id ,
192
+ instance_name = instance_name ,
193
+ )
182
194
)
195
+
183
196
# Remove this method call once we know Service sends correct ObjectPath id
184
197
self ._id = new_component .component .id
185
198
self ._name = new_component .component .name
199
+ self ._instance_name = new_component .component .instance_name
186
200
else :
187
201
self ._name = name
188
202
self ._id = None
203
+ self ._instance_name = instance_name
189
204
190
205
# Initialize needed instance variables
191
206
self ._components = []
@@ -231,6 +246,11 @@ def name(self) -> str:
231
246
"""Name of the component."""
232
247
return self ._name
233
248
249
+ @property
250
+ def instance_name (self ) -> str :
251
+ """Name of the component instance."""
252
+ return self ._instance_name
253
+
234
254
@property
235
255
def components (self ) -> list ["Component" ]:
236
256
"""List of ``Component`` objects inside of the component."""
@@ -367,7 +387,9 @@ def reset_placement(self):
367
387
368
388
@check_input_types
369
389
@ensure_design_is_active
370
- def add_component (self , name : str , template : Optional ["Component" ] = None ) -> "Component" :
390
+ def add_component (
391
+ self , name : str , template : Optional ["Component" ] = None , instance_name : str = None
392
+ ) -> "Component" :
371
393
"""Add a new component under this component within the design assembly.
372
394
373
395
Parameters
@@ -383,18 +405,20 @@ def add_component(self, name: str, template: Optional["Component"] = None) -> "C
383
405
Component
384
406
New component with no children in the design assembly.
385
407
"""
386
- new_comp = Component (name , self , self ._grpc_client , template = template )
408
+ new_comp = Component (
409
+ name , self , self ._grpc_client , template = template , instance_name = instance_name
410
+ )
387
411
master = new_comp ._master_component
388
412
master_id = new_comp .id .split ("/" )[- 1 ]
389
-
390
413
for comp in self ._master_component .occurrences :
391
414
if comp .id != self .id :
392
415
comp .components .append (
393
416
Component (
394
417
name ,
395
418
comp ,
396
419
self ._grpc_client ,
397
- template ,
420
+ template = template ,
421
+ instance_name = instance_name ,
398
422
preexisting_id = f"{ comp .id } /{ master_id } " ,
399
423
master_component = master ,
400
424
read_existing_comp = True ,
0 commit comments