-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Check if config is compatible with UI editor #2137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
68a36f5
3241a30
915a8d2
9bd76da
296654f
58bd653
c53980b
a461c5c
6d223cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,13 @@ | ||
| import { html, LitElement, PropertyDeclarations } from "@polymer/lit-element"; | ||
| import { TemplateResult } from "lit-html"; | ||
| import { struct } from "superstruct"; | ||
| import "@polymer/paper-dropdown-menu/paper-dropdown-menu"; | ||
| import "@polymer/paper-item/paper-item"; | ||
| import "@polymer/paper-listbox/paper-listbox"; | ||
| import "@polymer/paper-toggle-button/paper-toggle-button"; | ||
|
|
||
| import { processEditorEntities } from "../process-editor-entities"; | ||
|
|
||
| import { EntitiesEditorEvent, EditorTarget } from "../types"; | ||
| import { hassLocalizeLitMixin } from "../../../../mixins/lit-localize-mixin"; | ||
| import { HomeAssistant } from "../../../../types"; | ||
|
|
@@ -20,6 +22,24 @@ import "../../components/hui-entity-editor"; | |
| import "../../../../components/ha-card"; | ||
| import "../../../../components/ha-icon"; | ||
|
|
||
| const entitiesConfigStruct = struct.union([ | ||
| { | ||
| entity: "string", | ||
| name: "string?", | ||
| icon: "string?", | ||
| }, | ||
| "string", | ||
| ]); | ||
|
|
||
| const cardConfigStruct = struct({ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So nice!
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am wondering, this is something we should probably export from the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah nevermind, the config editor only supports a subset so needs their own.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably, but the struct of the editor is a little bit simpler as it doesn't support special rows etc.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yet 😉
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we can have our special struct register types that validate objects. So we can have something like const struct = superstruct({
'divider-row': validateDividerRow,
'entity-row': validateEntityRow,
})
const validate = struct({
entities: ['divider-row|entity-row']
})
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And use a struct inside
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah use a struct inside the validator, if that can work. Was just thinking out loud. |
||
| type: "string", | ||
| id: "string|number", | ||
| title: "string|number?", | ||
| theme: "string?", | ||
| show_header_toggle: "boolean?", | ||
| entities: [entitiesConfigStruct], | ||
| }); | ||
|
|
||
| export class HuiEntitiesCardEditor extends hassLocalizeLitMixin(LitElement) | ||
| implements LovelaceCardEditor { | ||
| public hass?: HomeAssistant; | ||
|
|
@@ -39,6 +59,8 @@ export class HuiEntitiesCardEditor extends hassLocalizeLitMixin(LitElement) | |
| } | ||
|
|
||
| public setConfig(config: Config): void { | ||
| config = cardConfigStruct(config); | ||
|
|
||
| this._config = { type: "entities", ...config }; | ||
| this._configEntities = processEditorEntities(config.entities); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add a superstruct that validates entity ID and icon to be valid format?
.:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah we should! 👍