Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/panels/lovelace/common/data.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { HomeAssistant } from "../../../types";
import { LovelaceConfig } from "../types";

export const getCardConfig = (
hass: HomeAssistant,
Expand All @@ -12,10 +13,17 @@ export const getCardConfig = (
export const updateCardConfig = (
hass: HomeAssistant,
cardId: string,
config: any
config: LovelaceConfig | string,
configFormat: "json" | "yaml"
): Promise<void> =>
hass!.callWS({
type: "lovelace/config/card/update",
card_id: cardId,
card_config: config,
format: configFormat,
});

export const migrateConfig = (hass: HomeAssistant): Promise<void> =>
hass!.callWS({
Comment thread
bramkragten marked this conversation as resolved.
Outdated
type: "lovelace/config/migrate",
});
8 changes: 4 additions & 4 deletions src/panels/lovelace/components/hui-card-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import "@polymer/paper-button/paper-button";
import { html, LitElement, PropertyDeclarations } from "@polymer/lit-element";
import { fireEvent } from "../../../common/dom/fire_event";
import { HomeAssistant } from "../../../types";
import { LovelaceConfig } from "../types";

let registeredDialog = false;

export class HuiCardOptions extends LitElement {
public cardId?: string;
public cardConfig?: LovelaceConfig;
protected hass?: HomeAssistant;

static get properties(): PropertyDeclarations {
return {
hass: {},
};
return { hass: {} };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this was changed. I dont think this is "prettier"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is, small objects will be put on a single line.

}

public connectedCallback() {
Expand Down Expand Up @@ -51,7 +51,7 @@ export class HuiCardOptions extends LitElement {
private _editCard() {
fireEvent(this, "show-edit-card", {
hass: this.hass,
cardId: this.cardId,
cardConfig: this.cardConfig,
reloadLovelace: () => fireEvent(this, "config-refresh"),
});
}
Expand Down
57 changes: 57 additions & 0 deletions src/panels/lovelace/editor/hui-card-preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import "@polymer/paper-input/paper-textarea";

import createCardElement from "../common/create-card-element";
import createErrorCardConfig from "../common/create-error-card-config";
import { HomeAssistant } from "../../../types";
import { LovelaceCard, LovelaceConfig } from "../types";
import { ConfigError } from "./types";

export class HuiCardPreview extends HTMLElement {
private _hass?: HomeAssistant;

set hass(value: HomeAssistant) {
this._hass = value;
if (this.lastChild) {
(this.lastChild as LovelaceCard).hass = value;
}
}

set error(error: ConfigError) {
const configValue = createErrorCardConfig(
`${error.type}: ${error.message}`,
undefined
);

this._createCard(configValue);
}

set value(configValue: LovelaceConfig) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can make this set config right? To align with everything else as well as its param type

this._createCard(configValue);
}

private _createCard(configValue: LovelaceConfig): void {
if (this.lastChild) {
this.removeChild(this.lastChild);
}

if (!configValue) {
return;
}

const element = createCardElement(configValue);

if (this._hass) {
element.hass = this._hass;
}

this.appendChild(element);
}
}

declare global {
interface HTMLElementTagNameMap {
"hui-card-preview": HuiCardPreview;
}
}

customElements.define("hui-card-preview", HuiCardPreview);
Loading