mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-29 20:26:39 +00:00
Make unavailable elements disabled (#5386)
* Make unavailable elements disabled * Unused * Add checks for unknown * Update hui-weather-entity-row.ts
This commit is contained in:
parent
2253275640
commit
ebb20abee0
@ -18,9 +18,12 @@ import { computeStateDomain } from "../../common/entity/compute_state_domain";
|
|||||||
import { computeStateName } from "../../common/entity/compute_state_name";
|
import { computeStateName } from "../../common/entity/compute_state_name";
|
||||||
|
|
||||||
import "../ha-switch";
|
import "../ha-switch";
|
||||||
|
import { UNAVAILABLE_STATES } from "../../data/entity";
|
||||||
|
|
||||||
const isOn = (stateObj?: HassEntity) =>
|
const isOn = (stateObj?: HassEntity) =>
|
||||||
stateObj !== undefined && !STATES_OFF.includes(stateObj.state);
|
stateObj !== undefined &&
|
||||||
|
!STATES_OFF.includes(stateObj.state) &&
|
||||||
|
!UNAVAILABLE_STATES.includes(stateObj.state);
|
||||||
|
|
||||||
class HaEntityToggle extends LitElement {
|
class HaEntityToggle extends LitElement {
|
||||||
// hass is not a property so that we only re-render on stateObj changes
|
// hass is not a property so that we only re-render on stateObj changes
|
||||||
@ -40,12 +43,14 @@ class HaEntityToggle extends LitElement {
|
|||||||
<paper-icon-button
|
<paper-icon-button
|
||||||
aria-label=${`Turn ${computeStateName(this.stateObj)} off`}
|
aria-label=${`Turn ${computeStateName(this.stateObj)} off`}
|
||||||
icon="hass:flash-off"
|
icon="hass:flash-off"
|
||||||
|
.disabled=${UNAVAILABLE_STATES.includes(this.stateObj.state)}
|
||||||
@click=${this._turnOff}
|
@click=${this._turnOff}
|
||||||
?state-active=${!this._isOn}
|
?state-active=${!this._isOn}
|
||||||
></paper-icon-button>
|
></paper-icon-button>
|
||||||
<paper-icon-button
|
<paper-icon-button
|
||||||
aria-label=${`Turn ${computeStateName(this.stateObj)} on`}
|
aria-label=${`Turn ${computeStateName(this.stateObj)} on`}
|
||||||
icon="hass:flash"
|
icon="hass:flash"
|
||||||
|
.disabled=${UNAVAILABLE_STATES.includes(this.stateObj.state)}
|
||||||
@click=${this._turnOn}
|
@click=${this._turnOn}
|
||||||
?state-active=${this._isOn}
|
?state-active=${this._isOn}
|
||||||
></paper-icon-button>
|
></paper-icon-button>
|
||||||
@ -58,6 +63,7 @@ class HaEntityToggle extends LitElement {
|
|||||||
this._isOn ? "off" : "on"
|
this._isOn ? "off" : "on"
|
||||||
}`}
|
}`}
|
||||||
.checked=${this._isOn}
|
.checked=${this._isOn}
|
||||||
|
.disabled=${UNAVAILABLE_STATES.includes(this.stateObj.state)}
|
||||||
@change=${this._toggleChanged}
|
@change=${this._toggleChanged}
|
||||||
></ha-switch>
|
></ha-switch>
|
||||||
`;
|
`;
|
||||||
|
@ -3,6 +3,7 @@ import { html } from "@polymer/polymer/lib/utils/html-tag";
|
|||||||
import { PolymerElement } from "@polymer/polymer/polymer-element";
|
import { PolymerElement } from "@polymer/polymer/polymer-element";
|
||||||
|
|
||||||
import CoverEntity from "../util/cover-model";
|
import CoverEntity from "../util/cover-model";
|
||||||
|
import { UNAVAILABLE_STATES } from "../data/entity";
|
||||||
|
|
||||||
class HaCoverControls extends PolymerElement {
|
class HaCoverControls extends PolymerElement {
|
||||||
static get template() {
|
static get template() {
|
||||||
@ -81,11 +82,17 @@ class HaCoverControls extends PolymerElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
computeOpenDisabled(stateObj, entityObj) {
|
computeOpenDisabled(stateObj, entityObj) {
|
||||||
|
if (UNAVAILABLE_STATES.includes(stateObj.state)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
var assumedState = stateObj.attributes.assumed_state === true;
|
var assumedState = stateObj.attributes.assumed_state === true;
|
||||||
return (entityObj.isFullyOpen || entityObj.isOpening) && !assumedState;
|
return (entityObj.isFullyOpen || entityObj.isOpening) && !assumedState;
|
||||||
}
|
}
|
||||||
|
|
||||||
computeClosedDisabled(stateObj, entityObj) {
|
computeClosedDisabled(stateObj, entityObj) {
|
||||||
|
if (UNAVAILABLE_STATES.includes(stateObj.state)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
var assumedState = stateObj.attributes.assumed_state === true;
|
var assumedState = stateObj.attributes.assumed_state === true;
|
||||||
return (entityObj.isFullyClosed || entityObj.isClosing) && !assumedState;
|
return (entityObj.isFullyClosed || entityObj.isClosing) && !assumedState;
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import { html } from "@polymer/polymer/lib/utils/html-tag";
|
|||||||
import { PolymerElement } from "@polymer/polymer/polymer-element";
|
import { PolymerElement } from "@polymer/polymer/polymer-element";
|
||||||
|
|
||||||
import CoverEntity from "../util/cover-model";
|
import CoverEntity from "../util/cover-model";
|
||||||
|
import { UNAVAILABLE_STATES } from "../data/entity";
|
||||||
|
|
||||||
class HaCoverTiltControls extends PolymerElement {
|
class HaCoverTiltControls extends PolymerElement {
|
||||||
static get template() {
|
static get template() {
|
||||||
@ -63,11 +64,17 @@ class HaCoverTiltControls extends PolymerElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
computeOpenDisabled(stateObj, entityObj) {
|
computeOpenDisabled(stateObj, entityObj) {
|
||||||
|
if (UNAVAILABLE_STATES.includes(stateObj.state)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
var assumedState = stateObj.attributes.assumed_state === true;
|
var assumedState = stateObj.attributes.assumed_state === true;
|
||||||
return entityObj.isFullyOpenTilt && !assumedState;
|
return entityObj.isFullyOpenTilt && !assumedState;
|
||||||
}
|
}
|
||||||
|
|
||||||
computeClosedDisabled(stateObj, entityObj) {
|
computeClosedDisabled(stateObj, entityObj) {
|
||||||
|
if (UNAVAILABLE_STATES.includes(stateObj.state)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
var assumedState = stateObj.attributes.assumed_state === true;
|
var assumedState = stateObj.attributes.assumed_state === true;
|
||||||
return entityObj.isFullyClosedTilt && !assumedState;
|
return entityObj.isFullyClosedTilt && !assumedState;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
export const UNAVAILABLE = "unavailable";
|
export const UNAVAILABLE = "unavailable";
|
||||||
export const UNKNOWN = "unknown";
|
export const UNKNOWN = "unknown";
|
||||||
|
|
||||||
|
export const UNAVAILABLE_STATES = [UNAVAILABLE, UNKNOWN];
|
||||||
|
|
||||||
export const ENTITY_COMPONENT_DOMAINS = [
|
export const ENTITY_COMPONENT_DOMAINS = [
|
||||||
"air_quality",
|
"air_quality",
|
||||||
"alarm_control_panel",
|
"alarm_control_panel",
|
||||||
|
@ -30,7 +30,7 @@ import { actionHandler } from "../common/directives/action-handler-directive";
|
|||||||
import { isValidEntityId } from "../../../common/entity/valid_entity_id";
|
import { isValidEntityId } from "../../../common/entity/valid_entity_id";
|
||||||
import { findEntities } from "../common/find-entites";
|
import { findEntities } from "../common/find-entites";
|
||||||
import { createHeaderFooterElement } from "../create-element/create-header-footer-element";
|
import { createHeaderFooterElement } from "../create-element/create-header-footer-element";
|
||||||
import { UNKNOWN, UNAVAILABLE } from "../../../data/entity";
|
import { UNAVAILABLE_STATES } from "../../../data/entity";
|
||||||
import { HuiErrorCard } from "./hui-error-card";
|
import { HuiErrorCard } from "./hui-error-card";
|
||||||
|
|
||||||
@customElement("hui-entity-card")
|
@customElement("hui-entity-card")
|
||||||
@ -105,7 +105,7 @@ export class HuiEntityCard extends LitElement implements LovelaceCard {
|
|||||||
|
|
||||||
const showUnit = this._config.attribute
|
const showUnit = this._config.attribute
|
||||||
? this._config.attribute in stateObj.attributes
|
? this._config.attribute in stateObj.attributes
|
||||||
: stateObj.state !== UNKNOWN && stateObj.state !== UNAVAILABLE;
|
: !UNAVAILABLE_STATES.includes(stateObj.state);
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-card>
|
<ha-card>
|
||||||
|
@ -30,7 +30,7 @@ import { hasAction } from "../common/has-action";
|
|||||||
import { ActionHandlerEvent } from "../../../data/lovelace";
|
import { ActionHandlerEvent } from "../../../data/lovelace";
|
||||||
import { handleAction } from "../common/handle-action";
|
import { handleAction } from "../common/handle-action";
|
||||||
import { computeDomain } from "../../../common/entity/compute_domain";
|
import { computeDomain } from "../../../common/entity/compute_domain";
|
||||||
import { UNAVAILABLE, UNKNOWN } from "../../../data/entity";
|
import { UNAVAILABLE_STATES } from "../../../data/entity";
|
||||||
import { findEntities } from "../common/find-entites";
|
import { findEntities } from "../common/find-entites";
|
||||||
|
|
||||||
@customElement("hui-glance-card")
|
@customElement("hui-glance-card")
|
||||||
@ -263,8 +263,7 @@ export class HuiGlanceCard extends LitElement implements LovelaceCard {
|
|||||||
<div>
|
<div>
|
||||||
${computeDomain(entityConf.entity) === "sensor" &&
|
${computeDomain(entityConf.entity) === "sensor" &&
|
||||||
stateObj.attributes.device_class === "timestamp" &&
|
stateObj.attributes.device_class === "timestamp" &&
|
||||||
stateObj.state !== UNAVAILABLE &&
|
!UNAVAILABLE_STATES.includes(stateObj.state)
|
||||||
stateObj.state !== UNKNOWN
|
|
||||||
? html`
|
? html`
|
||||||
<hui-timestamp-display
|
<hui-timestamp-display
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
|
@ -19,7 +19,6 @@ import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_elemen
|
|||||||
|
|
||||||
import "../../../components/ha-card";
|
import "../../../components/ha-card";
|
||||||
import "../components/hui-warning";
|
import "../components/hui-warning";
|
||||||
import "../components/hui-unavailable";
|
|
||||||
|
|
||||||
import { fireEvent } from "../../../common/dom/fire_event";
|
import { fireEvent } from "../../../common/dom/fire_event";
|
||||||
import { HomeAssistant, LightEntity } from "../../../types";
|
import { HomeAssistant, LightEntity } from "../../../types";
|
||||||
@ -29,7 +28,7 @@ import { LightCardConfig } from "./types";
|
|||||||
import { supportsFeature } from "../../../common/entity/supports-feature";
|
import { supportsFeature } from "../../../common/entity/supports-feature";
|
||||||
import { SUPPORT_BRIGHTNESS } from "../../../data/light";
|
import { SUPPORT_BRIGHTNESS } from "../../../data/light";
|
||||||
import { findEntities } from "../common/find-entites";
|
import { findEntities } from "../common/find-entites";
|
||||||
import { UNAVAILABLE } from "../../../data/entity";
|
import { UNAVAILABLE_STATES } from "../../../data/entity";
|
||||||
import { actionHandler } from "../common/directives/action-handler-directive";
|
import { actionHandler } from "../common/directives/action-handler-directive";
|
||||||
import { hasAction } from "../common/has-action";
|
import { hasAction } from "../common/has-action";
|
||||||
import { ActionHandlerEvent } from "../../../data/lovelace";
|
import { ActionHandlerEvent } from "../../../data/lovelace";
|
||||||
@ -107,14 +106,6 @@ export class HuiLightCard extends LitElement implements LovelaceCard {
|
|||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-card>
|
<ha-card>
|
||||||
${stateObj.state === UNAVAILABLE
|
|
||||||
? html`
|
|
||||||
<hui-unavailable
|
|
||||||
.text=${this.hass.localize("state.default.unavailable")}
|
|
||||||
@click=${this._handleMoreInfo}
|
|
||||||
></hui-unavailable>
|
|
||||||
`
|
|
||||||
: ""}
|
|
||||||
<paper-icon-button
|
<paper-icon-button
|
||||||
icon="hass:dots-vertical"
|
icon="hass:dots-vertical"
|
||||||
class="more-info"
|
class="more-info"
|
||||||
@ -128,6 +119,7 @@ export class HuiLightCard extends LitElement implements LovelaceCard {
|
|||||||
<round-slider
|
<round-slider
|
||||||
min="0"
|
min="0"
|
||||||
.value=${brightness}
|
.value=${brightness}
|
||||||
|
.disabled=${UNAVAILABLE_STATES.includes(stateObj.state)}
|
||||||
@value-changing=${this._dragEvent}
|
@value-changing=${this._dragEvent}
|
||||||
@value-changed=${this._setBrightness}
|
@value-changed=${this._setBrightness}
|
||||||
style=${styleMap({
|
style=${styleMap({
|
||||||
@ -145,6 +137,7 @@ export class HuiLightCard extends LitElement implements LovelaceCard {
|
|||||||
"state-on": stateObj.state === "on",
|
"state-on": stateObj.state === "on",
|
||||||
"state-unavailable": stateObj.state === "unavailable",
|
"state-unavailable": stateObj.state === "unavailable",
|
||||||
})}"
|
})}"
|
||||||
|
.disabled=${UNAVAILABLE_STATES.includes(stateObj.state)}
|
||||||
.icon=${this._config.icon || stateIcon(stateObj)}
|
.icon=${this._config.icon || stateIcon(stateObj)}
|
||||||
style=${styleMap({
|
style=${styleMap({
|
||||||
filter: this._computeBrightness(stateObj),
|
filter: this._computeBrightness(stateObj),
|
||||||
@ -161,9 +154,18 @@ export class HuiLightCard extends LitElement implements LovelaceCard {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="info">
|
<div id="info">
|
||||||
|
${UNAVAILABLE_STATES.includes(stateObj.state)
|
||||||
|
? html`
|
||||||
|
<div>
|
||||||
|
${this.hass.localize(`state.default.${stateObj.state}`) ||
|
||||||
|
stateObj.state}
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
: html`
|
||||||
<div class="brightness">
|
<div class="brightness">
|
||||||
%
|
%
|
||||||
</div>
|
</div>
|
||||||
|
`}
|
||||||
${this._config.name || computeStateName(stateObj)}
|
${this._config.name || computeStateName(stateObj)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -267,10 +269,6 @@ export class HuiLightCard extends LitElement implements LovelaceCard {
|
|||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
hui-unavailable {
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
ha-card {
|
ha-card {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
@ -353,9 +351,6 @@ export class HuiLightCard extends LitElement implements LovelaceCard {
|
|||||||
transition: opacity 0.5s ease-in-out;
|
transition: opacity 0.5s ease-in-out;
|
||||||
-moz-transition: opacity 0.5s ease-in-out;
|
-moz-transition: opacity 0.5s ease-in-out;
|
||||||
-webkit-transition: opacity 0.5s ease-in-out;
|
-webkit-transition: opacity 0.5s ease-in-out;
|
||||||
cursor: pointer;
|
|
||||||
pointer-events: none;
|
|
||||||
padding-left: 0.5em;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.show_brightness {
|
.show_brightness {
|
||||||
|
@ -30,7 +30,7 @@ import { stateIcon } from "../../../common/entity/state_icon";
|
|||||||
import { hasConfigOrEntityChanged } from "../common/has-changed";
|
import { hasConfigOrEntityChanged } from "../common/has-changed";
|
||||||
import { contrast } from "../common/color/contrast";
|
import { contrast } from "../common/color/contrast";
|
||||||
import { findEntities } from "../common/find-entites";
|
import { findEntities } from "../common/find-entites";
|
||||||
import { UNAVAILABLE, UNKNOWN } from "../../../data/entity";
|
import { UNAVAILABLE_STATES } from "../../../data/entity";
|
||||||
import {
|
import {
|
||||||
SUPPORT_PAUSE,
|
SUPPORT_PAUSE,
|
||||||
SUPPORT_TURN_ON,
|
SUPPORT_TURN_ON,
|
||||||
@ -285,8 +285,7 @@ export class HuiMediaControlCard extends LitElement implements LovelaceCard {
|
|||||||
|
|
||||||
const isOffState = state === "off";
|
const isOffState = state === "off";
|
||||||
const isUnavailable =
|
const isUnavailable =
|
||||||
state === UNAVAILABLE ||
|
UNAVAILABLE_STATES.includes(state) ||
|
||||||
state === UNKNOWN ||
|
|
||||||
(state === "off" && !supportsFeature(stateObj, SUPPORT_TURN_ON));
|
(state === "off" && !supportsFeature(stateObj, SUPPORT_TURN_ON));
|
||||||
const hasNoImage = !this._image;
|
const hasNoImage = !this._image;
|
||||||
const controls = this._getControls();
|
const controls = this._getControls();
|
||||||
@ -501,7 +500,7 @@ export class HuiMediaControlCard extends LitElement implements LovelaceCard {
|
|||||||
|
|
||||||
const state = stateObj.state;
|
const state = stateObj.state;
|
||||||
|
|
||||||
if (state === UNAVAILABLE || state === UNKNOWN) {
|
if (UNAVAILABLE_STATES.includes(state)) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ import { computeStateName } from "../../../common/entity/compute_state_name";
|
|||||||
import { computeStateDisplay } from "../../../common/entity/compute_state_display";
|
import { computeStateDisplay } from "../../../common/entity/compute_state_display";
|
||||||
import { HomeAssistant } from "../../../types";
|
import { HomeAssistant } from "../../../types";
|
||||||
import { LovelaceCard, LovelaceCardEditor } from "../types";
|
import { LovelaceCard, LovelaceCardEditor } from "../types";
|
||||||
import { UNAVAILABLE } from "../../../data/entity";
|
import { UNAVAILABLE_STATES } from "../../../data/entity";
|
||||||
import { hasConfigOrEntityChanged } from "../common/has-changed";
|
import { hasConfigOrEntityChanged } from "../common/has-changed";
|
||||||
import { PictureEntityCardConfig } from "./types";
|
import { PictureEntityCardConfig } from "./types";
|
||||||
import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element";
|
import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element";
|
||||||
@ -178,7 +178,7 @@ class HuiPictureEntityCard extends LitElement implements LovelaceCard {
|
|||||||
: undefined
|
: undefined
|
||||||
)}
|
)}
|
||||||
class=${classMap({
|
class=${classMap({
|
||||||
clickable: stateObj.state !== UNAVAILABLE,
|
clickable: !UNAVAILABLE_STATES.includes(stateObj.state),
|
||||||
})}
|
})}
|
||||||
></hui-image>
|
></hui-image>
|
||||||
${footer}
|
${footer}
|
||||||
|
@ -15,7 +15,6 @@ import "@thomasloven/round-slider";
|
|||||||
|
|
||||||
import "../../../components/ha-card";
|
import "../../../components/ha-card";
|
||||||
import "../components/hui-warning";
|
import "../components/hui-warning";
|
||||||
import "../components/hui-unavailable";
|
|
||||||
|
|
||||||
import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element";
|
import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element";
|
||||||
import { computeStateName } from "../../../common/entity/compute_state_name";
|
import { computeStateName } from "../../../common/entity/compute_state_name";
|
||||||
@ -35,7 +34,7 @@ import {
|
|||||||
import { HassEntity } from "home-assistant-js-websocket";
|
import { HassEntity } from "home-assistant-js-websocket";
|
||||||
import { actionHandler } from "../common/directives/action-handler-directive";
|
import { actionHandler } from "../common/directives/action-handler-directive";
|
||||||
import { findEntities } from "../common/find-entites";
|
import { findEntities } from "../common/find-entites";
|
||||||
import { UNAVAILABLE } from "../../../data/entity";
|
import { UNAVAILABLE_STATES } from "../../../data/entity";
|
||||||
|
|
||||||
const modeIcons: { [mode in HvacMode]: string } = {
|
const modeIcons: { [mode in HvacMode]: string } = {
|
||||||
auto: "hass:calendar-repeat",
|
auto: "hass:calendar-repeat",
|
||||||
@ -127,8 +126,7 @@ export class HuiThermostatCard extends LitElement implements LovelaceCard {
|
|||||||
? stateObj.attributes.temperature
|
? stateObj.attributes.temperature
|
||||||
: stateObj.attributes.min_temp;
|
: stateObj.attributes.min_temp;
|
||||||
|
|
||||||
const slider =
|
const slider = UNAVAILABLE_STATES.includes(stateObj.state)
|
||||||
stateObj.state === "unavailable"
|
|
||||||
? html`
|
? html`
|
||||||
<round-slider disabled="true"></round-slider>
|
<round-slider disabled="true"></round-slider>
|
||||||
`
|
`
|
||||||
@ -224,14 +222,6 @@ export class HuiThermostatCard extends LitElement implements LovelaceCard {
|
|||||||
[mode]: true,
|
[mode]: true,
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
${stateObj.state === UNAVAILABLE
|
|
||||||
? html`
|
|
||||||
<hui-unavailable
|
|
||||||
.text="${this.hass.localize("state.default.unavailable")}"
|
|
||||||
@click=${this._handleMoreInfo}
|
|
||||||
></hui-unavailable>
|
|
||||||
`
|
|
||||||
: ""}
|
|
||||||
<paper-icon-button
|
<paper-icon-button
|
||||||
icon="hass:dots-vertical"
|
icon="hass:dots-vertical"
|
||||||
class="more-info"
|
class="more-info"
|
||||||
@ -333,7 +323,7 @@ export class HuiThermostatCard extends LitElement implements LovelaceCard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _getSetTemp(stateObj: HassEntity) {
|
private _getSetTemp(stateObj: HassEntity) {
|
||||||
if (stateObj.state === "unavailable") {
|
if (UNAVAILABLE_STATES.includes(stateObj.state)) {
|
||||||
return this.hass!.localize("state.default.unavailable");
|
return this.hass!.localize("state.default.unavailable");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -420,10 +410,6 @@ export class HuiThermostatCard extends LitElement implements LovelaceCard {
|
|||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
hui-unavailable {
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
ha-card {
|
ha-card {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
@ -1,57 +0,0 @@
|
|||||||
import {
|
|
||||||
html,
|
|
||||||
LitElement,
|
|
||||||
TemplateResult,
|
|
||||||
CSSResult,
|
|
||||||
css,
|
|
||||||
customElement,
|
|
||||||
property,
|
|
||||||
} from "lit-element";
|
|
||||||
|
|
||||||
@customElement("hui-unavailable")
|
|
||||||
export class HuiUnavailable extends LitElement {
|
|
||||||
@property() public text?: string;
|
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
|
||||||
return html`
|
|
||||||
<div class="disabled-overlay"></div>
|
|
||||||
<div class="disabled-overlay-text">${this.text}</div>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
static get styles(): CSSResult {
|
|
||||||
return css`
|
|
||||||
.disabled-overlay {
|
|
||||||
position: absolute;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
right: 0;
|
|
||||||
bottom: 0;
|
|
||||||
background-color: var(--state-icon-unavailable-color);
|
|
||||||
opacity: 0.6;
|
|
||||||
z-index: 50;
|
|
||||||
}
|
|
||||||
|
|
||||||
.disabled-overlay-text {
|
|
||||||
position: absolute;
|
|
||||||
top: 50%;
|
|
||||||
left: 50%;
|
|
||||||
font-size: 24px;
|
|
||||||
text-align: center;
|
|
||||||
color: var(--primary-text-color);
|
|
||||||
transform: translate(-50%, -50%);
|
|
||||||
-ms-transform: translate(-50%, -50%);
|
|
||||||
z-index: 50;
|
|
||||||
opacity: 0.7;
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
declare global {
|
|
||||||
interface HTMLElementTagNameMap {
|
|
||||||
"hui-unavailable": HuiUnavailable;
|
|
||||||
}
|
|
||||||
}
|
|
@ -22,7 +22,7 @@ import {
|
|||||||
computeUsedEntities,
|
computeUsedEntities,
|
||||||
calcUnusedEntities,
|
calcUnusedEntities,
|
||||||
} from "../../common/compute-unused-entities";
|
} from "../../common/compute-unused-entities";
|
||||||
import { UNKNOWN, UNAVAILABLE } from "../../../../data/entity";
|
import { UNAVAILABLE_STATES } from "../../../../data/entity";
|
||||||
import {
|
import {
|
||||||
customCards,
|
customCards,
|
||||||
getCustomCardEntry,
|
getCustomCardEntry,
|
||||||
@ -168,14 +168,12 @@ export class HuiCardPicker extends LitElement {
|
|||||||
this._usedEntities = [...usedEntities].filter(
|
this._usedEntities = [...usedEntities].filter(
|
||||||
(eid) =>
|
(eid) =>
|
||||||
this.hass!.states[eid] &&
|
this.hass!.states[eid] &&
|
||||||
this.hass!.states[eid].state !== UNKNOWN &&
|
!UNAVAILABLE_STATES.includes(this.hass!.states[eid].state)
|
||||||
this.hass!.states[eid].state !== UNAVAILABLE
|
|
||||||
);
|
);
|
||||||
this._unusedEntities = [...unusedEntities].filter(
|
this._unusedEntities = [...unusedEntities].filter(
|
||||||
(eid) =>
|
(eid) =>
|
||||||
this.hass!.states[eid] &&
|
this.hass!.states[eid] &&
|
||||||
this.hass!.states[eid].state !== UNKNOWN &&
|
!UNAVAILABLE_STATES.includes(this.hass!.states[eid].state)
|
||||||
this.hass!.states[eid].state !== UNAVAILABLE
|
|
||||||
);
|
);
|
||||||
|
|
||||||
this.requestUpdate();
|
this.requestUpdate();
|
||||||
|
@ -19,6 +19,7 @@ import { HomeAssistant } from "../../../types";
|
|||||||
import { LovelaceRow, EntityConfig } from "./types";
|
import { LovelaceRow, EntityConfig } from "./types";
|
||||||
import { setInputDateTimeValue } from "../../../data/input_datetime";
|
import { setInputDateTimeValue } from "../../../data/input_datetime";
|
||||||
import { hasConfigOrEntityChanged } from "../common/has-changed";
|
import { hasConfigOrEntityChanged } from "../common/has-changed";
|
||||||
|
import { UNAVAILABLE_STATES } from "../../../data/entity";
|
||||||
|
|
||||||
@customElement("hui-input-datetime-entity-row")
|
@customElement("hui-input-datetime-entity-row")
|
||||||
class HuiInputDatetimeEntityRow extends LitElement implements LovelaceRow {
|
class HuiInputDatetimeEntityRow extends LitElement implements LovelaceRow {
|
||||||
@ -60,6 +61,7 @@ class HuiInputDatetimeEntityRow extends LitElement implements LovelaceRow {
|
|||||||
${stateObj.attributes.has_date
|
${stateObj.attributes.has_date
|
||||||
? html`
|
? html`
|
||||||
<ha-date-input
|
<ha-date-input
|
||||||
|
.disabled=${UNAVAILABLE_STATES.includes(stateObj.state)}
|
||||||
.year=${stateObj.attributes.year}
|
.year=${stateObj.attributes.year}
|
||||||
.month=${("0" + stateObj.attributes.month).slice(-2)}
|
.month=${("0" + stateObj.attributes.month).slice(-2)}
|
||||||
.day=${("0" + stateObj.attributes.day).slice(-2)}
|
.day=${("0" + stateObj.attributes.day).slice(-2)}
|
||||||
@ -72,6 +74,7 @@ class HuiInputDatetimeEntityRow extends LitElement implements LovelaceRow {
|
|||||||
${stateObj.attributes.has_time
|
${stateObj.attributes.has_time
|
||||||
? html`
|
? html`
|
||||||
<paper-time-input
|
<paper-time-input
|
||||||
|
.disabled=${UNAVAILABLE_STATES.includes(stateObj.state)}
|
||||||
.hour=${stateObj.state === "unknown"
|
.hour=${stateObj.state === "unknown"
|
||||||
? ""
|
? ""
|
||||||
: ("0" + stateObj.attributes.hour).slice(-2)}
|
: ("0" + stateObj.attributes.hour).slice(-2)}
|
||||||
|
@ -18,6 +18,7 @@ import { LovelaceRow, EntityConfig } from "./types";
|
|||||||
import { HomeAssistant } from "../../../types";
|
import { HomeAssistant } from "../../../types";
|
||||||
import { setValue } from "../../../data/input_text";
|
import { setValue } from "../../../data/input_text";
|
||||||
import { hasConfigOrEntityChanged } from "../common/has-changed";
|
import { hasConfigOrEntityChanged } from "../common/has-changed";
|
||||||
|
import { UNAVAILABLE_STATES } from "../../../data/entity";
|
||||||
|
|
||||||
@customElement("hui-input-number-entity-row")
|
@customElement("hui-input-number-entity-row")
|
||||||
class HuiInputNumberEntityRow extends LitElement implements LovelaceRow {
|
class HuiInputNumberEntityRow extends LitElement implements LovelaceRow {
|
||||||
@ -79,6 +80,7 @@ class HuiInputNumberEntityRow extends LitElement implements LovelaceRow {
|
|||||||
? html`
|
? html`
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<ha-slider
|
<ha-slider
|
||||||
|
.disabled=${UNAVAILABLE_STATES.includes(stateObj.state)}
|
||||||
.dir="${computeRTLDirection(this.hass!)}"
|
.dir="${computeRTLDirection(this.hass!)}"
|
||||||
.step="${Number(stateObj.attributes.step)}"
|
.step="${Number(stateObj.attributes.step)}"
|
||||||
.min="${Number(stateObj.attributes.min)}"
|
.min="${Number(stateObj.attributes.min)}"
|
||||||
@ -99,6 +101,7 @@ class HuiInputNumberEntityRow extends LitElement implements LovelaceRow {
|
|||||||
<paper-input
|
<paper-input
|
||||||
no-label-float
|
no-label-float
|
||||||
auto-validate
|
auto-validate
|
||||||
|
.disabled=${UNAVAILABLE_STATES.includes(stateObj.state)}
|
||||||
.pattern="[0-9]+([\\.][0-9]+)?"
|
.pattern="[0-9]+([\\.][0-9]+)?"
|
||||||
.step="${Number(stateObj.attributes.step)}"
|
.step="${Number(stateObj.attributes.step)}"
|
||||||
.min="${Number(stateObj.attributes.min)}"
|
.min="${Number(stateObj.attributes.min)}"
|
||||||
|
@ -32,8 +32,7 @@ import { actionHandler } from "../common/directives/action-handler-directive";
|
|||||||
import { hasAction } from "../common/has-action";
|
import { hasAction } from "../common/has-action";
|
||||||
import { ActionHandlerEvent } from "../../../data/lovelace";
|
import { ActionHandlerEvent } from "../../../data/lovelace";
|
||||||
import { handleAction } from "../common/handle-action";
|
import { handleAction } from "../common/handle-action";
|
||||||
import { UNAVAILABLE } from "../../../data/entity";
|
import { UNAVAILABLE_STATES } from "../../../data/entity";
|
||||||
import { fireEvent } from "../../../common/dom/fire_event";
|
|
||||||
|
|
||||||
@customElement("hui-input-select-entity-row")
|
@customElement("hui-input-select-entity-row")
|
||||||
class HuiInputSelectEntityRow extends LitElement implements LovelaceRow {
|
class HuiInputSelectEntityRow extends LitElement implements LovelaceRow {
|
||||||
@ -80,14 +79,6 @@ class HuiInputSelectEntityRow extends LitElement implements LovelaceRow {
|
|||||||
!DOMAINS_HIDE_MORE_INFO.includes(computeDomain(this._config.entity)));
|
!DOMAINS_HIDE_MORE_INFO.includes(computeDomain(this._config.entity)));
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
${stateObj.state === UNAVAILABLE
|
|
||||||
? html`
|
|
||||||
<hui-unavailable
|
|
||||||
.text=${this.hass.localize("state.default.unavailable")}
|
|
||||||
@click=${this._showMoreInfo}
|
|
||||||
></hui-unavailable>
|
|
||||||
`
|
|
||||||
: ""}
|
|
||||||
<state-badge
|
<state-badge
|
||||||
.stateObj=${stateObj}
|
.stateObj=${stateObj}
|
||||||
.stateColor=${this._config.state_color}
|
.stateColor=${this._config.state_color}
|
||||||
@ -106,6 +97,7 @@ class HuiInputSelectEntityRow extends LitElement implements LovelaceRow {
|
|||||||
<ha-paper-dropdown-menu
|
<ha-paper-dropdown-menu
|
||||||
.label=${this._config.name || computeStateName(stateObj)}
|
.label=${this._config.name || computeStateName(stateObj)}
|
||||||
.value=${stateObj.state}
|
.value=${stateObj.state}
|
||||||
|
.disabled=${UNAVAILABLE_STATES.includes(stateObj.state)}
|
||||||
@iron-select=${this._selectedChanged}
|
@iron-select=${this._selectedChanged}
|
||||||
@click=${stopPropagation}
|
@click=${stopPropagation}
|
||||||
>
|
>
|
||||||
@ -149,10 +141,6 @@ class HuiInputSelectEntityRow extends LitElement implements LovelaceRow {
|
|||||||
handleAction(this, this.hass!, this._config!, ev.detail.action!);
|
handleAction(this, this.hass!, this._config!, ev.detail.action!);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _showMoreInfo() {
|
|
||||||
fireEvent(this, "hass-more-info", { entityId: this._config!.entity });
|
|
||||||
}
|
|
||||||
|
|
||||||
static get styles(): CSSResult {
|
static get styles(): CSSResult {
|
||||||
return css`
|
return css`
|
||||||
:host {
|
:host {
|
||||||
@ -175,9 +163,6 @@ class HuiInputSelectEntityRow extends LitElement implements LovelaceRow {
|
|||||||
background: var(--divider-color);
|
background: var(--divider-color);
|
||||||
border-radius: 100%;
|
border-radius: 100%;
|
||||||
}
|
}
|
||||||
hui-unavailable {
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ import { HomeAssistant } from "../../../types";
|
|||||||
import { LovelaceRow, EntityConfig } from "./types";
|
import { LovelaceRow, EntityConfig } from "./types";
|
||||||
import { setValue } from "../../../data/input_text";
|
import { setValue } from "../../../data/input_text";
|
||||||
import { hasConfigOrEntityChanged } from "../common/has-changed";
|
import { hasConfigOrEntityChanged } from "../common/has-changed";
|
||||||
|
import { UNAVAILABLE_STATES } from "../../../data/entity";
|
||||||
|
|
||||||
@customElement("hui-input-text-entity-row")
|
@customElement("hui-input-text-entity-row")
|
||||||
class HuiInputTextEntityRow extends LitElement implements LovelaceRow {
|
class HuiInputTextEntityRow extends LitElement implements LovelaceRow {
|
||||||
@ -56,6 +57,7 @@ class HuiInputTextEntityRow extends LitElement implements LovelaceRow {
|
|||||||
<hui-generic-entity-row .hass=${this.hass} .config=${this._config}>
|
<hui-generic-entity-row .hass=${this.hass} .config=${this._config}>
|
||||||
<paper-input
|
<paper-input
|
||||||
no-label-float
|
no-label-float
|
||||||
|
.disabled=${UNAVAILABLE_STATES.includes(stateObj.state)}
|
||||||
.value="${stateObj.state}"
|
.value="${stateObj.state}"
|
||||||
.minlength="${stateObj.attributes.min}"
|
.minlength="${stateObj.attributes.min}"
|
||||||
.maxlength="${stateObj.attributes.max}"
|
.maxlength="${stateObj.attributes.max}"
|
||||||
|
@ -15,6 +15,7 @@ import "../components/hui-warning";
|
|||||||
import { HomeAssistant } from "../../../types";
|
import { HomeAssistant } from "../../../types";
|
||||||
import { LovelaceRow, EntityConfig } from "./types";
|
import { LovelaceRow, EntityConfig } from "./types";
|
||||||
import { hasConfigOrEntityChanged } from "../common/has-changed";
|
import { hasConfigOrEntityChanged } from "../common/has-changed";
|
||||||
|
import { UNAVAILABLE_STATES } from "../../../data/entity";
|
||||||
|
|
||||||
@customElement("hui-lock-entity-row")
|
@customElement("hui-lock-entity-row")
|
||||||
class HuiLockEntityRow extends LitElement implements LovelaceRow {
|
class HuiLockEntityRow extends LitElement implements LovelaceRow {
|
||||||
@ -54,7 +55,11 @@ class HuiLockEntityRow extends LitElement implements LovelaceRow {
|
|||||||
|
|
||||||
return html`
|
return html`
|
||||||
<hui-generic-entity-row .hass=${this.hass} .config=${this._config}>
|
<hui-generic-entity-row .hass=${this.hass} .config=${this._config}>
|
||||||
<mwc-button @click="${this._callService}" class="text-content">
|
<mwc-button
|
||||||
|
@click="${this._callService}"
|
||||||
|
.disabled=${UNAVAILABLE_STATES.includes(stateObj.state)}
|
||||||
|
class="text-content"
|
||||||
|
>
|
||||||
${stateObj.state === "locked"
|
${stateObj.state === "locked"
|
||||||
? this.hass!.localize("ui.card.lock.unlock")
|
? this.hass!.localize("ui.card.lock.unlock")
|
||||||
: this.hass!.localize("ui.card.lock.lock")}
|
: this.hass!.localize("ui.card.lock.lock")}
|
||||||
|
@ -17,6 +17,7 @@ import { HomeAssistant } from "../../../types";
|
|||||||
import { LovelaceRow, ActionRowConfig } from "./types";
|
import { LovelaceRow, ActionRowConfig } from "./types";
|
||||||
import { hasConfigOrEntityChanged } from "../common/has-changed";
|
import { hasConfigOrEntityChanged } from "../common/has-changed";
|
||||||
import { activateScene } from "../../../data/scene";
|
import { activateScene } from "../../../data/scene";
|
||||||
|
import { UNAVAILABLE_STATES } from "../../../data/entity";
|
||||||
|
|
||||||
@customElement("hui-scene-entity-row")
|
@customElement("hui-scene-entity-row")
|
||||||
class HuiSceneEntityRow extends LitElement implements LovelaceRow {
|
class HuiSceneEntityRow extends LitElement implements LovelaceRow {
|
||||||
@ -56,7 +57,11 @@ class HuiSceneEntityRow extends LitElement implements LovelaceRow {
|
|||||||
|
|
||||||
return html`
|
return html`
|
||||||
<hui-generic-entity-row .hass=${this.hass} .config=${this._config}>
|
<hui-generic-entity-row .hass=${this.hass} .config=${this._config}>
|
||||||
<mwc-button @click="${this._callService}" class="text-content">
|
<mwc-button
|
||||||
|
@click="${this._callService}"
|
||||||
|
.disabled=${UNAVAILABLE_STATES.includes(stateObj.state)}
|
||||||
|
class="text-content"
|
||||||
|
>
|
||||||
${this._config.action_name ||
|
${this._config.action_name ||
|
||||||
this.hass!.localize("ui.card.scene.activate")}
|
this.hass!.localize("ui.card.scene.activate")}
|
||||||
</mwc-button>
|
</mwc-button>
|
||||||
|
@ -16,6 +16,7 @@ import "../components/hui-warning";
|
|||||||
import { HomeAssistant } from "../../../types";
|
import { HomeAssistant } from "../../../types";
|
||||||
import { LovelaceRow, ActionRowConfig } from "./types";
|
import { LovelaceRow, ActionRowConfig } from "./types";
|
||||||
import { hasConfigOrEntityChanged } from "../common/has-changed";
|
import { hasConfigOrEntityChanged } from "../common/has-changed";
|
||||||
|
import { UNAVAILABLE_STATES } from "../../../data/entity";
|
||||||
|
|
||||||
@customElement("hui-script-entity-row")
|
@customElement("hui-script-entity-row")
|
||||||
class HuiScriptEntityRow extends LitElement implements LovelaceRow {
|
class HuiScriptEntityRow extends LitElement implements LovelaceRow {
|
||||||
@ -58,12 +59,17 @@ class HuiScriptEntityRow extends LitElement implements LovelaceRow {
|
|||||||
${stateObj.attributes.can_cancel
|
${stateObj.attributes.can_cancel
|
||||||
? html`
|
? html`
|
||||||
<ha-entity-toggle
|
<ha-entity-toggle
|
||||||
|
.disabled=${UNAVAILABLE_STATES.includes(stateObj.state)}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.stateObj=${stateObj}
|
.stateObj=${stateObj}
|
||||||
></ha-entity-toggle>
|
></ha-entity-toggle>
|
||||||
`
|
`
|
||||||
: html`
|
: html`
|
||||||
<mwc-button @click=${this._callService} class="text-content">
|
<mwc-button
|
||||||
|
@click=${this._callService}
|
||||||
|
.disabled=${UNAVAILABLE_STATES.includes(stateObj.state)}
|
||||||
|
class="text-content"
|
||||||
|
>
|
||||||
${this._config.action_name ||
|
${this._config.action_name ||
|
||||||
this.hass!.localize("ui.card.script.execute")}
|
this.hass!.localize("ui.card.script.execute")}
|
||||||
</mwc-button>
|
</mwc-button>
|
||||||
|
@ -15,6 +15,7 @@ import { computeStateDisplay } from "../../../common/entity/compute_state_displa
|
|||||||
import { HomeAssistant } from "../../../types";
|
import { HomeAssistant } from "../../../types";
|
||||||
import { LovelaceRow, EntityConfig } from "./types";
|
import { LovelaceRow, EntityConfig } from "./types";
|
||||||
import { hasConfigOrEntityChanged } from "../common/has-changed";
|
import { hasConfigOrEntityChanged } from "../common/has-changed";
|
||||||
|
import { UNAVAILABLE_STATES } from "../../../data/entity";
|
||||||
|
|
||||||
@customElement("hui-toggle-entity-row")
|
@customElement("hui-toggle-entity-row")
|
||||||
class HuiToggleEntityRow extends LitElement implements LovelaceRow {
|
class HuiToggleEntityRow extends LitElement implements LovelaceRow {
|
||||||
@ -54,7 +55,9 @@ class HuiToggleEntityRow extends LitElement implements LovelaceRow {
|
|||||||
|
|
||||||
return html`
|
return html`
|
||||||
<hui-generic-entity-row .hass=${this.hass} .config=${this._config}>
|
<hui-generic-entity-row .hass=${this.hass} .config=${this._config}>
|
||||||
${stateObj.state === "on" || stateObj.state === "off"
|
${stateObj.state === "on" ||
|
||||||
|
stateObj.state === "off" ||
|
||||||
|
UNAVAILABLE_STATES.includes(stateObj.state)
|
||||||
? html`
|
? html`
|
||||||
<ha-entity-toggle
|
<ha-entity-toggle
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
|
@ -22,6 +22,8 @@ import {
|
|||||||
weatherImages,
|
weatherImages,
|
||||||
} from "../../../data/weather";
|
} from "../../../data/weather";
|
||||||
|
|
||||||
|
import { UNAVAILABLE_STATES } from "../../../data/entity";
|
||||||
|
|
||||||
@customElement("hui-weather-entity-row")
|
@customElement("hui-weather-entity-row")
|
||||||
class HuiWeatherEntityRow extends LitElement implements LovelaceRow {
|
class HuiWeatherEntityRow extends LitElement implements LovelaceRow {
|
||||||
@property() public hass?: HomeAssistant;
|
@property() public hass?: HomeAssistant;
|
||||||
@ -68,11 +70,18 @@ class HuiWeatherEntityRow extends LitElement implements LovelaceRow {
|
|||||||
<hui-generic-entity-row .hass=${this.hass} .config=${weatherRowConfig}>
|
<hui-generic-entity-row .hass=${this.hass} .config=${weatherRowConfig}>
|
||||||
<div class="attributes">
|
<div class="attributes">
|
||||||
<div>
|
<div>
|
||||||
|
${UNAVAILABLE_STATES.includes(stateObj.state)
|
||||||
|
? this.hass.localize(`state.default.${stateObj.state}`) ||
|
||||||
|
stateObj.state
|
||||||
|
: html`
|
||||||
${stateObj.attributes.temperature}
|
${stateObj.attributes.temperature}
|
||||||
${getWeatherUnit(this.hass, "temperature")}
|
${getWeatherUnit(this.hass, "temperature")}
|
||||||
|
`}
|
||||||
</div>
|
</div>
|
||||||
<div class="secondary">
|
<div class="secondary">
|
||||||
${this._getSecondaryAttribute(stateObj)}
|
${!UNAVAILABLE_STATES.includes(stateObj.state)
|
||||||
|
? this._getSecondaryAttribute(stateObj)
|
||||||
|
: ""}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</hui-generic-entity-row>
|
</hui-generic-entity-row>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user