Skip to content

Commit fc7d64e

Browse files
committed
Extract _convertSchemaElement from _convertSchema
1 parent d7fe680 commit fc7d64e

File tree

1 file changed

+61
-53
lines changed

1 file changed

+61
-53
lines changed

hassio/src/addon-view/config/hassio-addon-config.ts

Lines changed: 61 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -92,67 +92,75 @@ class HassioAddonConfig extends LitElement {
9292

9393
private _convertSchema = memoizeOne(
9494
// Convert supervisor schema to selectors
95-
(schema: Record<string, any>): HaFormSchema[] =>
96-
schema.map((entry) => {
97-
if (entry.type === "select") {
98-
return {
99-
name: entry.name,
100-
required: entry.required,
101-
selector: { select: { options: entry.options } },
102-
};
103-
}
104-
if (entry.type === "string") {
105-
return entry.multiple
106-
? {
107-
name: entry.name,
108-
required: entry.required,
109-
selector: {
110-
select: { options: [], multiple: true, custom_value: true },
111-
},
112-
}
113-
: {
114-
name: entry.name,
115-
required: entry.required,
116-
selector: {
117-
text: {
118-
type: entry.format
119-
? entry.format
120-
: MASKED_FIELDS.includes(entry.name)
121-
? "password"
122-
: "text",
123-
},
124-
},
125-
};
126-
}
127-
if (entry.type === "boolean") {
128-
return {
129-
name: entry.name,
130-
required: entry.required,
131-
selector: { boolean: {} },
132-
};
133-
}
134-
if (entry.type === "schema") {
135-
return {
95+
(schema: readonly HaFormSchema[]): HaFormSchema[] =>
96+
this._convertSchemaElements(schema)
97+
);
98+
99+
private _convertSchemaElements(
100+
schema: readonly HaFormSchema[]
101+
): HaFormSchema[] {
102+
return schema.map((entry) => this._convertSchemaElement(entry));
103+
}
104+
105+
private _convertSchemaElement(entry: any): HaFormSchema {
106+
if (entry.type === "select") {
107+
return {
108+
name: entry.name,
109+
required: entry.required,
110+
selector: { select: { options: entry.options } },
111+
};
112+
}
113+
if (entry.type === "string") {
114+
return entry.multiple
115+
? {
136116
name: entry.name,
137117
required: entry.required,
138-
selector: { object: {} },
139-
};
140-
}
141-
if (entry.type === "float" || entry.type === "integer") {
142-
return {
118+
selector: {
119+
select: { options: [], multiple: true, custom_value: true },
120+
},
121+
}
122+
: {
143123
name: entry.name,
144124
required: entry.required,
145125
selector: {
146-
number: {
147-
mode: "box",
148-
step: entry.type === "float" ? "any" : undefined,
126+
text: {
127+
type: entry.format
128+
? entry.format
129+
: MASKED_FIELDS.includes(entry.name)
130+
? "password"
131+
: "text",
149132
},
150133
},
151134
};
152-
}
153-
return entry;
154-
})
155-
);
135+
}
136+
if (entry.type === "boolean") {
137+
return {
138+
name: entry.name,
139+
required: entry.required,
140+
selector: { boolean: {} },
141+
};
142+
}
143+
if (entry.type === "schema") {
144+
return {
145+
name: entry.name,
146+
required: entry.required,
147+
selector: { object: {} },
148+
};
149+
}
150+
if (entry.type === "float" || entry.type === "integer") {
151+
return {
152+
name: entry.name,
153+
required: entry.required,
154+
selector: {
155+
number: {
156+
mode: "box",
157+
step: entry.type === "float" ? "any" : undefined,
158+
},
159+
},
160+
};
161+
}
162+
return entry;
163+
}
156164

157165
private _filteredSchema = memoizeOne(
158166
(options: Record<string, unknown>, schema: HaFormSchema[]) =>

0 commit comments

Comments
 (0)