Skip to content

Commit

Permalink
Merge pull request #109 from ikaruswill/fix-tap-handling
Browse files Browse the repository at this point in the history
Remove action handler which was conflicting with tap handling
  • Loading branch information
ikaruswill authored Jul 24, 2022
2 parents 3f2428a + cd42744 commit d805977
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions src/xiaomi-fan-card.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { LitElement, html, TemplateResult, css, PropertyValues, CSSResultGroup, HTMLTemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators";
import {
HomeAssistant,
hasConfigOrEntityChanged,
ActionHandlerEvent,
handleAction,
LovelaceCardEditor,
} from "custom-card-helpers"; // This is a community maintained npm module with common helper functions/types. https://github.com/custom-cards/custom-card-helpers

import { actionHandler } from "./action-handler-directive";
import { HomeAssistant, hasConfigOrEntityChanged, handleAction, LovelaceCardEditor } from "custom-card-helpers"; // This is a community maintained npm module with common helper functions/types. https://github.com/custom-cards/custom-card-helpers

import { FanXiaomiCardConfig, defaultConfig } from "./config";

// Add the card to the UI card picker dialog
Expand Down Expand Up @@ -479,8 +472,7 @@ export class FanXiaomiCard extends LitElement {
return html`
<ha-card
.header=${this.config.name || state?.attributes["friendly_name"] || ""}
@action=${this.handleAction}
.actionHandler=${actionHandler({})}
@click=${this.onCardTitleClick}
tabindex="0"
.label=${`Xiaomi Fan: ${this.config.entity || "No Entity Defined"}`}
>
Expand Down Expand Up @@ -591,10 +583,13 @@ export class FanXiaomiCard extends LitElement {
Speed down
</button>
</div>`
: html`<div class="op var-speed ${(speedLevel > 0 && state.state === "on") ? "active" : ""}" @click=${this.toggleSpeedLevel}>
: html`<div
class="op var-speed ${speedLevel > 0 && state.state === "on" ? "active" : ""}"
@click=${this.toggleSpeedLevel}
>
<button>
<span class="icon-waper">
<ha-icon icon="mdi:numeric-${(state.state === "on") ? speedLevel : 0}-box-outline"></ha-icon>
<ha-icon icon="mdi:numeric-${state.state === "on" ? speedLevel : 0}-box-outline"></ha-icon>
</span>
Speed
</button>
Expand Down Expand Up @@ -644,9 +639,9 @@ export class FanXiaomiCard extends LitElement {
</div>`;
}

private handleAction(ev: ActionHandlerEvent): void {
if (this.hass && this.config && ev.detail.action) {
handleAction(this, this.hass, this.config, ev.detail.action);
private onCardTitleClick(): void {
if (this.hass && this.config) {
handleAction(this, this.hass, this.config, "click");
}
}

Expand Down Expand Up @@ -682,8 +677,14 @@ export class FanXiaomiCard extends LitElement {
private toggleSpeedLevel(): void {
const currentLevel = this.getSpeedLevel();

const newLevel = currentLevel >= this.supportedAttributes.speedLevels ?
(this.config.disable_animation ? (this.hass.states[this.config.entity].state === 'off' ? 1 : 0) : 1) : currentLevel + 1;
const newLevel =
currentLevel >= this.supportedAttributes.speedLevels
? this.config.disable_animation
? this.hass.states[this.config.entity].state === "off"
? 1
: 0
: 1
: currentLevel + 1;
const newPercentage = (newLevel / this.supportedAttributes.speedLevels) * 100;

this.hass.callService("fan", "set_percentage", {
Expand Down

0 comments on commit d805977

Please sign in to comment.