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
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class DemoAlarmPanelEntity extends PolymerElement {
};
}

ready() {
public ready() {
super.ready();
const hass = provideHass(this.$.demos);
hass.addEntities(ENTITIES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class DemoConditional extends PolymerElement {
};
}

ready() {
public ready() {
super.ready();
const hass = provideHass(this.$.demos);
hass.addEntities(ENTITIES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class DemoEntities extends PolymerElement {
};
}

ready() {
public ready() {
super.ready();
const hass = provideHass(this.$.demos);
hass.addEntities(ENTITIES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class DemoEntityButtonEntity extends PolymerElement {
};
}

ready() {
public ready() {
super.ready();
const hass = provideHass(this.$.demos);
hass.addEntities(ENTITIES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class DemoFilter extends PolymerElement {
};
}

ready() {
public ready() {
super.ready();
const hass = provideHass(this.$.demos);
hass.addEntities(ENTITIES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ class DemoPicEntity extends PolymerElement {
};
}

ready() {
public ready() {
super.ready();
const hass = provideHass(this.$.demos);
hass.addEntities(ENTITIES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class DemoLightEntity extends PolymerElement {
};
}

ready() {
public ready() {
super.ready();
const hass = provideHass(this.$.demos);
hass.addEntities(ENTITIES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class DemoMap extends PolymerElement {
};
}

ready() {
public ready() {
super.ready();
const hass = provideHass(this.$.demos);
hass.addEntities(ENTITIES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class DemoHuiMediaPlayerRows extends PolymerElement {
};
}

ready() {
public ready() {
super.ready();
const hass = provideHass(this.$.demos);
hass.addEntities(ENTITIES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class DemoPicElements extends PolymerElement {
};
}

ready() {
public ready() {
super.ready();
const hass = provideHass(this.$.demos);
hass.addEntities(ENTITIES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class DemoShoppingListEntity extends PolymerElement {
};
}

ready() {
public ready() {
super.ready();
const hass = provideHass(this.$.demos);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class DemoStack extends PolymerElement {
};
}

ready() {
public ready() {
super.ready();
const hass = provideHass(this.$.demos);
hass.addEntities(ENTITIES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class DemoThermostatEntity extends PolymerElement {
};
}

ready() {
public ready() {
super.ready();
const hass = provideHass(this.$.demos);
hass.addEntities(ENTITIES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,7 @@ import getEntity from "../data/entity";
import provideHass from "../data/provide_hass";

import "../components/demo-more-infos";

/* eslint-disable no-unused-vars */

const SUPPORT_BRIGHTNESS = 1;
const SUPPORT_COLOR_TEMP = 2;
const SUPPORT_EFFECT = 4;
const SUPPORT_FLASH = 8;
const SUPPORT_COLOR = 16;
const SUPPORT_TRANSITION = 32;
const SUPPORT_WHITE_VALUE = 128;
import { SUPPORT_BRIGHTNESS } from "../../../src/data/light";

const ENTITIES = [
getEntity("light", "bed_light", "on", {
Expand Down Expand Up @@ -49,7 +40,7 @@ class DemoMoreInfoLight extends PolymerElement {
};
}

ready() {
public ready() {
super.ready();
const hass = provideHass(this);
hass.addEntities(ENTITIES);
Expand Down
79 changes: 79 additions & 0 deletions gallery/src/demos/demo-util-long-press.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { html, LitElement } from "@polymer/lit-element";
import { TemplateResult } from "lit-html";
import "@polymer/paper-button/paper-button";

import "../../../src/components/ha-card";
import { longPress } from "../../../src/panels/lovelace/common/directives/long-press-directive";

export class DemoUtilLongPress extends LitElement {
public render(): TemplateResult {
return html`
${this.renderStyle()}
${
[1, 2, 3].map(
() => html`
<ha-card>
<paper-button
@ha-click="${this._handleTap}"
@ha-hold="${this._handleHold}"
.longPress="${longPress()}"
>
(long) press me!
</paper-button>

<textarea></textarea>

<div>(try pressing and scrolling too!)</div>
</ha-card>
`
)
}
`;
}

private _handleTap(ev: Event) {
this._addValue(ev, "tap");
}

private _handleHold(ev: Event) {
this._addValue(ev, "hold");
}

private _addValue(ev: Event, value: string) {
const area = (ev.currentTarget as HTMLElement)
.nextElementSibling! as HTMLTextAreaElement;
const now = new Date().toTimeString().split(" ")[0];
area.value += `${now}: ${value}\n`;
area.scrollTop = area.scrollHeight;
}

private renderStyle() {
return html`
<style>
ha-card {
width: 200px;
margin: calc(42vh - 140px) auto;
padding: 8px;
text-align: center;
}
ha-card:first-of-type {
margin-top: 16px;
}
ha-card:last-of-type {
margin-bottom: 16px;
}

paper-button {
font-weight: bold;
color: var(--primary-color);
}

textarea {
height: 50px;
}
</style>
`;
}
}

customElements.define("demo-util-long-press", DemoUtilLongPress);
28 changes: 26 additions & 2 deletions gallery/src/ha-gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { PolymerElement } from "@polymer/polymer/polymer-element";

import "../../src/managers/notification-manager";

const DEMOS = require.context("./demos", true, /^(.*\.(js$))[^.]*$/im);
const DEMOS = require.context("./demos", true, /^(.*\.(ts$))[^.]*$/im);

const fixPath = (path) => path.substr(2, path.length - 5);

Expand Down Expand Up @@ -118,6 +118,22 @@ class HaGallery extends PolymerElement {
</a>
</template>
</paper-card>

<paper-card heading="Util demos">
<div class='card-content intro'>
<p>
Test pages for our utility functions.
</p>
</div>
<template is='dom-repeat' items='[[_utilDemos]]'>
<a href='#[[item]]'>
<paper-item>
<paper-item-body>{{ item }}</paper-item-body>
<iron-icon icon="hass:chevron-right"></iron-icon>
</paper-item>
</a>
</template>
</paper-card>
</div>
</template>
</div>
Expand Down Expand Up @@ -145,6 +161,10 @@ class HaGallery extends PolymerElement {
type: Array,
computed: "_computeMoreInfos(_demos)",
},
_utilDemos: {
type: Array,
computed: "_computeUtil(_demos)",
},
};
}

Expand Down Expand Up @@ -178,7 +198,7 @@ class HaGallery extends PolymerElement {
while (root.lastChild) root.removeChild(root.lastChild);

if (demo) {
DEMOS(`./${demo}.js`);
DEMOS(`./${demo}.ts`);
const el = document.createElement(demo);
root.appendChild(el);
}
Expand All @@ -199,6 +219,10 @@ class HaGallery extends PolymerElement {
_computeMoreInfos(demos) {
return demos.filter((demo) => demo.includes("more-info"));
}

_computeUtil(demos) {
return demos.filter((demo) => demo.includes("util"));
}
}

customElements.define("ha-gallery", HaGallery);
7 changes: 7 additions & 0 deletions src/data/light.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const SUPPORT_BRIGHTNESS = 1;
export const SUPPORT_COLOR_TEMP = 2;
export const SUPPORT_EFFECT = 4;
export const SUPPORT_FLASH = 8;
export const SUPPORT_COLOR = 16;
export const SUPPORT_TRANSITION = 32;
export const SUPPORT_WHITE_VALUE = 128;