Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 11 additions & 6 deletions src/components/entity/ha-state-label-badge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export class HaStateLabelBadge extends LitElement {

@property() public image?: string;

@property() public handleClick?: boolean;
Comment thread
iantrich marked this conversation as resolved.
Outdated

@property() private _timerTimeRemaining?: number;

private _connected?: boolean;
Expand Down Expand Up @@ -92,12 +94,15 @@ export class HaStateLabelBadge extends LitElement {

protected firstUpdated(changedProperties: PropertyValues): void {
super.firstUpdated(changedProperties);
this.addEventListener("click", (ev) => {
ev.stopPropagation();
if (this.state) {
fireEvent(this, "hass-more-info", { entityId: this.state.entity_id });
}
});

if (this.handleClick !== false) {
Comment thread
iantrich marked this conversation as resolved.
Outdated
this.addEventListener("click", (ev) => {
ev.stopPropagation();
if (this.state) {
fireEvent(this, "hass-more-info", { entityId: this.state.entity_id });
}
});
}
}

protected updated(changedProperties: PropertyValues): void {
Expand Down
22 changes: 22 additions & 0 deletions src/panels/lovelace/elements/hui-state-badge-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import { computeStateName } from "../../../common/entity/compute_state_name";
import { LovelaceElement, StateBadgeElementConfig } from "./types";
import { HomeAssistant } from "../../../types";
import { hasConfigOrEntityChanged } from "../common/has-changed";
import { longPress } from "../common/directives/long-press-directive";
import { hasDoubleClick } from "../common/has-double-click";
import { handleClick } from "../common/handle-click";

@customElement("hui-state-badge-element")
export class HuiStateBadgeElement extends LitElement
Expand Down Expand Up @@ -61,9 +64,28 @@ export class HuiStateBadgeElement extends LitElement
: this._config.title === null
? ""
: this._config.title}"
@ha-click=${this._handleClick}
@ha-hold=${this._handleHold}
@ha-dblclick=${this._handleDblClick}
.longPress=${longPress({
hasDoubleClick: hasDoubleClick(this._config!.double_tap_action),
})}
.handleClick=${false}
Comment thread
iantrich marked this conversation as resolved.
Outdated
></ha-state-label-badge>
`;
}

private _handleClick() {
handleClick(this, this.hass!, this._config!, false, false);
}

private _handleHold() {
handleClick(this, this.hass!, this._config!, true, false);
}

private _handleDblClick() {
handleClick(this, this.hass!, this._config!, false, true);
}
}

declare global {
Expand Down
1 change: 0 additions & 1 deletion src/panels/lovelace/elements/hui-state-label-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
PropertyValues,
} from "lit-element";

import "../../../components/entity/ha-state-label-badge";
import "../components/hui-warning-element";

import { computeStateDisplay } from "../../../common/entity/compute_state_display";
Expand Down
3 changes: 3 additions & 0 deletions src/panels/lovelace/elements/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ export interface ServiceButtonElementConfig extends LovelaceElementConfig {
export interface StateBadgeElementConfig extends LovelaceElementConfig {
entity: string;
title?: string;
tap_action?: ActionConfig;
hold_action?: ActionConfig;
double_tap_action?: ActionConfig;
}

export interface StateIconElementConfig extends LovelaceElementConfig {
Expand Down