-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(cli, api) add breakers * fix(cli) tests * fix(cli) tests * refactor(cli) update attributes * feat(cli) avoid sep/pillar/breaker in wrong obj * fix(cli) better doc and test * fix(cli) minor test improvement * fix(cli) add tests * fix(cli,api) update tests * fix(cli) check len value for update interact
1 parent
7d102a1
commit 822627d
Showing
24 changed files
with
1,067 additions
and
590 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package models | ||
|
||
import ( | ||
"cli/utils" | ||
"fmt" | ||
"strconv" | ||
) | ||
|
||
// Rack inner attributes | ||
type Breaker struct { | ||
Powerpanel string `json:"powerpanel"` | ||
Type string `json:"type,omitempty"` | ||
Circuit string `json:"circuit,omitempty"` | ||
Intensity float64 `json:"intensity,omitempty"` | ||
Tag string `json:"tag,omitempty"` | ||
} | ||
|
||
func ValuesToBreaker(values []any) (string, Breaker, error) { | ||
nMandatory := 2 | ||
// mandatory name | ||
mandatoryErr := fmt.Errorf("at least %d values (name and powerpanel) expected to add a breaker", nMandatory) | ||
if len(values) < nMandatory { | ||
return "", Breaker{}, mandatoryErr | ||
} | ||
name, err := utils.ValToString(values[0], "name") | ||
if err != nil { | ||
return name, Breaker{}, err | ||
} | ||
powerpanel, err := utils.ValToString(values[1], "powerpanel") | ||
if err != nil { | ||
return name, Breaker{}, err | ||
} | ||
if len(name) <= 0 || len(powerpanel) <= 0 { | ||
return name, Breaker{}, mandatoryErr | ||
} | ||
var breakerType string | ||
var circuit string | ||
var intensityStr string | ||
var tag string | ||
for index, receiver := range []*string{&breakerType, &circuit, &intensityStr, &tag} { | ||
err = setOptionalParam(index+nMandatory, values, receiver) | ||
if err != nil { | ||
return name, Breaker{}, err | ||
} | ||
} | ||
var intensity float64 | ||
if intensity, err = strconv.ParseFloat(intensityStr, | ||
64); intensityStr != "" && (err != nil || intensity <= 0) { | ||
return name, Breaker{}, fmt.Errorf("invalid value for intensity, it should be a positive number") | ||
} | ||
|
||
return name, Breaker{Powerpanel: powerpanel, Type: breakerType, | ||
Circuit: circuit, Intensity: intensity, Tag: tag}, nil | ||
} | ||
|
||
// Helpers | ||
func setOptionalParam(index int, values []any, receiver *string) error { | ||
if len(values) > index { | ||
value, err := utils.ValToString(values[index], fmt.Sprintf("optional %d", index)) | ||
if err != nil { | ||
return err | ||
} | ||
*receiver = value | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package models | ||
|
||
import ( | ||
"cli/utils" | ||
"fmt" | ||
) | ||
|
||
// Room inner attributes | ||
type Pillar struct { | ||
CenterXY []float64 `json:"centerXY"` | ||
SizeXY []float64 `json:"sizeXY"` | ||
Rotation float64 `json:"rotation"` | ||
} | ||
|
||
func ValuesToPillar(values []any) (string, Pillar, error) { | ||
if len(values) != 4 { | ||
return "", Pillar{}, fmt.Errorf("4 values (name, centerXY, sizeXY, rotation) expected to add a pillar") | ||
} | ||
name, err := utils.ValToString(values[0], "name") | ||
if err != nil { | ||
return name, Pillar{}, err | ||
} | ||
centerXY, err := utils.ValToVec(values[1], 2, "centerXY") | ||
if err != nil { | ||
return name, Pillar{}, err | ||
} | ||
sizeXY, err := utils.ValToVec(values[2], 2, "sizeXY") | ||
if err != nil { | ||
return name, Pillar{}, err | ||
} | ||
rotation, err := utils.ValToFloat(values[3], "rotation") | ||
if err != nil { | ||
return name, Pillar{}, err | ||
} | ||
return name, Pillar{centerXY, sizeXY, rotation}, nil | ||
} | ||
|
||
type Separator struct { | ||
StartPos []float64 `json:"startPosXYm"` | ||
EndPos []float64 `json:"endPosXYm"` | ||
Type string `json:"type"` | ||
} | ||
|
||
func ValuesToSeparator(values []any) (string, Separator, error) { | ||
if len(values) != 4 { | ||
return "", Separator{}, fmt.Errorf("4 values (name, startPos, endPos, type) expected to add a separator") | ||
} | ||
name, err := utils.ValToString(values[0], "name") | ||
if err != nil { | ||
return name, Separator{}, err | ||
} | ||
startPos, err := utils.ValToVec(values[1], 2, "startPos") | ||
if err != nil { | ||
return name, Separator{}, err | ||
} | ||
endPos, err := utils.ValToVec(values[2], 2, "endPos") | ||
if err != nil { | ||
return name, Separator{}, err | ||
} | ||
sepType, err := utils.ValToString(values[3], "separator type") | ||
if err != nil { | ||
return name, Separator{}, err | ||
} | ||
return name, Separator{startPos, endPos, sepType}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters