Skip to content

Commit

Permalink
Revert "Templates: replace validvalues with choice (BC) (#17653)"
Browse files Browse the repository at this point in the history
This reverts commit 02cc689.
  • Loading branch information
andig committed Dec 29, 2024
1 parent 6db5b66 commit a6bb2ef
Show file tree
Hide file tree
Showing 29 changed files with 50 additions and 70 deletions.
4 changes: 2 additions & 2 deletions assets/js/components/Config/PropertyEntry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
:type="Type"
class="me-2"
:required="Required"
:choice="Choice"
:validValues="ValidValues"
/>
</FormRow>
</template>
Expand All @@ -36,7 +36,7 @@ export default {
Example: String,
Type: String,
Mask: Boolean,
Choice: Array,
ValidValues: Array,
modelValue: [String, Number, Boolean, Object],
},
emits: ["update:modelValue"],
Expand Down
10 changes: 5 additions & 5 deletions assets/js/components/Config/PropertyField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export default {
size: String,
scale: Number,
required: Boolean,
choice: { type: Array, default: () => [] },
validValues: { type: Array, default: () => [] },
modelValue: [String, Number, Boolean, Object],
},
emits: ["update:modelValue"],
Expand Down Expand Up @@ -171,15 +171,15 @@ export default {
return this.type === "List";
},
select() {
return this.choice.length > 0;
return this.validValues.length > 0;
},
selectOptions() {
// If the valid values are already in the correct format, return them
if (typeof this.choice[0] === "object") {
return this.choice;
if (typeof this.validValues[0] === "object") {
return this.validValues;
}
let values = [...this.choice];
let values = [...this.validValues];
if (this.icons && !this.required) {
values = ["", ...values];
Expand Down
8 changes: 1 addition & 7 deletions assets/js/components/Config/VehicleModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ export default {
};
},
templateParams() {
const params = (this.template?.Params || [])
return (this.template?.Params || [])
.filter((p) => !CUSTOM_FIELDS.includes(p.Name))
.map((p) => {
if (p.Name === "title" || p.Name === "icon") {
Expand All @@ -322,12 +322,6 @@ 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);
Expand Down
2 changes: 1 addition & 1 deletion assets/js/components/SelectGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default {
props: {
id: String,
options: Array,
modelValue: [Number, String, Boolean],
modelValue: [Number, String],
equalWidth: Boolean,
large: Boolean,
transparent: Boolean,
Expand Down
2 changes: 1 addition & 1 deletion cmd/configure/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ func (c *CmdConfigure) processInputConfig(param templates.Param) string {
exampleValue: param.Example,
help: param.Help.ShortString(c.lang),
valueType: param.Type,
choice: param.Choice,
validValues: param.ValidValues,
mask: param.IsMasked(),
required: param.IsRequired(),
})
Expand Down
18 changes: 9 additions & 9 deletions cmd/configure/survey.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ type question struct {
label, help string
defaultValue, exampleValue string
invalidValues []string
choice []string
validValues []string
valueType templates.ParamType
minNumberValue, maxNumberValue int64
mask, required bool
Expand All @@ -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,
choice: p.Choice,
mask: mask,
required: required,
label: p.Description.String(c.lang),
valueType: p.Type,
validValues: p.Choice, // TODO proper choice handling
mask: mask,
required: required,
})
}

Expand All @@ -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.choice)
return q.choice[idx]
idx, _ := c.askChoice(label, q.validValues)
return q.validValues[idx]
}

if q.valueType == templates.TypeChargeModes {
Expand All @@ -181,7 +181,7 @@ func (c *CmdConfigure) askValue(q question) string {
return errors.New(c.localizedString("ValueError_Used"))
}

if q.choice != nil && !slices.Contains(q.choice, value) {
if q.validValues != nil && !slices.Contains(q.validValues, value) {
return errors.New(c.localizedString("ValueError_Invalid"))
}

Expand Down
3 changes: 1 addition & 2 deletions templates/definition/charger/demo-charger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ params:
description:
de: Ladezustand
en: Charge status
type: choice
choice: [A, B, C, D, E, F]
validvalues: [A, B, C, D, E, F]
default: A
- name: power
description:
Expand Down
3 changes: 1 addition & 2 deletions templates/definition/charger/stiebel-lwa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ params:
- name: modbus
choice: ["tcpip"]
- name: tempsource
type: choice
choice: ["", "warmwater"]
validvalues: ["", "warmwater"]
description:
de: "Temperaturquelle"
en: "Temperature source"
Expand Down
3 changes: 1 addition & 2 deletions templates/definition/charger/stiebel-wpm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ params:
- name: modbus
choice: ["tcpip"]
- name: tempsource
type: choice
choice: ["", "warmwater", "buffer"]
validvalues: ["", "warmwater", "buffer"]
description:
de: "Temperaturquelle"
en: "Temperature source"
Expand Down
5 changes: 3 additions & 2 deletions templates/definition/meter/goodwe-hybrid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ params:
id: 247
- name: battery
default: 1
type: choice
choice: [1, 2]
validvalues:
- 1
- 2
- name: capacity
advanced: true
- name: maxacpower
Expand Down
3 changes: 1 addition & 2 deletions templates/definition/meter/kostal-plenticore-gen2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ params:
description:
de: Byte-Reihenfolge (Little/Big)
en: Endianness (Little/Big)
type: choice
choice: ["little", "big"]
validvalues: ["big", "little"]
default: little
advanced: true
- name: capacity
Expand Down
3 changes: 1 addition & 2 deletions templates/definition/meter/kostal-plenticore.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ params:
description:
de: Byte-Reihenfolge (Little/Big)
en: Endianness (Little/Big)
type: choice
choice: ["little", "big"]
validvalues: ["big", "little"]
default: little
advanced: true
- name: capacity
Expand Down
4 changes: 3 additions & 1 deletion templates/definition/meter/senec-home.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ params:
- name: host
- name: schema
type: choice
choice: ["https", "http"]
validvalues:
- https
- http
default: https
- name: capacity
advanced: true
Expand Down
2 changes: 1 addition & 1 deletion templates/definition/meter/zendure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions templates/definition/tariff/awattar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ group: price
params:
- name: region
example: AT
type: choice
choice: ["DE", "AT"]
validvalues: ["DE", "AT"]
- preset: tariff-base
render: |
type: awattar
Expand Down
3 changes: 1 addition & 2 deletions templates/definition/tariff/elering.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ group: price
params:
- name: region
example: ee
type: choice
choice: ["ee", "lt", "lv", "fi"]
validvalues: ["ee", "lt", "lv", "fi"]
- preset: tariff-base
render: |
type: elering
Expand Down
3 changes: 1 addition & 2 deletions templates/definition/tariff/energinet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ group: price
params:
- name: region
example: dk1
type: choice
choice: ["dk1", "dk2"]
validvalues: ["dk1", "dk2"]
- preset: tariff-base
render: |
type: energinet
Expand Down
4 changes: 2 additions & 2 deletions templates/definition/tariff/energy-charts-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ requirements:
group: price
params:
- name: bzn
type: choice
type: string
required: true
choice:
validvalues:
[
"AT",
"BE",
Expand Down
3 changes: 1 addition & 2 deletions templates/definition/tariff/enever.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ params:
- name: token
required: true
- name: provider
type: choice
choice:
validvalues:
[
"",
"AA",
Expand Down
6 changes: 2 additions & 4 deletions templates/definition/tariff/nordpool.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ group: price
params:
- name: region
example: GER
type: choice
choice:
validvalues:
[
"EE",
"LT",
Expand Down Expand Up @@ -39,8 +38,7 @@ params:
]
- name: currency
default: EUR
type: choice
choice: ["DKK", "EUR", "NOK", "PLN", "RON", "SEK"]
validvalues: ["DKK", "EUR", "NOK", "PLN", "RON", "SEK"]
- preset: tariff-base
render: |
type: custom
Expand Down
4 changes: 2 additions & 2 deletions templates/definition/tariff/octopus-productcode.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: choice
choice: ["A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P"]
type: string
validvalues: ["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/"
Expand Down
3 changes: 1 addition & 2 deletions templates/definition/tariff/spottyenergy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ params:
en: "You can get your contract id from the customer portal https://i.spottyenergie.at/"
- name: pricetype
default: CONSUMPTION
type: choice
choice: ["MARKET", "CONSUMPTION", "GENERATION"]
validvalues: ["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"
Expand Down
3 changes: 1 addition & 2 deletions templates/definition/vehicle/bmw.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ params:
description:
de: Region
en: Region
type: choice
choice: ["EU", "NA"]
validvalues: ["NA", "EU"]
default: EU
advanced: true
- name: hcaptcha
Expand Down
3 changes: 1 addition & 2 deletions templates/definition/vehicle/ford.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ params:
- name: vin
example: WF0FXX...
- name: domain
type: choice
choice: ["com", "de"]
default: com
validvalues: ["de", "com"]
render: |
type: ford
{{ include "vehicle-base" . }}
Expand Down
3 changes: 1 addition & 2 deletions templates/definition/vehicle/mercedes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ params:
required: true
- name: region
required: true
type: choice
choice: ["EMEA", "APAC", "NORAM"]
validvalues: [EMEA, APAC, NORAM]
default: EMEA
- name: accessToken
required: true
Expand Down
3 changes: 1 addition & 2 deletions templates/definition/vehicle/mg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ params:
description:
de: Region
en: Region
type: choice
choice: ["EU", "AU"]
validvalues: ["EU", "AU"]
default: EU
advanced: true
render: |
Expand Down
3 changes: 1 addition & 2 deletions templates/definition/vehicle/mini.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ params:
description:
de: Region
en: Region
type: choice
choice: ["EU", "NA"]
validvalues: ["NA", "EU"]
default: EU
advanced: true
- name: hcaptcha
Expand Down
5 changes: 2 additions & 3 deletions util/templates/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,7 @@ params:
de: "'de' für Deutsch und 'en' für Englisch"
en: "'en' for English and 'de' for German"
default: en
type: choice
choice: ["en", "de"]
validvalues: ["de", "en"]
- name: icon
description:
de: Icon
Expand All @@ -232,7 +231,7 @@ params:
de: "Icon in der Benutzeroberfläche"
en: "Icon as shown in user interface"
type: choice
choice:
validvalues:
- car
- bike
- bus
Expand Down
1 change: 1 addition & 0 deletions util/templates/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ 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

Expand Down

0 comments on commit a6bb2ef

Please sign in to comment.