Skip to content

Commit

Permalink
Remove redundant action handler and wrapper from sensor entity row (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
arthanoss authored Nov 24, 2024
1 parent 536d2e0 commit 1b74e94
Showing 1 changed file with 13 additions and 41 deletions.
54 changes: 13 additions & 41 deletions src/panels/lovelace/entity-rows/hui-sensor-entity-row.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import type { CSSResultGroup, PropertyValues } from "lit";
import { LitElement, css, html, nothing } from "lit";
import type { PropertyValues } from "lit";
import { LitElement, html, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
import { isUnavailableState } from "../../../data/entity";
import type { ActionHandlerEvent } from "../../../data/lovelace/action_handler";
import { SENSOR_DEVICE_CLASS_TIMESTAMP } from "../../../data/sensor";
import type { HomeAssistant } from "../../../types";
import type { EntitiesCardEntityConfig } from "../cards/types";
import { actionHandler } from "../common/directives/action-handler-directive";
import { handleAction } from "../common/handle-action";
import { hasAction } from "../common/has-action";
import { hasConfigOrEntityChanged } from "../common/has-changed";
import "../components/hui-generic-entity-row";
import "../components/hui-timestamp-display";
Expand Down Expand Up @@ -54,44 +50,20 @@ class HuiSensorEntityRow extends LitElement implements LovelaceRow {

return html`
<hui-generic-entity-row .hass=${this.hass} .config=${this._config}>
<div
class="text-content value"
@action=${this._handleAction}
.actionHandler=${actionHandler({
hasHold: hasAction(this._config.hold_action),
hasDoubleClick: hasAction(this._config.double_tap_action),
})}
>
${stateObj.attributes.device_class ===
SENSOR_DEVICE_CLASS_TIMESTAMP && !isUnavailableState(stateObj.state)
? html`
<hui-timestamp-display
.hass=${this.hass}
.ts=${new Date(stateObj.state)}
.format=${this._config.format}
capitalize
></hui-timestamp-display>
`
: this.hass.formatEntityState(stateObj)}
</div>
${stateObj.attributes.device_class === SENSOR_DEVICE_CLASS_TIMESTAMP &&
!isUnavailableState(stateObj.state)
? html`
<hui-timestamp-display
.hass=${this.hass}
.ts=${new Date(stateObj.state)}
.format=${this._config.format}
capitalize
></hui-timestamp-display>
`
: this.hass.formatEntityState(stateObj)}
</hui-generic-entity-row>
`;
}

private _handleAction(ev: ActionHandlerEvent) {
handleAction(this, this.hass!, this._config!, ev.detail.action);
}

static get styles(): CSSResultGroup {
return css`
div {
text-align: right;
}
.value {
direction: ltr;
}
`;
}
}

declare global {
Expand Down

0 comments on commit 1b74e94

Please sign in to comment.