@@ -18,7 +18,6 @@ package bricks
1818import (
1919 "errors"
2020 "fmt"
21- "maps"
2221 "slices"
2322
2423 "github.com/arduino/go-paths-helper"
@@ -91,30 +90,43 @@ func (s *Service) AppBrickInstancesList(a *app.ArduinoApp) (AppBrickInstancesRes
9190 return res , nil
9291}
9392
94- func (s * Service ) AppBrickInstanceDetails (a * app.ArduinoApp , brickID string ) (BrickInstance , error ) {
93+ func (s * Service ) AppBrickInstanceDetails (a * app.ArduinoApp , brickID string ) (BrickInstanceDetails , error ) {
9594 brick , found := s .bricksIndex .FindBrickByID (brickID )
9695 if ! found {
97- return BrickInstance {}, ErrBrickNotFound
96+ return BrickInstanceDetails {}, ErrBrickNotFound
9897 }
9998 // Check if the brick is already added in the app
10099 brickIndex := slices .IndexFunc (a .Descriptor .Bricks , func (b app.Brick ) bool { return b .ID == brickID })
101100 if brickIndex == - 1 {
102- return BrickInstance {}, fmt .Errorf ("brick %s not added in the app" , brickID )
101+ return BrickInstanceDetails {}, fmt .Errorf ("brick %s not added in the app" , brickID )
103102 }
104103
105- variables := make (map [string ]string , len (brick .Variables ))
104+ variables := make (map [string ]BrickVariable , len (brick .Variables ))
106105 for _ , v := range brick .Variables {
107- variables [v .Name ] = v .DefaultValue
106+ variables [v .Name ] = BrickVariable {
107+ DefaultValue : v .DefaultValue ,
108+ Description : v .Description ,
109+ Required : v .IsRequired (),
110+ }
108111 }
109112 // Add/Update the variables with the ones from the app descriptor
110- maps .Copy (variables , a .Descriptor .Bricks [brickIndex ].Variables )
111-
113+ appVars := a .Descriptor .Bricks [brickIndex ].Variables
114+ for varName , appValue := range appVars {
115+ if v , ok := variables [varName ]; ok {
116+ v .DefaultValue = appValue
117+ variables [varName ] = v
118+ } else {
119+ variables [varName ] = BrickVariable {
120+ DefaultValue : appValue ,
121+ }
122+ }
123+ }
112124 modelID := a .Descriptor .Bricks [brickIndex ].Model
113125 if modelID == "" {
114126 modelID = brick .ModelName
115127 }
116128
117- return BrickInstance {
129+ return BrickInstanceDetails {
118130 ID : brickID ,
119131 Name : brick .Name ,
120132 Author : "Arduino" , // TODO: for now we only support our bricks
0 commit comments