From a6bb2efe7ee5874abf7cf9a05075e78dbb9147ce Mon Sep 17 00:00:00 2001 From: andig Date: Sun, 29 Dec 2024 11:32:25 +0100 Subject: [PATCH] Revert "Templates: replace validvalues with choice (BC) (#17653)" This reverts commit 02cc6899a716b107979e4ac10a9a08d6305d5e2c. --- assets/js/components/Config/PropertyEntry.vue | 4 ++-- assets/js/components/Config/PropertyField.vue | 10 +++++----- assets/js/components/Config/VehicleModal.vue | 8 +------- assets/js/components/SelectGroup.vue | 2 +- cmd/configure/helper.go | 2 +- cmd/configure/survey.go | 18 +++++++++--------- templates/definition/charger/demo-charger.yaml | 3 +-- templates/definition/charger/stiebel-lwa.yaml | 3 +-- templates/definition/charger/stiebel-wpm.yaml | 3 +-- templates/definition/meter/goodwe-hybrid.yaml | 5 +++-- .../meter/kostal-plenticore-gen2.yaml | 3 +-- .../definition/meter/kostal-plenticore.yaml | 3 +-- templates/definition/meter/senec-home.yaml | 4 +++- templates/definition/meter/zendure.yaml | 2 +- templates/definition/tariff/awattar.yaml | 3 +-- templates/definition/tariff/elering.yaml | 3 +-- templates/definition/tariff/energinet.yaml | 3 +-- .../definition/tariff/energy-charts-api.yaml | 4 ++-- templates/definition/tariff/enever.yaml | 3 +-- templates/definition/tariff/nordpool.yaml | 6 ++---- .../definition/tariff/octopus-productcode.yaml | 4 ++-- templates/definition/tariff/spottyenergy.yaml | 3 +-- templates/definition/vehicle/bmw.yaml | 3 +-- templates/definition/vehicle/ford.yaml | 3 +-- templates/definition/vehicle/mercedes.yaml | 3 +-- templates/definition/vehicle/mg.yaml | 3 +-- templates/definition/vehicle/mini.yaml | 3 +-- util/templates/defaults.yaml | 5 ++--- util/templates/types.go | 1 + 29 files changed, 50 insertions(+), 70 deletions(-) diff --git a/assets/js/components/Config/PropertyEntry.vue b/assets/js/components/Config/PropertyEntry.vue index a1fe5bef9f..a1e5df70de 100644 --- a/assets/js/components/Config/PropertyEntry.vue +++ b/assets/js/components/Config/PropertyEntry.vue @@ -14,7 +14,7 @@ :type="Type" class="me-2" :required="Required" - :choice="Choice" + :validValues="ValidValues" /> @@ -36,7 +36,7 @@ export default { Example: String, Type: String, Mask: Boolean, - Choice: Array, + ValidValues: Array, modelValue: [String, Number, Boolean, Object], }, emits: ["update:modelValue"], diff --git a/assets/js/components/Config/PropertyField.vue b/assets/js/components/Config/PropertyField.vue index ac3f153302..77dd2ca649 100644 --- a/assets/js/components/Config/PropertyField.vue +++ b/assets/js/components/Config/PropertyField.vue @@ -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"], @@ -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]; diff --git a/assets/js/components/Config/VehicleModal.vue b/assets/js/components/Config/VehicleModal.vue index ba881e97ef..7628215447 100644 --- a/assets/js/components/Config/VehicleModal.vue +++ b/assets/js/components/Config/VehicleModal.vue @@ -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") { @@ -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); diff --git a/assets/js/components/SelectGroup.vue b/assets/js/components/SelectGroup.vue index a746dbb707..e6ccadb0e8 100644 --- a/assets/js/components/SelectGroup.vue +++ b/assets/js/components/SelectGroup.vue @@ -21,7 +21,7 @@ export default { props: { id: String, options: Array, - modelValue: [Number, String, Boolean], + modelValue: [Number, String], equalWidth: Boolean, large: Boolean, transparent: Boolean, diff --git a/cmd/configure/helper.go b/cmd/configure/helper.go index 8e2e72ac55..d2e994c15d 100644 --- a/cmd/configure/helper.go +++ b/cmd/configure/helper.go @@ -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(), }) diff --git a/cmd/configure/survey.go b/cmd/configure/survey.go index 09268fce33..be27dbbe9f 100644 --- a/cmd/configure/survey.go +++ b/cmd/configure/survey.go @@ -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 @@ -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, }) } @@ -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 { @@ -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")) } diff --git a/templates/definition/charger/demo-charger.yaml b/templates/definition/charger/demo-charger.yaml index 9ced91830b..6d959d9cc0 100644 --- a/templates/definition/charger/demo-charger.yaml +++ b/templates/definition/charger/demo-charger.yaml @@ -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: diff --git a/templates/definition/charger/stiebel-lwa.yaml b/templates/definition/charger/stiebel-lwa.yaml index e2cf3ada12..b10ce469bd 100644 --- a/templates/definition/charger/stiebel-lwa.yaml +++ b/templates/definition/charger/stiebel-lwa.yaml @@ -13,8 +13,7 @@ params: - name: modbus choice: ["tcpip"] - name: tempsource - type: choice - choice: ["", "warmwater"] + validvalues: ["", "warmwater"] description: de: "Temperaturquelle" en: "Temperature source" diff --git a/templates/definition/charger/stiebel-wpm.yaml b/templates/definition/charger/stiebel-wpm.yaml index 0d7a2692be..78c1ca3547 100644 --- a/templates/definition/charger/stiebel-wpm.yaml +++ b/templates/definition/charger/stiebel-wpm.yaml @@ -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" diff --git a/templates/definition/meter/goodwe-hybrid.yaml b/templates/definition/meter/goodwe-hybrid.yaml index de984aa8cc..5cb263fd79 100644 --- a/templates/definition/meter/goodwe-hybrid.yaml +++ b/templates/definition/meter/goodwe-hybrid.yaml @@ -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 diff --git a/templates/definition/meter/kostal-plenticore-gen2.yaml b/templates/definition/meter/kostal-plenticore-gen2.yaml index 4319a41794..c8f5efe76c 100644 --- a/templates/definition/meter/kostal-plenticore-gen2.yaml +++ b/templates/definition/meter/kostal-plenticore-gen2.yaml @@ -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 diff --git a/templates/definition/meter/kostal-plenticore.yaml b/templates/definition/meter/kostal-plenticore.yaml index caac55c6dd..815adf992a 100644 --- a/templates/definition/meter/kostal-plenticore.yaml +++ b/templates/definition/meter/kostal-plenticore.yaml @@ -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 diff --git a/templates/definition/meter/senec-home.yaml b/templates/definition/meter/senec-home.yaml index 314e466939..c22b7f27fe 100644 --- a/templates/definition/meter/senec-home.yaml +++ b/templates/definition/meter/senec-home.yaml @@ -11,7 +11,9 @@ params: - name: host - name: schema type: choice - choice: ["https", "http"] + validvalues: + - https + - http default: https - name: capacity advanced: true diff --git a/templates/definition/meter/zendure.yaml b/templates/definition/meter/zendure.yaml index 0136965a8d..5f53f2dcfe 100644 --- a/templates/definition/meter/zendure.yaml +++ b/templates/definition/meter/zendure.yaml @@ -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 diff --git a/templates/definition/tariff/awattar.yaml b/templates/definition/tariff/awattar.yaml index 27c795a5e3..9e9794a866 100644 --- a/templates/definition/tariff/awattar.yaml +++ b/templates/definition/tariff/awattar.yaml @@ -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 diff --git a/templates/definition/tariff/elering.yaml b/templates/definition/tariff/elering.yaml index 9656c76d00..faf7f53a9b 100644 --- a/templates/definition/tariff/elering.yaml +++ b/templates/definition/tariff/elering.yaml @@ -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 diff --git a/templates/definition/tariff/energinet.yaml b/templates/definition/tariff/energinet.yaml index 280877aa30..3f45119e6d 100644 --- a/templates/definition/tariff/energinet.yaml +++ b/templates/definition/tariff/energinet.yaml @@ -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 diff --git a/templates/definition/tariff/energy-charts-api.yaml b/templates/definition/tariff/energy-charts-api.yaml index 5b364ca036..a60382232f 100644 --- a/templates/definition/tariff/energy-charts-api.yaml +++ b/templates/definition/tariff/energy-charts-api.yaml @@ -9,9 +9,9 @@ requirements: group: price params: - name: bzn - type: choice + type: string required: true - choice: + validvalues: [ "AT", "BE", diff --git a/templates/definition/tariff/enever.yaml b/templates/definition/tariff/enever.yaml index 366bc4580b..99e131b03d 100644 --- a/templates/definition/tariff/enever.yaml +++ b/templates/definition/tariff/enever.yaml @@ -11,8 +11,7 @@ params: - name: token required: true - name: provider - type: choice - choice: + validvalues: [ "", "AA", diff --git a/templates/definition/tariff/nordpool.yaml b/templates/definition/tariff/nordpool.yaml index 7490ab3318..dc2e313240 100644 --- a/templates/definition/tariff/nordpool.yaml +++ b/templates/definition/tariff/nordpool.yaml @@ -10,8 +10,7 @@ group: price params: - name: region example: GER - type: choice - choice: + validvalues: [ "EE", "LT", @@ -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 diff --git a/templates/definition/tariff/octopus-productcode.yaml b/templates/definition/tariff/octopus-productcode.yaml index bc8108610b..5b033d724d 100644 --- a/templates/definition/tariff/octopus-productcode.yaml +++ b/templates/definition/tariff/octopus-productcode.yaml @@ -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/" diff --git a/templates/definition/tariff/spottyenergy.yaml b/templates/definition/tariff/spottyenergy.yaml index b0c8596002..61b4909be0 100644 --- a/templates/definition/tariff/spottyenergy.yaml +++ b/templates/definition/tariff/spottyenergy.yaml @@ -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" diff --git a/templates/definition/vehicle/bmw.yaml b/templates/definition/vehicle/bmw.yaml index b4ac04d332..ec572189a1 100644 --- a/templates/definition/vehicle/bmw.yaml +++ b/templates/definition/vehicle/bmw.yaml @@ -15,8 +15,7 @@ params: description: de: Region en: Region - type: choice - choice: ["EU", "NA"] + validvalues: ["NA", "EU"] default: EU advanced: true - name: hcaptcha diff --git a/templates/definition/vehicle/ford.yaml b/templates/definition/vehicle/ford.yaml index ddab0d27db..088f969211 100644 --- a/templates/definition/vehicle/ford.yaml +++ b/templates/definition/vehicle/ford.yaml @@ -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" . }} diff --git a/templates/definition/vehicle/mercedes.yaml b/templates/definition/vehicle/mercedes.yaml index 9e3f07f8b0..83914fbfdf 100644 --- a/templates/definition/vehicle/mercedes.yaml +++ b/templates/definition/vehicle/mercedes.yaml @@ -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 diff --git a/templates/definition/vehicle/mg.yaml b/templates/definition/vehicle/mg.yaml index 498f1cf0f3..2a55b41c41 100644 --- a/templates/definition/vehicle/mg.yaml +++ b/templates/definition/vehicle/mg.yaml @@ -9,8 +9,7 @@ params: description: de: Region en: Region - type: choice - choice: ["EU", "AU"] + validvalues: ["EU", "AU"] default: EU advanced: true render: | diff --git a/templates/definition/vehicle/mini.yaml b/templates/definition/vehicle/mini.yaml index 56f28c6589..e72ad4f058 100644 --- a/templates/definition/vehicle/mini.yaml +++ b/templates/definition/vehicle/mini.yaml @@ -15,8 +15,7 @@ params: description: de: Region en: Region - type: choice - choice: ["EU", "NA"] + validvalues: ["NA", "EU"] default: EU advanced: true - name: hcaptcha diff --git a/util/templates/defaults.yaml b/util/templates/defaults.yaml index 1db8a10570..cef7421289 100644 --- a/util/templates/defaults.yaml +++ b/util/templates/defaults.yaml @@ -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 @@ -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 diff --git a/util/templates/types.go b/util/templates/types.go index 9b834192ca..d0fa22730a 100644 --- a/util/templates/types.go +++ b/util/templates/types.go @@ -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