mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 19:26:36 +00:00
Use SENSOR_DEVICE_CLASS_* constants more (#9982)
This commit is contained in:
parent
b3dedae115
commit
6ba6b821f5
@ -2,6 +2,7 @@
|
||||
import { HassEntity } from "home-assistant-js-websocket";
|
||||
import { FIXED_DEVICE_CLASS_ICONS, UNIT_C, UNIT_F } from "../const";
|
||||
import { batteryIcon } from "./battery_icon";
|
||||
import { SENSOR_DEVICE_CLASS_BATTERY } from "../../data/sensor";
|
||||
|
||||
export const sensorIcon = (stateObj?: HassEntity): string | undefined => {
|
||||
const dclass = stateObj?.attributes.device_class;
|
||||
@ -10,7 +11,7 @@ export const sensorIcon = (stateObj?: HassEntity): string | undefined => {
|
||||
return FIXED_DEVICE_CLASS_ICONS[dclass];
|
||||
}
|
||||
|
||||
if (dclass === "battery") {
|
||||
if (dclass === SENSOR_DEVICE_CLASS_BATTERY) {
|
||||
return stateObj ? batteryIcon(stateObj) : "hass:battery";
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@ import {
|
||||
CallServiceActionConfig,
|
||||
MoreInfoActionConfig,
|
||||
} from "../../../data/lovelace";
|
||||
import { SENSOR_DEVICE_CLASS_TIMESTAMP } from "../../../data/sensor";
|
||||
import { HomeAssistant } from "../../../types";
|
||||
import { actionHandler } from "../common/directives/action-handler-directive";
|
||||
import { findEntities } from "../common/find-entities";
|
||||
@ -316,7 +317,8 @@ export class HuiGlanceCard extends LitElement implements LovelaceCard {
|
||||
? html`
|
||||
<div>
|
||||
${computeDomain(entityConf.entity) === "sensor" &&
|
||||
stateObj.attributes.device_class === "timestamp" &&
|
||||
stateObj.attributes.device_class ===
|
||||
SENSOR_DEVICE_CLASS_TIMESTAMP &&
|
||||
!UNAVAILABLE_STATES.includes(stateObj.state)
|
||||
? html`
|
||||
<hui-timestamp-display
|
||||
|
@ -8,6 +8,7 @@ import { computeStateDisplay } from "../common/entity/compute_state_display";
|
||||
import { computeRTL } from "../common/util/compute_rtl";
|
||||
import "../components/entity/state-info";
|
||||
import { UNAVAILABLE_STATES } from "../data/entity";
|
||||
import { SENSOR_DEVICE_CLASS_TIMESTAMP } from "../data/sensor";
|
||||
import "../panels/lovelace/components/hui-timestamp-display";
|
||||
import { haStyle } from "../resources/styles";
|
||||
import type { HomeAssistant } from "../types";
|
||||
@ -39,7 +40,8 @@ export class StateCardDisplay extends LitElement {
|
||||
})}"
|
||||
>
|
||||
${computeDomain(this.stateObj.entity_id) === "sensor" &&
|
||||
this.stateObj.attributes.device_class === "timestamp" &&
|
||||
this.stateObj.attributes.device_class ===
|
||||
SENSOR_DEVICE_CLASS_TIMESTAMP &&
|
||||
!UNAVAILABLE_STATES.includes(this.stateObj.state)
|
||||
? html` <hui-timestamp-display
|
||||
.hass=${this.hass}
|
||||
|
Loading…
x
Reference in New Issue
Block a user