mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 09:46:36 +00:00
Use switch for valve in entity row (#19342)
This commit is contained in:
parent
e8c1a34f3b
commit
a5630a4a7d
@ -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";
|
||||
|
@ -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>
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user