diff --git a/gallery/src/demos/demo-hui-alarm-panel-card.js b/gallery/src/demos/demo-hui-alarm-panel-card.ts similarity index 98% rename from gallery/src/demos/demo-hui-alarm-panel-card.js rename to gallery/src/demos/demo-hui-alarm-panel-card.ts index fb943186d6..11feab3b9a 100644 --- a/gallery/src/demos/demo-hui-alarm-panel-card.js +++ b/gallery/src/demos/demo-hui-alarm-panel-card.ts @@ -69,7 +69,7 @@ class DemoAlarmPanelEntity extends PolymerElement { }; } - ready() { + public ready() { super.ready(); const hass = provideHass(this.$.demos); hass.addEntities(ENTITIES); diff --git a/gallery/src/demos/demo-hui-conditional-card.js b/gallery/src/demos/demo-hui-conditional-card.ts similarity index 98% rename from gallery/src/demos/demo-hui-conditional-card.js rename to gallery/src/demos/demo-hui-conditional-card.ts index c3dc1193eb..6a774061ac 100644 --- a/gallery/src/demos/demo-hui-conditional-card.js +++ b/gallery/src/demos/demo-hui-conditional-card.ts @@ -74,7 +74,7 @@ class DemoConditional extends PolymerElement { }; } - ready() { + public ready() { super.ready(); const hass = provideHass(this.$.demos); hass.addEntities(ENTITIES); diff --git a/gallery/src/demos/demo-hui-entities-card.js b/gallery/src/demos/demo-hui-entities-card.ts similarity index 99% rename from gallery/src/demos/demo-hui-entities-card.js rename to gallery/src/demos/demo-hui-entities-card.ts index 006df1653f..32f137d6e1 100644 --- a/gallery/src/demos/demo-hui-entities-card.js +++ b/gallery/src/demos/demo-hui-entities-card.ts @@ -188,7 +188,7 @@ class DemoEntities extends PolymerElement { }; } - ready() { + public ready() { super.ready(); const hass = provideHass(this.$.demos); hass.addEntities(ENTITIES); diff --git a/gallery/src/demos/demo-hui-entity-button-card.js b/gallery/src/demos/demo-hui-entity-button-card.ts similarity index 98% rename from gallery/src/demos/demo-hui-entity-button-card.js rename to gallery/src/demos/demo-hui-entity-button-card.ts index d88627121a..1b201734a4 100644 --- a/gallery/src/demos/demo-hui-entity-button-card.js +++ b/gallery/src/demos/demo-hui-entity-button-card.ts @@ -89,7 +89,7 @@ class DemoEntityButtonEntity extends PolymerElement { }; } - ready() { + public ready() { super.ready(); const hass = provideHass(this.$.demos); hass.addEntities(ENTITIES); diff --git a/gallery/src/demos/demo-hui-entity-filter-card.js b/gallery/src/demos/demo-hui-entity-filter-card.ts similarity index 99% rename from gallery/src/demos/demo-hui-entity-filter-card.js rename to gallery/src/demos/demo-hui-entity-filter-card.ts index 92d8731ff6..3f8f07ce99 100644 --- a/gallery/src/demos/demo-hui-entity-filter-card.js +++ b/gallery/src/demos/demo-hui-entity-filter-card.ts @@ -105,7 +105,7 @@ class DemoFilter extends PolymerElement { }; } - ready() { + public ready() { super.ready(); const hass = provideHass(this.$.demos); hass.addEntities(ENTITIES); diff --git a/gallery/src/demos/demo-hui-gauge-card.js b/gallery/src/demos/demo-hui-gauge-card.ts similarity index 100% rename from gallery/src/demos/demo-hui-gauge-card.js rename to gallery/src/demos/demo-hui-gauge-card.ts diff --git a/gallery/src/demos/demo-hui-glance-card.js b/gallery/src/demos/demo-hui-glance-card.ts similarity index 99% rename from gallery/src/demos/demo-hui-glance-card.js rename to gallery/src/demos/demo-hui-glance-card.ts index d0ff3abf6f..844b7c4656 100644 --- a/gallery/src/demos/demo-hui-glance-card.js +++ b/gallery/src/demos/demo-hui-glance-card.ts @@ -230,7 +230,7 @@ class DemoPicEntity extends PolymerElement { }; } - ready() { + public ready() { super.ready(); const hass = provideHass(this.$.demos); hass.addEntities(ENTITIES); diff --git a/gallery/src/demos/demo-hui-iframe-card.js b/gallery/src/demos/demo-hui-iframe-card.ts similarity index 100% rename from gallery/src/demos/demo-hui-iframe-card.js rename to gallery/src/demos/demo-hui-iframe-card.ts diff --git a/gallery/src/demos/demo-hui-light-card.js b/gallery/src/demos/demo-hui-light-card.ts similarity index 98% rename from gallery/src/demos/demo-hui-light-card.js rename to gallery/src/demos/demo-hui-light-card.ts index a2d359565d..642f095da6 100644 --- a/gallery/src/demos/demo-hui-light-card.js +++ b/gallery/src/demos/demo-hui-light-card.ts @@ -38,7 +38,7 @@ class DemoLightEntity extends PolymerElement { }; } - ready() { + public ready() { super.ready(); const hass = provideHass(this.$.demos); hass.addEntities(ENTITIES); diff --git a/gallery/src/demos/demo-hui-map-card.js b/gallery/src/demos/demo-hui-map-card.ts similarity index 99% rename from gallery/src/demos/demo-hui-map-card.js rename to gallery/src/demos/demo-hui-map-card.ts index ec6890b2aa..a402d80024 100644 --- a/gallery/src/demos/demo-hui-map-card.js +++ b/gallery/src/demos/demo-hui-map-card.ts @@ -139,7 +139,7 @@ class DemoMap extends PolymerElement { }; } - ready() { + public ready() { super.ready(); const hass = provideHass(this.$.demos); hass.addEntities(ENTITIES); diff --git a/gallery/src/demos/demo-hui-markdown-card.js b/gallery/src/demos/demo-hui-markdown-card.ts similarity index 100% rename from gallery/src/demos/demo-hui-markdown-card.js rename to gallery/src/demos/demo-hui-markdown-card.ts diff --git a/gallery/src/demos/demo-hui-media-player-rows.js b/gallery/src/demos/demo-hui-media-player-rows.ts similarity index 99% rename from gallery/src/demos/demo-hui-media-player-rows.js rename to gallery/src/demos/demo-hui-media-player-rows.ts index d3f2e00700..e657881915 100644 --- a/gallery/src/demos/demo-hui-media-player-rows.js +++ b/gallery/src/demos/demo-hui-media-player-rows.ts @@ -95,7 +95,7 @@ class DemoHuiMediaPlayerRows extends PolymerElement { }; } - ready() { + public ready() { super.ready(); const hass = provideHass(this.$.demos); hass.addEntities(ENTITIES); diff --git a/gallery/src/demos/demo-hui-picture-elements-card.js b/gallery/src/demos/demo-hui-picture-elements-card.ts similarity index 99% rename from gallery/src/demos/demo-hui-picture-elements-card.js rename to gallery/src/demos/demo-hui-picture-elements-card.ts index 9f5ebe90e0..53cb27f585 100644 --- a/gallery/src/demos/demo-hui-picture-elements-card.js +++ b/gallery/src/demos/demo-hui-picture-elements-card.ts @@ -93,7 +93,7 @@ class DemoPicElements extends PolymerElement { }; } - ready() { + public ready() { super.ready(); const hass = provideHass(this.$.demos); hass.addEntities(ENTITIES); diff --git a/gallery/src/demos/demo-hui-picture-entity-card.js b/gallery/src/demos/demo-hui-picture-entity-card.ts similarity index 100% rename from gallery/src/demos/demo-hui-picture-entity-card.js rename to gallery/src/demos/demo-hui-picture-entity-card.ts diff --git a/gallery/src/demos/demo-hui-picture-glance-card.js b/gallery/src/demos/demo-hui-picture-glance-card.ts similarity index 100% rename from gallery/src/demos/demo-hui-picture-glance-card.js rename to gallery/src/demos/demo-hui-picture-glance-card.ts diff --git a/gallery/src/demos/demo-hui-shopping-list-card.js b/gallery/src/demos/demo-hui-shopping-list-card.ts similarity index 98% rename from gallery/src/demos/demo-hui-shopping-list-card.js rename to gallery/src/demos/demo-hui-shopping-list-card.ts index d79e2f839d..b290bd7e9b 100644 --- a/gallery/src/demos/demo-hui-shopping-list-card.js +++ b/gallery/src/demos/demo-hui-shopping-list-card.ts @@ -36,7 +36,7 @@ class DemoShoppingListEntity extends PolymerElement { }; } - ready() { + public ready() { super.ready(); const hass = provideHass(this.$.demos); diff --git a/gallery/src/demos/demo-hui-stack-card.js b/gallery/src/demos/demo-hui-stack-card.ts similarity index 99% rename from gallery/src/demos/demo-hui-stack-card.js rename to gallery/src/demos/demo-hui-stack-card.ts index 1dce40ecfa..257d753d4a 100644 --- a/gallery/src/demos/demo-hui-stack-card.js +++ b/gallery/src/demos/demo-hui-stack-card.ts @@ -104,7 +104,7 @@ class DemoStack extends PolymerElement { }; } - ready() { + public ready() { super.ready(); const hass = provideHass(this.$.demos); hass.addEntities(ENTITIES); diff --git a/gallery/src/demos/demo-hui-thermostat-card.js b/gallery/src/demos/demo-hui-thermostat-card.ts similarity index 99% rename from gallery/src/demos/demo-hui-thermostat-card.js rename to gallery/src/demos/demo-hui-thermostat-card.ts index cbc667c874..740f8c9471 100644 --- a/gallery/src/demos/demo-hui-thermostat-card.js +++ b/gallery/src/demos/demo-hui-thermostat-card.ts @@ -75,7 +75,7 @@ class DemoThermostatEntity extends PolymerElement { }; } - ready() { + public ready() { super.ready(); const hass = provideHass(this.$.demos); hass.addEntities(ENTITIES); diff --git a/gallery/src/demos/demo-more-info-light.js b/gallery/src/demos/demo-more-info-light.ts similarity index 82% rename from gallery/src/demos/demo-more-info-light.js rename to gallery/src/demos/demo-more-info-light.ts index 25708dd584..88a5cf7d6b 100644 --- a/gallery/src/demos/demo-more-info-light.js +++ b/gallery/src/demos/demo-more-info-light.ts @@ -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", { @@ -49,7 +40,7 @@ class DemoMoreInfoLight extends PolymerElement { }; } - ready() { + public ready() { super.ready(); const hass = provideHass(this); hass.addEntities(ENTITIES); diff --git a/gallery/src/demos/demo-util-long-press.ts b/gallery/src/demos/demo-util-long-press.ts new file mode 100644 index 0000000000..9e790fed50 --- /dev/null +++ b/gallery/src/demos/demo-util-long-press.ts @@ -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` + + + (long) press me! + + + + +
(try pressing and scrolling too!)
+
+ ` + ) + } + `; + } + + 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` + + `; + } +} + +customElements.define("demo-util-long-press", DemoUtilLongPress); diff --git a/gallery/src/ha-gallery.js b/gallery/src/ha-gallery.js index 73c3e666d6..08af976940 100644 --- a/gallery/src/ha-gallery.js +++ b/gallery/src/ha-gallery.js @@ -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); @@ -118,6 +118,22 @@ class HaGallery extends PolymerElement { + + +
+

+ Test pages for our utility functions. +

+
+ +
@@ -145,6 +161,10 @@ class HaGallery extends PolymerElement { type: Array, computed: "_computeMoreInfos(_demos)", }, + _utilDemos: { + type: Array, + computed: "_computeUtil(_demos)", + }, }; } @@ -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); } @@ -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); diff --git a/src/data/light.ts b/src/data/light.ts new file mode 100644 index 0000000000..8d0a701d29 --- /dev/null +++ b/src/data/light.ts @@ -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;