From 601bbfd88ededc385d286be5a74aa46208eba05f Mon Sep 17 00:00:00 2001 From: Zack Arnett Date: Thu, 6 Dec 2018 13:17:41 -0500 Subject: [PATCH] Light Tap/Hold Action fix (#2191) * Light action fix * oops copy pasta --- src/panels/lovelace/cards/hui-light-card.ts | 30 +++++++++------------ 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/panels/lovelace/cards/hui-light-card.ts b/src/panels/lovelace/cards/hui-light-card.ts index 9720f7ecd4..b161d8bb59 100644 --- a/src/panels/lovelace/cards/hui-light-card.ts +++ b/src/panels/lovelace/cards/hui-light-card.ts @@ -13,15 +13,16 @@ import { hassLocalizeLitMixin } from "../../../mixins/lit-localize-mixin"; import { LovelaceCard } from "../types"; import { LovelaceCardConfig } from "../../../data/lovelace"; import { longPress } from "../common/directives/long-press-directive"; +import { hasConfigOrEntityChanged } from "../common/has-changed"; +import { loadRoundslider } from "../../../resources/jquery.roundslider.ondemand"; +import { toggleEntity } from "../common/entity/toggle-entity"; import stateIcon from "../../../common/entity/state_icon"; import computeStateName from "../../../common/entity/compute_state_name"; import applyThemesOnElement from "../../../common/dom/apply_themes_on_element"; -import { hasConfigOrEntityChanged } from "../common/has-changed"; import "../../../components/ha-card"; import "../../../components/ha-icon"; -import { loadRoundslider } from "../../../resources/jquery.roundslider.ondemand"; const lightConfig = { radius: 80, @@ -102,14 +103,14 @@ export class HuiLightCard extends hassLocalizeLitMixin(LitElement) color: this._computeColor(stateObj), }) }" - @ha-click="${() => this._handleClick(false)}" - @ha-hold="${() => this._handleClick(true)}" + @ha-click="${this._handleTap}" + @ha-hold="${this._handleHold}" .longPress="${longPress()}" >
@@ -319,18 +320,13 @@ export class HuiLightCard extends hassLocalizeLitMixin(LitElement) return `hsl(${hue}, 100%, ${100 - sat / 2}%)`; } - private _handleClick(hold: boolean): void { - const entityId = this._config!.entity; + private _handleTap() { + toggleEntity(this.hass!, this._config!.entity!); + } - if (hold) { - fireEvent(this, "hass-more-info", { - entityId, - }); - return; - } - - this.hass!.callService("light", "toggle", { - entity_id: entityId, + private _handleHold() { + fireEvent(this, "hass-more-info", { + entityId: this._config!.entity, }); } }