Skip to content

Commit 6fc6b46

Browse files
committed
fix bug
1 parent 25879bd commit 6fc6b46

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

internal/e2e/daemon/const.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ var (
3737
Description: f.Ptr("path to the custom model directory"),
3838
Name: f.Ptr("CUSTOM_MODEL_PATH"),
3939
Required: f.Ptr(false),
40-
Value: f.Ptr(""),
40+
Value: f.Ptr("/home/arduino/.arduino-bricks/ei-models"),
4141
},
4242
{
4343
Description: f.Ptr("path to the model file"),
4444
Name: f.Ptr("EI_CLASSIFICATION_MODEL"),
4545
Required: f.Ptr(false),
46-
Value: f.Ptr(""),
46+
Value: f.Ptr("/models/ootb/ei/mobilenet-v2-224px.eim"),
4747
},
4848
}
4949
)

internal/orchestrator/bricks/bricks.go

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"errors"
2020
"fmt"
2121
"log/slog"
22-
"maps"
2322
"slices"
2423

2524
"github.com/arduino/go-paths-helper"
@@ -81,16 +80,16 @@ func (s *Service) AppBrickInstancesList(a *app.ArduinoApp) (AppBrickInstancesRes
8180
return AppBrickInstancesResult{}, fmt.Errorf("brick not found with id %s", brickInstance.ID)
8281
}
8382

84-
instanceVariables := getBrickInstanceVariableDetails(brick, brickInstance.Variables)
83+
variablesMap, instanceVariables := getBrickVariableDetails(brick, brickInstance.Variables)
8584

8685
res.BrickInstances[i] = BrickInstance{
8786
ID: brick.ID,
8887
Name: brick.Name,
8988
Author: "Arduino", // TODO: for now we only support our bricks
9089
Category: brick.Category,
9190
Status: "installed",
92-
ModelID: brickInstance.Model, // TODO: in case is not set by the user, should we return the default model?
93-
Variables: brickInstance.Variables, // TODO: do we want to show also the default value of not explicitly set variables?
91+
ModelID: brickInstance.Model, // TODO: in case is not set by the user, should we return the default model?
92+
Variables: variablesMap, // TODO: do we want to show also the default value of not explicitly set variables?
9493
VariablesDetails: instanceVariables,
9594
}
9695

@@ -109,14 +108,7 @@ func (s *Service) AppBrickInstanceDetails(a *app.ArduinoApp, brickID string) (Br
109108
return BrickInstance{}, fmt.Errorf("brick %s not added in the app", brickID)
110109
}
111110

112-
variables := make(map[string]string, len(brick.Variables))
113-
for _, v := range brick.Variables {
114-
variables[v.Name] = v.DefaultValue
115-
}
116-
// Add/Update the variables with the ones from the app descriptor
117-
maps.Copy(variables, a.Descriptor.Bricks[brickIndex].Variables)
118-
119-
instanceVariables := getBrickInstanceVariableDetails(brick, a.Descriptor.Bricks[brickIndex].Variables)
111+
variables, instanceVariables := getBrickVariableDetails(brick, a.Descriptor.Bricks[brickIndex].Variables)
120112

121113
modelID := a.Descriptor.Bricks[brickIndex].Model
122114
if modelID == "" {
@@ -135,21 +127,30 @@ func (s *Service) AppBrickInstanceDetails(a *app.ArduinoApp, brickID string) (Br
135127
}, nil
136128
}
137129

138-
func getBrickInstanceVariableDetails(
139-
brick *bricksindex.Brick,
140-
brickInstanceVariables map[string]string,
141-
) []BrickInstanceVariable {
130+
func getBrickVariableDetails(
131+
brick *bricksindex.Brick, userVariables map[string]string,
132+
) (map[string]string, []BrickInstanceVariable) {
133+
variablesMap := make(map[string]string, len(brick.Variables))
142134
variableDetails := make([]BrickInstanceVariable, 0, len(brick.Variables))
135+
143136
for _, v := range brick.Variables {
144-
value := brickInstanceVariables[v.Name]
137+
finalValue := v.DefaultValue
138+
139+
userValue, ok := userVariables[v.Name]
140+
if ok {
141+
finalValue = userValue
142+
}
143+
variablesMap[v.Name] = finalValue
144+
145145
variableDetails = append(variableDetails, BrickInstanceVariable{
146146
Name: v.Name,
147-
Value: value,
147+
Value: finalValue,
148148
Description: v.Description,
149149
Required: v.IsRequired(),
150150
})
151151
}
152-
return variableDetails
152+
153+
return variablesMap, variableDetails
153154
}
154155

155156
func (s *Service) BricksDetails(id string, idProvider *app.IDProvider,

0 commit comments

Comments
 (0)