Templates: replace validvalues with choice (BC) (#17653)

This commit is contained in:
andig 2024-12-27 12:39:41 +01:00 • committed by GitHub
parent a92b6eac5e
commit 02cc6899a7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
29 changed files with 70 additions and 50 deletions

View file

@ -14,7 +14,7 @@
:type="Type"
class="me-2"
:required="Required"
:validValues="ValidValues"
:choice="Choice"
/>
</FormRow>
</template>
@ -36,7 +36,7 @@ export default {
Example: String,
Type: String,
Mask: Boolean,
ValidValues: Array,
Choice: Array,
modelValue: [String, Number, Boolean, Object],
},
emits: ["update:modelValue"],

View file

@ -111,7 +111,7 @@ export default {
size: String,
scale: Number,
required: Boolean,
validValues: { type: Array, default: () => [] },
choice: { type: Array, default: () => [] },
modelValue: [String, Number, Boolean, Object],
},
emits: ["update:modelValue"],
@ -171,15 +171,15 @@ export default {
return this.type === "List";
},
select() {
return this.validValues.length > 0;
return this.choice.length > 0;
},
selectOptions() {
// If the valid values are already in the correct format, return them
if (typeof this.validValues[0] === "object") {
return this.validValues;
if (typeof this.choice[0] === "object") {
return this.choice;
}
let values = [...this.validValues];
let values = [...this.choice];
if (this.icons && !this.required) {
values = ["", ...values];

View file

@ -313,7 +313,7 @@ export default {
};
},
templateParams() {
return (this.template?.Params || [])
const params = (this.template?.Params || [])
.filter((p) => !CUSTOM_FIELDS.includes(p.Name))
.map((p) => {
if (p.Name === "title" || p.Name === "icon") {
@ -322,6 +322,12 @@ export default {
}
return p;
});
// always start with title and icon field
const order = { title: -2, icon: -1 };
params.sort((a, b) => (order[a.Name] || 0) - (order[b.Name] || 0));
return params;
},
normalParams() {
return this.templateParams.filter((p) => !p.Advanced);

View file

@ -21,7 +21,7 @@ export default {
props: {
id: String,
options: Array,
modelValue: [Number, String],
modelValue: [Number, String, Boolean],
equalWidth: Boolean,
large: Boolean,
transparent: Boolean,

View file

@ -444,7 +444,7 @@ func (c *CmdConfigure) processInputConfig(param templates.Param) string {
exampleValue: param.Example,
help: param.Help.ShortString(c.lang),
valueType: param.Type,
validValues: param.ValidValues,
choice: param.Choice,
mask: param.IsMasked(),
required: param.IsRequired(),
})

View file

@ -104,7 +104,7 @@ type question struct {
label, help string
defaultValue, exampleValue string
invalidValues []string
validValues []string
choice []string
valueType templates.ParamType
minNumberValue, maxNumberValue int64
mask, required bool
@ -130,11 +130,11 @@ func (c *CmdConfigure) askParam(p templates.Param) string {
}
return c.askValue(question{
label: p.Description.String(c.lang),
valueType: p.Type,
validValues: p.Choice, // TODO proper choice handling
mask: mask,
required: required,
label: p.Description.String(c.lang),
valueType: p.Type,
choice: p.Choice,
mask: mask,
required: required,
})
}
@ -155,8 +155,8 @@ func (c *CmdConfigure) askValue(q question) string {
if q.valueType == templates.TypeChoice {
label := strings.TrimSpace(strings.Join([]string{q.label, c.localizedString("Value_Choice")}, " "))
idx, _ := c.askChoice(label, q.validValues)
return q.validValues[idx]
idx, _ := c.askChoice(label, q.choice)
return q.choice[idx]
}
if q.valueType == templates.TypeChargeModes {
@ -181,7 +181,7 @@ func (c *CmdConfigure) askValue(q question) string {
return errors.New(c.localizedString("ValueError_Used"))
}
if q.validValues != nil && !slices.Contains(q.validValues, value) {
if q.choice != nil && !slices.Contains(q.choice, value) {
return errors.New(c.localizedString("ValueError_Invalid"))
}

View file

@ -13,7 +13,8 @@ params:
description:
de: Ladezustand
en: Charge status
validvalues: [A, B, C, D, E, F]
type: choice
choice: [A, B, C, D, E, F]
default: A
- name: power
description:

View file

@ -13,7 +13,8 @@ params:
- name: modbus
choice: ["tcpip"]
- name: tempsource
validvalues: ["", "warmwater"]
type: choice
choice: ["", "warmwater"]
description:
de: "Temperaturquelle"
en: "Temperature source"

View file

@ -10,7 +10,8 @@ params:
- name: modbus
choice: ["tcpip"]
- name: tempsource
validvalues: ["", "warmwater", "buffer"]
type: choice
choice: ["", "warmwater", "buffer"]
description:
de: "Temperaturquelle"
en: "Temperature source"

View file

@ -13,9 +13,8 @@ params:
id: 247
- name: battery
default: 1
validvalues:
- 1
- 2
type: choice
choice: [1, 2]
- name: capacity
advanced: true
- name: maxacpower

View file

@ -34,7 +34,8 @@ params:
description:
de: Byte-Reihenfolge (Little/Big)
en: Endianness (Little/Big)
validvalues: ["big", "little"]
type: choice
choice: ["little", "big"]
default: little
advanced: true
- name: capacity

View file

@ -30,7 +30,8 @@ params:
description:
de: Byte-Reihenfolge (Little/Big)
en: Endianness (Little/Big)
validvalues: ["big", "little"]
type: choice
choice: ["little", "big"]
default: little
advanced: true
- name: capacity

View file

@ -11,9 +11,7 @@ params:
- name: host
- name: schema
type: choice
validvalues:
- https
- http
choice: ["https", "http"]
default: https
- name: capacity
advanced: true

View file

@ -19,8 +19,8 @@ params:
en: "You can find this in the Zendure App in the settings of the device"
- name: region
type: choice
choice: ["EU", "Global"]
default: EU
validvalues: ["EU", "Global"]
- name: capacity
default: 2
advanced: true

View file

@ -9,7 +9,8 @@ group: price
params:
- name: region
example: AT
validvalues: ["DE", "AT"]
type: choice
choice: ["DE", "AT"]
- preset: tariff-base
render: |
type: awattar

View file

@ -12,7 +12,8 @@ group: price
params:
- name: region
example: ee
validvalues: ["ee", "lt", "lv", "fi"]
type: choice
choice: ["ee", "lt", "lv", "fi"]
- preset: tariff-base
render: |
type: elering

View file

@ -10,7 +10,8 @@ group: price
params:
- name: region
example: dk1
validvalues: ["dk1", "dk2"]
type: choice
choice: ["dk1", "dk2"]
- preset: tariff-base
render: |
type: energinet

View file

@ -9,9 +9,9 @@ requirements:
group: price
params:
- name: bzn
type: string
type: choice
required: true
validvalues:
choice:
[
"AT",
"BE",

View file

@ -11,7 +11,8 @@ params:
- name: token
required: true
- name: provider
validvalues:
type: choice
choice:
[
"",
"AA",

View file

@ -10,7 +10,8 @@ group: price
params:
- name: region
example: GER
validvalues:
type: choice
choice:
[
"EE",
"LT",
@ -38,7 +39,8 @@ params:
]
- name: currency
default: EUR
validvalues: ["DKK", "EUR", "NOK", "PLN", "RON", "SEK"]
type: choice
choice: ["DKK", "EUR", "NOK", "PLN", "RON", "SEK"]
- preset: tariff-base
render: |
type: custom

View file

@ -13,8 +13,8 @@ params:
de: "Der Tarifcode für Ihren Energievertrag. Stellen Sie sicher, dass dieser auf Ihren Importtarifcode eingestellt ist."
en: "The tariff code for your energy contract. Make sure this is set to your import tariff code."
- name: region
type: string
validvalues: ["A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P"]
type: choice
choice: ["A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P"]
required: true
help:
de: "Die DNO-Region, in der Sie sich befinden. Weitere Informationen: https://www.energy-stats.uk/dno-region-codes-explained/"

View file

@ -15,7 +15,8 @@ params:
en: "You can get your contract id from the customer portal https://i.spottyenergie.at/"
- name: pricetype
default: CONSUMPTION
validvalues: ["MARKET", "CONSUMPTION", "GENERATION"]
type: choice
choice: ["MARKET", "CONSUMPTION", "GENERATION"]
required: true
help:
de: "Preistyp, entweder Börsenpreis, Verbrauchspreis oder Einspeisevergütung (falls vereinbart), siehe https://www.spottyenergie.at/blog/energie-smart-produzieren"

View file

@ -15,7 +15,8 @@ params:
description:
de: Region
en: Region
validvalues: ["NA", "EU"]
type: choice
choice: ["EU", "NA"]
default: EU
advanced: true
- name: hcaptcha

View file

@ -7,8 +7,9 @@ params:
- name: vin
example: WF0FXX...
- name: domain
type: choice
choice: ["com", "de"]
default: com
validvalues: ["de", "com"]
render: |
type: ford
{{ include "vehicle-base" . }}

View file

@ -13,7 +13,8 @@ params:
required: true
- name: region
required: true
validvalues: [EMEA, APAC, NORAM]
type: choice
choice: ["EMEA", "APAC", "NORAM"]
default: EMEA
- name: accessToken
required: true

View file

@ -9,7 +9,8 @@ params:
description:
de: Region
en: Region
validvalues: ["EU", "AU"]
type: choice
choice: ["EU", "AU"]
default: EU
advanced: true
render: |

View file

@ -15,7 +15,8 @@ params:
description:
de: Region
en: Region
validvalues: ["NA", "EU"]
type: choice
choice: ["EU", "NA"]
default: EU
advanced: true
- name: hcaptcha

View file

@ -222,7 +222,8 @@ params:
de: "'de' für Deutsch und 'en' für Englisch"
en: "'en' for English and 'de' for German"
default: en
validvalues: ["de", "en"]
type: choice
choice: ["en", "de"]
- name: icon
description:
de: Icon
@ -231,7 +232,7 @@ params:
de: "Icon in der Benutzeroberfläche"
en: "Icon as shown in user interface"
type: choice
validvalues:
choice:
- car
- bike
- bus

View file

@ -187,7 +187,6 @@ type Param struct {
Values []string `json:",omitempty"` // user provided list of values e.g. for Type "list"
Usages []string `json:",omitempty"` // restrict param to these usage types, e.g. "battery" for home battery capacity
Type ParamType // string representation of the value type, "string" is default
ValidValues []string `json:",omitempty"` // list of valid values the user can provide
Choice []string `json:",omitempty"` // defines a set of choices, e.g. "grid", "pv", "battery", "charge" for "usage"
AllInOne *bool `json:"-"` // defines if the defined usages can all be present in a single device