Skip to content
Closed
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
20 changes: 0 additions & 20 deletions src/panels/lovelace/cards/hui-entities-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@ import {
import "../../../components/ha-card";
import "../components/hui-entities-toggle";

import { fireEvent } from "../../../common/dom/fire_event";
import { DOMAINS_HIDE_MORE_INFO } from "../../../common/const";
import { HomeAssistant } from "../../../types";
import { EntityRow } from "../entity-rows/types";
import { LovelaceCard, LovelaceCardEditor } from "../types";
import { processConfigEntities } from "../common/process-config-entities";
import { createRowElement } from "../common/create-row-element";
import { EntitiesCardConfig, EntitiesCardEntityConfig } from "./types";

import { computeDomain } from "../../../common/entity/compute_domain";
import applyThemesOnElement from "../../../common/dom/apply_themes_on_element";

@customElement("hui-entities-card")
Expand Down Expand Up @@ -136,10 +132,6 @@ class HuiEntitiesCard extends LitElement implements LovelaceCard {
#states > div > * {
overflow: hidden;
}

.state-card-dialog {
cursor: pointer;
}
`;
}

Expand All @@ -148,23 +140,11 @@ class HuiEntitiesCard extends LitElement implements LovelaceCard {
if (this._hass) {
element.hass = this._hass;
}
if (
entityConf.entity &&
!DOMAINS_HIDE_MORE_INFO.includes(computeDomain(entityConf.entity))
) {
element.classList.add("state-card-dialog");
element.addEventListener("click", () => this._handleClick(entityConf));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now changed the behaviour of all entity rows? You can no longer click on the row to get the more-info?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved actions to the badge

}

return html`
<div>${element}</div>
`;
}

private _handleClick(entityConf: EntitiesCardEntityConfig): void {
const entityId = entityConf.entity;
fireEvent(this, "hass-more-info", { entityId });
}
}

declare global {
Expand Down
2 changes: 2 additions & 0 deletions src/panels/lovelace/cards/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export interface EntitiesCardEntityConfig extends EntityConfig {
service?: string;
service_data?: object;
url?: string;
tap_action?: ActionConfig;
hold_action?: ActionConfig;
}

export interface EntitiesCardConfig extends LovelaceCardConfig {
Expand Down
23 changes: 23 additions & 0 deletions src/panels/lovelace/components/hui-generic-entity-row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import { HomeAssistant } from "../../../types";
import { computeRTL } from "../../../common/util/compute_rtl";
import { EntitiesCardEntityConfig } from "../cards/types";
import { toggleAttribute } from "../../../common/dom/toggle_attribute";
import { longPress } from "../common/directives/long-press-directive";
import { handleClick } from "../common/handle-click";
import { classMap } from "lit-html/directives/class-map";

class HuiGenericEntityRow extends LitElement {
@property() public hass?: HomeAssistant;
Expand Down Expand Up @@ -48,10 +51,19 @@ class HuiGenericEntityRow extends LitElement {

return html`
<state-badge
class=${classMap({
pointer:
!this.config.tap_action ||
(this.config.tap_action &&
this.config.tap_action.action !== "none"),
})}
.hass=${this.hass}
.stateObj=${stateObj}
.overrideIcon=${this.config.icon}
.overrideImage=${this.config.image}
@ha-click=${this._handleTap}
@ha-hold=${this._handleHold}
.longPress=${longPress()}
></state-badge>
<div class="flex">
<div class="info">
Expand Down Expand Up @@ -86,6 +98,14 @@ class HuiGenericEntityRow extends LitElement {
}
}

private _handleTap() {
handleClick(this, this.hass!, this.config!, false);
}

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

static get styles(): CSSResult {
return css`
:host {
Expand Down Expand Up @@ -132,6 +152,9 @@ class HuiGenericEntityRow extends LitElement {
margin-left: 0;
margin-right: 8px;
}
.pointer {
cursor: pointer;
}
`;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/panels/lovelace/editor/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export const entitiesConfigStruct = struct.union([
entity: "entity-id",
name: "string?",
icon: "icon?",
tap_action: struct.optional(actionConfigStruct),
hold_action: struct.optional(actionConfigStruct),
},
"entity-id",
]);
19 changes: 17 additions & 2 deletions src/panels/lovelace/entity-rows/hui-input-select-entity-row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ import "@polymer/paper-listbox/paper-listbox";
import "../../../components/ha-paper-dropdown-menu";
import "../../../components/entity/state-badge";
import "../components/hui-warning";
import "../components/hui-generic-entity-row";

import { computeStateName } from "../../../common/entity/compute_state_name";

import { HomeAssistant, InputSelectEntity } from "../../../types";
import { EntityRow, EntityConfig } from "./types";
import { setInputSelectOption } from "../../../data/input-select";
import { hasConfigOrEntityChanged } from "../common/has-changed";
import { forwardHaptic } from "../../../data/haptics";
import { stopPropagation } from "../../../common/dom/stop_propagation";
import { longPress } from "../common/directives/long-press-directive";
import { handleClick } from "../common/handle-click";

@customElement("hui-input-select-entity-row")
class HuiInputSelectEntityRow extends LitElement implements EntityRow {
Expand Down Expand Up @@ -64,7 +66,12 @@ class HuiInputSelectEntityRow extends LitElement implements EntityRow {
}

return html`
<state-badge .stateObj="${stateObj}"></state-badge>
<state-badge
@ha-click="${this._handleTap}"
@ha-hold="${this._handleHold}"
.longPress="${longPress()}"
.stateObj="${stateObj}"
></state-badge>
<ha-paper-dropdown-menu
.label=${this._config.name || computeStateName(stateObj)}
.value=${stateObj.state}
Expand Down Expand Up @@ -132,6 +139,14 @@ class HuiInputSelectEntityRow extends LitElement implements EntityRow {

setInputSelectOption(this.hass!, stateObj.entity_id, option);
}

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

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

declare global {
Expand Down