Use switch for valve in entity row (#19342)

This commit is contained in:
Paul Bottein 2024-01-09 16:15:33 +01:00 committed by GitHub
parent e8c1a34f3b
commit a5630a4a7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 24 deletions

View File

@ -129,6 +129,9 @@ export class HaEntityToggle extends LitElement {
} else if (stateDomain === "cover") {
serviceDomain = "cover";
service = turnOn ? "open_cover" : "close_cover";
} else if (stateDomain === "valve") {
serviceDomain = "valve";
service = turnOn ? "open_valve" : "close_valve";
} else if (stateDomain === "group") {
serviceDomain = "homeassistant";
service = turnOn ? "turn_on" : "turn_off";

View File

@ -1,14 +1,7 @@
import {
css,
CSSResultGroup,
html,
LitElement,
PropertyValues,
nothing,
} from "lit";
import { LitElement, PropertyValues, html, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
import "../../../components/ha-valve-controls";
import { ValveEntity } from "../../../data/valve";
import { isUnavailableState } from "../../../data/entity";
import { HomeAssistant } from "../../../types";
import { hasConfigOrEntityChanged } from "../common/has-changed";
import "../components/hui-generic-entity-row";
@ -37,7 +30,7 @@ class HuiValveEntityRow extends LitElement implements LovelaceRow {
return nothing;
}
const stateObj = this.hass.states[this._config.entity] as ValveEntity;
const stateObj = this.hass.states[this._config.entity];
if (!stateObj) {
return html`
@ -47,21 +40,30 @@ class HuiValveEntityRow extends LitElement implements LovelaceRow {
`;
}
return html`
<hui-generic-entity-row .hass=${this.hass} .config=${this._config}>
<ha-valve-controls
.hass=${this.hass}
.stateObj=${stateObj}
></ha-valve-controls>
</hui-generic-entity-row>
`;
}
const showToggle =
stateObj.state === "open" ||
stateObj.state === "closed" ||
isUnavailableState(stateObj.state);
static get styles(): CSSResultGroup {
return css`
ha-valve-controls {
margin-right: -0.57em;
}
return html`
<hui-generic-entity-row
.hass=${this.hass}
.config=${this._config}
.catchInteraction=${!showToggle}
>
${showToggle
? html`
<ha-entity-toggle
.hass=${this.hass}
.stateObj=${stateObj}
></ha-entity-toggle>
`
: html`
<div class="text-content">
${this.hass.formatEntityState(stateObj)}
</div>
`}
</hui-generic-entity-row>
`;
}
}