Config UI: fix user-defined vehicle title/icon not displayed (#21956)

This commit is contained in:
andig 2025-06-23 11:01:41 +02:00 • committed by GitHub
parent b6e6529364
commit 01504b99e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 23 additions and 1 deletions

View file

@ -318,6 +318,7 @@ export default defineComponent({
// remove icon if custom
if (this.values.type === ConfigType.Custom) {
delete data["icon"];
delete data["title"];
}
// trim and remove empty lines
if (Array.isArray(data["identifiers"])) {

View file

@ -18,6 +18,7 @@ import (
"github.com/evcc-io/evcc/util/templates"
"github.com/evcc-io/evcc/vehicle"
"github.com/gorilla/mux"
"gopkg.in/yaml.v3"
)
func devicesConfig[T any](class templates.Class, h config.Handler[T]) ([]map[string]any, error) {
@ -107,7 +108,25 @@ func deviceConfigMap[T any](class templates.Class, dev config.Device[T]) (map[st
dc["config"] = params
} else {
// custom device, no masking
dc["config"] = conf.Other
config := make(map[string]any)
for k, v := range conf.Other {
config[k] = v
}
// extract title & icon if possible (user-defined vehicle embeds)
if yamlStr, ok := conf.Other["yaml"].(string); ok && config["title"] == nil && config["icon"] == nil {
var yamlData map[string]any
if err := yaml.Unmarshal([]byte(yamlStr), &yamlData); err == nil {
if title, ok := yamlData["title"].(string); ok {
config["title"] = title
}
if icon, ok := yamlData["icon"].(string); ok {
config["icon"] = icon
}
}
}
dc["config"] = config
}
}

View file

@ -240,6 +240,7 @@ soc:
await page.reload();
await expect(page.getByTestId("vehicle")).toHaveCount(1);
await expect(page.getByTestId("vehicle").nth(0)).toContainText("blue Honda");
await page.getByTestId("vehicle").getByRole("button", { name: "edit" }).click();
await expectModalVisible(modal);
await expect(modal.getByLabel("Manufacturer")).toHaveValue("User-defined device");
@ -265,6 +266,7 @@ soc:
await modal.getByRole("button", { name: "Save" }).click();
await expectModalHidden(modal);
await expect(page.getByTestId("vehicle")).toHaveCount(1);
await expect(page.getByTestId("vehicle").nth(0)).toContainText("pink Honda");
// delete
await page.getByTestId("vehicle").getByRole("button", { name: "edit" }).click();