badge warning (#3009)

This commit is contained in:
Ian Richardson 2019-03-25 09:40:04 -05:00 committed by Paulus Schoutsen
parent 324f0bb8a2
commit 9a2207b5cb
2 changed files with 60 additions and 59 deletions

View File

@ -2,11 +2,17 @@ import {
LitElement, LitElement,
html, html,
PropertyValues, PropertyValues,
PropertyDeclarations,
TemplateResult, TemplateResult,
css,
CSSResult,
customElement,
property,
} from "lit-element"; } from "lit-element";
import { HassEntity } from "home-assistant-js-websocket"; import { HassEntity } from "home-assistant-js-websocket";
import { classMap } from "lit-html/directives/class-map"; import { classMap } from "lit-html/directives/class-map";
import { fireEvent } from "../../common/dom/fire_event";
import { HomeAssistant } from "../../types";
import computeStateDomain from "../../common/entity/compute_state_domain"; import computeStateDomain from "../../common/entity/compute_state_domain";
import computeStateName from "../../common/entity/compute_state_name"; import computeStateName from "../../common/entity/compute_state_name";
@ -14,21 +20,20 @@ import domainIcon from "../../common/entity/domain_icon";
import stateIcon from "../../common/entity/state_icon"; import stateIcon from "../../common/entity/state_icon";
import timerTimeRemaining from "../../common/entity/timer_time_remaining"; import timerTimeRemaining from "../../common/entity/timer_time_remaining";
import secondsToDuration from "../../common/datetime/seconds_to_duration"; import secondsToDuration from "../../common/datetime/seconds_to_duration";
import { fireEvent } from "../../common/dom/fire_event";
import { HomeAssistant } from "../../types";
import "../ha-label-badge"; import "../ha-label-badge";
/* @customElement("ha-state-label-badge")
* @appliesMixin LocalizeMixin
* @appliesMixin EventsMixin
*/
export class HaStateLabelBadge extends LitElement { export class HaStateLabelBadge extends LitElement {
public hass?: HomeAssistant; @property() public hass?: HomeAssistant;
public state?: HassEntity;
@property() public state?: HassEntity;
@property() private _timerTimeRemaining?: number;
private _connected?: boolean; private _connected?: boolean;
private _updateRemaining?: number; private _updateRemaining?: number;
private _timerTimeRemaining?: number;
public connectedCallback(): void { public connectedCallback(): void {
super.connectedCallback(); super.connectedCallback();
@ -47,15 +52,20 @@ export class HaStateLabelBadge extends LitElement {
if (!state) { if (!state) {
return html` return html`
${this.renderStyle()} <ha-label-badge
<ha-label-badge label="not found"></ha-label-badge> class="warning"
label="${this.hass!.localize("state_badge.default.error")}"
icon="hass:alert"
description="${this.hass!.localize(
"state_badge.default.entity_not_found"
)}"
></ha-label-badge>
`; `;
} }
const domain = computeStateDomain(state); const domain = computeStateDomain(state);
return html` return html`
${this.renderStyle()}
<ha-label-badge <ha-label-badge
class="${classMap({ class="${classMap({
[domain]: true, [domain]: true,
@ -70,14 +80,6 @@ export class HaStateLabelBadge extends LitElement {
`; `;
} }
static get properties(): PropertyDeclarations {
return {
hass: {},
state: {},
_timerTimeRemaining: {},
};
}
protected firstUpdated(changedProperties: PropertyValues): void { protected firstUpdated(changedProperties: PropertyValues): void {
super.firstUpdated(changedProperties); super.firstUpdated(changedProperties);
this.addEventListener("click", (ev) => { this.addEventListener("click", (ev) => {
@ -201,48 +203,47 @@ export class HaStateLabelBadge extends LitElement {
this._timerTimeRemaining = timerTimeRemaining(stateObj); this._timerTimeRemaining = timerTimeRemaining(stateObj);
} }
private renderStyle(): TemplateResult { static get styles(): CSSResult {
return html` return css`
<style> :host {
:host { cursor: pointer;
cursor: pointer; }
}
ha-label-badge { ha-label-badge {
--ha-label-badge-color: var(--label-badge-red, #df4c1e); --ha-label-badge-color: var(--label-badge-red, #df4c1e);
} }
ha-label-badge.has-unit_of_measurement { ha-label-badge.has-unit_of_measurement {
--ha-label-badge-label-text-transform: none; --ha-label-badge-label-text-transform: none;
} }
ha-label-badge.binary_sensor, ha-label-badge.binary_sensor,
ha-label-badge.updater { ha-label-badge.updater {
--ha-label-badge-color: var(--label-badge-blue, #039be5); --ha-label-badge-color: var(--label-badge-blue, #039be5);
} }
.red { .red {
--ha-label-badge-color: var(--label-badge-red, #df4c1e); --ha-label-badge-color: var(--label-badge-red, #df4c1e);
} }
.blue { .blue {
--ha-label-badge-color: var(--label-badge-blue, #039be5); --ha-label-badge-color: var(--label-badge-blue, #039be5);
} }
.green { .green {
--ha-label-badge-color: var(--label-badge-green, #0da035); --ha-label-badge-color: var(--label-badge-green, #0da035);
} }
.yellow { .yellow {
--ha-label-badge-color: var(--label-badge-yellow, #f4b400); --ha-label-badge-color: var(--label-badge-yellow, #f4b400);
} }
.grey { .grey {
--ha-label-badge-color: var( --ha-label-badge-color: var(--label-badge-grey, var(--paper-grey-500));
--label-badge-grey, }
var(--paper-grey-500)
); .warning {
} --ha-label-badge-color: var(--label-badge-yellow, #fce588);
</style> }
`; `;
} }
} }
@ -252,5 +253,3 @@ declare global {
"ha-state-label-badge": HaStateLabelBadge; "ha-state-label-badge": HaStateLabelBadge;
} }
} }
customElements.define("ha-state-label-badge", HaStateLabelBadge);

View File

@ -332,7 +332,9 @@
"state_badge": { "state_badge": {
"default": { "default": {
"unknown": "Unk", "unknown": "Unk",
"unavailable": "Unavai" "unavailable": "Unavai",
"error": "Error",
"entity_not_found": "Entity Not Found"
}, },
"alarm_control_panel": { "alarm_control_panel": {
"armed": "Armed", "armed": "Armed",