Add validation and limits to current input
This commit is contained in:
parent
7f4a1e8f7b
commit
754e8a5a7d
4 changed files with 24 additions and 10 deletions
|
|
@ -115,6 +115,8 @@ ValueError_Used = "Dieser Wert wird bereits verwendet."
|
|||
ValueError_Empty = "Der Wert darf nicht leer sein."
|
||||
ValueError_Float = "Der Wert muss eine Zahl sein. Nachkommastellen mit . anstatt mit , trennen."
|
||||
ValueError_Number = "Der Wert muss eine ganzzahlige Zahl sein."
|
||||
ValueError_NumberLowerThanMin = "Der Wert muss größer oder gleich {{ .Min }} sein."
|
||||
ValueError_NumberBiggerThanMax = "Der Wert muss kleiner oder gleich {{ .Max }} sein."
|
||||
|
||||
Device_Configure = "Konfiguration"
|
||||
Device_Added = "wurde erfolgreich hinzugefügt."
|
||||
|
|
|
|||
|
|
@ -115,6 +115,8 @@ ValueError_Used = "This value is aready in use."
|
|||
ValueError_Empty = "The value may not be empty."
|
||||
ValueError_Float = "The value has to be a number."
|
||||
ValueError_Number = "The value has to be an integer."
|
||||
ValueError_NumberLowerThanMin = "The value must be bigger or equal to {{ .Min }}."
|
||||
ValueError_NumberBiggerThanMax = "The value must be smaller or equal to {{ .Max }}."
|
||||
|
||||
Device_Configure = "Configuration"
|
||||
Device_Added = "was successfully added."
|
||||
|
|
|
|||
|
|
@ -275,6 +275,7 @@ func (c *CmdConfigure) configureLoadpoints() {
|
|||
}
|
||||
fmt.Println()
|
||||
powerIndex, _ := c.askChoice(c.localizedString("Loadpoint_WallboxMaxPower", nil), powerChoices)
|
||||
loadpoint.MinCurrent = 6
|
||||
switch powerIndex {
|
||||
case 0:
|
||||
loadpoint.MaxCurrent = 16
|
||||
|
|
@ -293,9 +294,11 @@ func (c *CmdConfigure) configureLoadpoints() {
|
|||
}
|
||||
case 3:
|
||||
amperage := c.askValue(question{
|
||||
label: c.localizedString("Loadpoint_WallboxMaxAmperage", nil),
|
||||
valueType: templates.ParamValueTypeNumber,
|
||||
required: true})
|
||||
label: c.localizedString("Loadpoint_WallboxMaxAmperage", nil),
|
||||
valueType: templates.ParamValueTypeNumber,
|
||||
minNumberValue: 6,
|
||||
maxNumberValue: 32,
|
||||
required: true})
|
||||
loadpoint.MaxCurrent, _ = strconv.Atoi(amperage)
|
||||
|
||||
if !chargerHasMeter {
|
||||
|
|
|
|||
|
|
@ -111,12 +111,13 @@ func (c *CmdConfigure) askYesNo(label string) bool {
|
|||
}
|
||||
|
||||
type question struct {
|
||||
label, help string
|
||||
defaultValue, exampleValue interface{}
|
||||
invalidValues []string
|
||||
valueType string
|
||||
mask, required bool
|
||||
excludeNone bool
|
||||
label, help string
|
||||
defaultValue, exampleValue interface{}
|
||||
invalidValues []string
|
||||
valueType string
|
||||
minNumberValue, maxNumberValue int64
|
||||
mask, required bool
|
||||
excludeNone bool
|
||||
}
|
||||
|
||||
// askBoolValue asks for a boolean value selection for a given question
|
||||
|
|
@ -177,10 +178,16 @@ func (c *CmdConfigure) askValue(q question) string {
|
|||
}
|
||||
|
||||
if q.valueType == templates.ParamValueTypeNumber {
|
||||
_, err := strconv.ParseInt(value, 10, 64)
|
||||
intValue, err := strconv.ParseInt(value, 10, 64)
|
||||
if err != nil {
|
||||
return errors.New(c.localizedString("ValueError_Number", nil))
|
||||
}
|
||||
if q.minNumberValue != 0 && intValue < q.minNumberValue {
|
||||
return errors.New(c.localizedString("ValueError_NumberLowerThanMin", localizeMap{"Min": q.minNumberValue}))
|
||||
}
|
||||
if q.maxNumberValue != 0 && intValue > q.maxNumberValue {
|
||||
return errors.New(c.localizedString("ValueError_NumberBiggerThanMax", localizeMap{"Max": q.maxNumberValue}))
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue