Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
35 changes: 27 additions & 8 deletions gallery/src/components/demo-cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ import { PolymerElement } from "@polymer/polymer/polymer-element";
import "../../../src/components/ha-switch";
import "../../../src/components/ha-formfield";
import "./demo-card";
import { applyThemesOnElement } from "../../../src/common/dom/apply_themes_on_element";

class DemoCards extends PolymerElement {
static get template() {
return html`
<style>
#container {
min-height: calc(100vh - 128px);
background: var(--primary-background-color);
}
.cards {
display: flex;
flex-wrap: wrap;
Expand All @@ -24,23 +29,31 @@ class DemoCards extends PolymerElement {
.filters {
margin-left: 60px;
}
ha-formfield {
margin-right: 16px;
}
</style>
<app-toolbar>
<div class="filters">
<ha-formfield label="Show config">
<ha-switch checked="[[_showConfig]]" on-change="_showConfigToggled">
</ha-switch>
</ha-formfield>
<ha-formfield label="Dark theme">
<ha-switch on-change="_darkThemeToggled"> </ha-switch>
</ha-formfield>
</div>
</app-toolbar>
<div class="cards">
<template is="dom-repeat" items="[[configs]]">
<demo-card
config="[[item]]"
show-config="[[_showConfig]]"
hass="[[hass]]"
></demo-card>
</template>
<div id="container">
<div class="cards">
<template is="dom-repeat" items="[[configs]]">
<demo-card
config="[[item]]"
show-config="[[_showConfig]]"
hass="[[hass]]"
></demo-card>
</template>
</div>
</div>
`;
}
Expand All @@ -59,6 +72,12 @@ class DemoCards extends PolymerElement {
_showConfigToggled(ev) {
this._showConfig = ev.target.checked;
}

_darkThemeToggled(ev) {
applyThemesOnElement(this.$.container, { themes: {} }, "default", {
dark: ev.target.checked,
});
}
}

customElements.define("demo-cards", DemoCards);
9 changes: 3 additions & 6 deletions gallery/src/components/demo-more-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { html } from "@polymer/polymer/lib/utils/html-tag";
import { PolymerElement } from "@polymer/polymer/polymer-element";
import "../../../src/components/ha-card";
import "../../../src/state-summary/state-card-content";
import "./more-info-content";
import "../../../src/dialogs/more-info/more-info-content";

class DemoMoreInfo extends PolymerElement {
static get template() {
Expand All @@ -16,15 +16,12 @@ class DemoMoreInfo extends PolymerElement {

ha-card {
width: 333px;
padding: 20px 24px;
}

state-card-content {
display: block;
padding: 16px;
}

more-info-content {
padding: 0 16px;
margin-bottom: 16px;
}

pre {
Expand Down
73 changes: 0 additions & 73 deletions gallery/src/components/more-info-content.ts

This file was deleted.

19 changes: 17 additions & 2 deletions gallery/src/demos/demo-hui-alarm-panel-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ const ENTITIES = [
getEntity("alarm_control_panel", "unavailable", "unavailable", {
friendly_name: "Alarm",
}),
getEntity("alarm_control_panel", "alarm_code", "disarmed", {
friendly_name: "Alarm",
code_format: "number",
}),
];

const CONFIGS = [
Expand All @@ -30,7 +34,14 @@ const CONFIGS = [
config: `
- type: alarm-panel
entity: alarm_control_panel.alarm_armed
title: My Alarm
name: My Alarm
`,
},
{
heading: "Code Example",
config: `
- type: alarm-panel
entity: alarm_control_panel.alarm_code
`,
},
{
Expand Down Expand Up @@ -83,8 +94,12 @@ class DemoAlarmPanelEntity extends PolymerElement {

public ready() {
super.ready();
this._setupDemo();
}

private async _setupDemo() {
const hass = provideHass(this.$.demos);
hass.updateTranslations(null, "en");
await hass.updateTranslations(null, "en");
hass.addEntities(ENTITIES);
}
}
Expand Down
2 changes: 1 addition & 1 deletion gallery/src/demos/demo-hui-entity-button-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,4 @@ class DemoButtonEntity extends PolymerElement {
}
}

customElements.define("demo-hui-button-card", DemoButtonEntity);
customElements.define("demo-hui-entity-button-card", DemoButtonEntity);
8 changes: 6 additions & 2 deletions gallery/src/demos/demo-more-info-light.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { SUPPORT_BRIGHTNESS } from "../../../src/data/light";
import { getEntity } from "../../../src/fake_data/entity";
import { provideHass } from "../../../src/fake_data/provide_hass";
import "../components/demo-more-infos";
import "../components/more-info-content";
import "../../../src/dialogs/more-info/more-info-content";

const ENTITIES = [
getEntity("light", "bed_light", "on", {
Expand Down Expand Up @@ -40,8 +40,12 @@ class DemoMoreInfoLight extends PolymerElement {

public ready() {
super.ready();
this._setupDemo();
}

private async _setupDemo() {
const hass = provideHass(this);
hass.updateTranslations(null, "en");
await hass.updateTranslations(null, "en");
hass.addEntities(ENTITIES);
}
}
Expand Down
31 changes: 6 additions & 25 deletions src/dialogs/more-info/ha-more-info-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@ import {
DOMAINS_MORE_INFO_NO_HISTORY,
DOMAINS_WITH_MORE_INFO,
} from "../../common/const";
import { dynamicElement } from "../../common/dom/dynamic-element-directive";
import { fireEvent } from "../../common/dom/fire_event";
import { computeDomain } from "../../common/entity/compute_domain";
import { computeStateName } from "../../common/entity/compute_state_name";
import {
stateMoreInfoType,
importMoreInfoControl,
} from "./state_more_info_control";

import { navigate } from "../../common/navigate";
import "../../components/ha-dialog";
import "../../components/ha-header-bar";
Expand All @@ -39,6 +35,7 @@ import "./ha-more-info-history";
import "./ha-more-info-logbook";
import "./controls/more-info-default";
import { CONTINUOUS_DOMAINS } from "../../data/logbook";
import "./more-info-content";

const DOMAINS_NO_INFO = ["camera", "configurator"];
/**
Expand All @@ -63,8 +60,6 @@ export class MoreInfoDialog extends LitElement {

@internalProperty() private _entityId?: string | null;

@internalProperty() private _moreInfoType?: string;

@internalProperty() private _currTabIndex = 0;

public showDialog(params: MoreInfoDialogParams) {
Expand All @@ -74,18 +69,6 @@ export class MoreInfoDialog extends LitElement {
return;
}
this.large = false;

const stateObj = this.hass.states[this._entityId];
if (!stateObj) {
return;
}
if (stateObj.attributes && "custom_ui_more_info" in stateObj.attributes) {
this._moreInfoType = stateObj.attributes.custom_ui_more_info;
} else {
const type = stateMoreInfoType(stateObj);
importMoreInfoControl(type);
this._moreInfoType = type === "hidden" ? undefined : `more-info-${type}`;
}
}

public closeDialog() {
Expand Down Expand Up @@ -218,12 +201,10 @@ export class MoreInfoDialog extends LitElement {
.hass=${this.hass}
.entityId=${this._entityId}
></ha-more-info-logbook>`}
${this._moreInfoType
? dynamicElement(this._moreInfoType, {
hass: this.hass,
stateObj,
})
: ""}
<more-info-content
.stateObj=${stateObj}
.hass=${this.hass}
></more-info-content>
${stateObj.attributes.restored
? html`
<p>
Expand Down
57 changes: 57 additions & 0 deletions src/dialogs/more-info/more-info-content.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { HassEntity } from "home-assistant-js-websocket";
import { property, PropertyValues, UpdatingElement } from "lit-element";

import { HomeAssistant } from "../../types";
import dynamicContentUpdater from "../../common/dom/dynamic_content_updater";
import { stateMoreInfoType } from "./state_more_info_control";
import { importMoreInfoControl } from "../../panels/lovelace/custom-card-helpers";

class MoreInfoContent extends UpdatingElement {
@property({ attribute: false }) public hass?: HomeAssistant;

@property() public stateObj?: HassEntity;

private _detachedChild?: ChildNode;

// This is not a lit element, but an updating element, so we implement update
protected update(changedProps: PropertyValues): void {
super.update(changedProps);
const stateObj = this.stateObj;
const hass = this.hass;

if (!stateObj || !hass) {
if (this.lastChild) {
this._detachedChild = this.lastChild;
// Detach child to prevent it from doing work.
this.removeChild(this.lastChild);
}
return;
}

if (this._detachedChild) {
this.appendChild(this._detachedChild);
this._detachedChild = undefined;
}

let moreInfoType: string | undefined;

if (stateObj.attributes && "custom_ui_more_info" in stateObj.attributes) {
moreInfoType = stateObj.attributes.custom_ui_more_info;
} else {
const type = stateMoreInfoType(stateObj);
importMoreInfoControl(type);
moreInfoType = type === "hidden" ? undefined : `more-info-${type}`;
}

if (!moreInfoType) {
return;
}

dynamicContentUpdater(this, moreInfoType.toUpperCase(), {
hass,
stateObj,
});
}
}

customElements.define("more-info-content", MoreInfoContent);
Loading