Use proper constants for "unavailable" checks (#6922)

* Use proper constants for "unavailable"

* Additional usage of constants
This commit is contained in:
Philip Allgaier
2020-09-10 22:59:45 +02:00
committed by GitHub
parent aa4bc2ce03
commit 2139a80a7a
11 changed files with 31 additions and 22 deletions

View File

@@ -20,6 +20,7 @@ import { stateIcon } from "../../common/entity/state_icon";
import { timerTimeRemaining } from "../../common/entity/timer_time_remaining";
import { HomeAssistant } from "../../types";
import "../ha-label-badge";
import { UNAVAILABLE, UNKNOWN } from "../../data/entity";
@customElement("ha-state-label-badge")
export class HaStateLabelBadge extends LitElement {
@@ -81,7 +82,8 @@ export class HaStateLabelBadge extends LitElement {
? ""
: this.image
? this.image
: state.attributes.entity_picture_local || state.attributes.entity_picture}"
: state.attributes.entity_picture_local ||
state.attributes.entity_picture}"
.label="${this._computeLabel(domain, state, this._timerTimeRemaining)}"
.description="${this.name ? this.name : computeStateName(state)}"
></ha-label-badge>
@@ -108,7 +110,7 @@ export class HaStateLabelBadge extends LitElement {
return null;
case "sensor":
default:
return state.state === "unknown"
return state.state === UNKNOWN
? "-"
: state.attributes.unit_of_measurement
? state.state
@@ -121,7 +123,7 @@ export class HaStateLabelBadge extends LitElement {
}
private _computeIcon(domain: string, state: HassEntity) {
if (state.state === "unavailable") {
if (state.state === UNAVAILABLE) {
return null;
}
switch (domain) {
@@ -166,7 +168,7 @@ export class HaStateLabelBadge extends LitElement {
private _computeLabel(domain, state, _timerTimeRemaining) {
if (
state.state === "unavailable" ||
state.state === UNAVAILABLE ||
["device_tracker", "alarm_control_panel", "person"].includes(domain)
) {
// Localize the state with a special state_badge namespace, which has variations of