Don't disable controls when state is unknown (#5687)

This commit is contained in:
Bram Kragten 2020-05-01 13:18:58 +02:00
parent 04a2ff7506
commit fa8bd30e83
3 changed files with 25 additions and 9 deletions

View File

@ -12,7 +12,7 @@ import {
import { STATES_OFF } from "../../common/const";
import { computeStateDomain } from "../../common/entity/compute_state_domain";
import { computeStateName } from "../../common/entity/compute_state_name";
import { UNAVAILABLE_STATES } from "../../data/entity";
import { UNAVAILABLE_STATES, UNAVAILABLE } from "../../data/entity";
import { forwardHaptic } from "../../data/haptics";
import { HomeAssistant } from "../../types";
import "../ha-switch";
@ -40,14 +40,14 @@ class HaEntityToggle extends LitElement {
<paper-icon-button
aria-label=${`Turn ${computeStateName(this.stateObj)} off`}
icon="hass:flash-off"
.disabled=${UNAVAILABLE_STATES.includes(this.stateObj.state)}
.disabled=${this.stateObj.state === UNAVAILABLE}
@click=${this._turnOff}
?state-active=${!this._isOn}
></paper-icon-button>
<paper-icon-button
aria-label=${`Turn ${computeStateName(this.stateObj)} on`}
icon="hass:flash"
.disabled=${UNAVAILABLE_STATES.includes(this.stateObj.state)}
.disabled=${this.stateObj.state === UNAVAILABLE}
@click=${this._turnOn}
?state-active=${this._isOn}
></paper-icon-button>

View File

@ -2,7 +2,7 @@ import "@polymer/paper-icon-button/paper-icon-button";
import { html } from "@polymer/polymer/lib/utils/html-tag";
/* eslint-plugin-disable lit */
import { PolymerElement } from "@polymer/polymer/polymer-element";
import { UNAVAILABLE_STATES } from "../data/entity";
import { UNAVAILABLE } from "../data/entity";
import CoverEntity from "../util/cover-model";
class HaCoverControls extends PolymerElement {
@ -30,6 +30,7 @@ class HaCoverControls extends PolymerElement {
icon="hass:stop"
on-click="onStopTap"
invisible$="[[!entityObj.supportsStop]]"
disabled="[[computStopDisabled(stateObj)]]"
></paper-icon-button>
<paper-icon-button
aria-label="Close cover"
@ -81,8 +82,15 @@ class HaCoverControls extends PolymerElement {
}
}
computeStopDisabled(stateObj) {
if (stateObj.state === UNAVAILABLE) {
return true;
}
return false;
}
computeOpenDisabled(stateObj, entityObj) {
if (UNAVAILABLE_STATES.includes(stateObj.state)) {
if (stateObj.state === UNAVAILABLE) {
return true;
}
var assumedState = stateObj.attributes.assumed_state === true;
@ -90,7 +98,7 @@ class HaCoverControls extends PolymerElement {
}
computeClosedDisabled(stateObj, entityObj) {
if (UNAVAILABLE_STATES.includes(stateObj.state)) {
if (stateObj.state === UNAVAILABLE) {
return true;
}
var assumedState = stateObj.attributes.assumed_state === true;

View File

@ -3,7 +3,7 @@ import "@polymer/paper-icon-button/paper-icon-button";
import { html } from "@polymer/polymer/lib/utils/html-tag";
/* eslint-plugin-disable lit */
import { PolymerElement } from "@polymer/polymer/polymer-element";
import { UNAVAILABLE_STATES } from "../data/entity";
import { UNAVAILABLE } from "../data/entity";
import CoverEntity from "../util/cover-model";
class HaCoverTiltControls extends PolymerElement {
@ -31,6 +31,7 @@ class HaCoverTiltControls extends PolymerElement {
icon="hass:stop"
on-click="onStopTiltTap"
invisible$="[[!entityObj.supportsStopTilt]]"
disabled="[[computStopDisabled(stateObj)]]"
title="Stop tilt"
></paper-icon-button>
<paper-icon-button
@ -63,8 +64,15 @@ class HaCoverTiltControls extends PolymerElement {
return new CoverEntity(hass, stateObj);
}
computeStopDisabled(stateObj) {
if (stateObj.state === UNAVAILABLE) {
return true;
}
return false;
}
computeOpenDisabled(stateObj, entityObj) {
if (UNAVAILABLE_STATES.includes(stateObj.state)) {
if (stateObj.state === UNAVAILABLE) {
return true;
}
var assumedState = stateObj.attributes.assumed_state === true;
@ -72,7 +80,7 @@ class HaCoverTiltControls extends PolymerElement {
}
computeClosedDisabled(stateObj, entityObj) {
if (UNAVAILABLE_STATES.includes(stateObj.state)) {
if (stateObj.state === UNAVAILABLE) {
return true;
}
var assumedState = stateObj.attributes.assumed_state === true;