Skip to content

Commit

Permalink
Use SENSOR_DEVICE_CLASS_* constants more
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed Sep 7, 2021
1 parent b3dedae commit cf75353
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/common/entity/sensor_icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
}

Expand Down
3 changes: 2 additions & 1 deletion src/panels/lovelace/cards/hui-glance-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -316,7 +317,7 @@ 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
Expand Down
3 changes: 2 additions & 1 deletion src/state-summary/state-card-display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -39,7 +40,7 @@ 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}
Expand Down

0 comments on commit cf75353

Please sign in to comment.