Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow not_set value for timestamp device class #10006

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/data/sensor.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
import { UNAVAILABLE_STATES } from "./entity";

export const SENSOR_DEVICE_CLASS_BATTERY = "battery";
export const SENSOR_DEVICE_CLASS_TIMESTAMP = "timestamp";
export const NOT_SET = "not_set";
export const VALID_TIMESTAMP_STATES = UNAVAILABLE_STATES.concat([NOT_SET]);
8 changes: 5 additions & 3 deletions src/panels/lovelace/cards/hui-glance-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ import { computeStateName } from "../../../common/entity/compute_state_name";
import "../../../components/entity/state-badge";
import "../../../components/ha-card";
import "../../../components/ha-icon";
import { UNAVAILABLE_STATES } from "../../../data/entity";
import {
ActionHandlerEvent,
CallServiceActionConfig,
MoreInfoActionConfig,
} from "../../../data/lovelace";
import { SENSOR_DEVICE_CLASS_TIMESTAMP } from "../../../data/sensor";
import {
SENSOR_DEVICE_CLASS_TIMESTAMP,
VALID_TIMESTAMP_STATES,
} 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 @@ -319,7 +321,7 @@ export class HuiGlanceCard extends LitElement implements LovelaceCard {
${computeDomain(entityConf.entity) === "sensor" &&
stateObj.attributes.device_class ===
SENSOR_DEVICE_CLASS_TIMESTAMP &&
!UNAVAILABLE_STATES.includes(stateObj.state)
!VALID_TIMESTAMP_STATES.includes(stateObj.state)
? html`
<hui-timestamp-display
.hass=${this.hass}
Expand Down
8 changes: 5 additions & 3 deletions src/panels/lovelace/entity-rows/hui-sensor-entity-row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import {
} from "lit";
import { customElement, property, state } from "lit/decorators";
import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import { UNAVAILABLE_STATES } from "../../../data/entity";
import { ActionHandlerEvent } from "../../../data/lovelace";
import { SENSOR_DEVICE_CLASS_TIMESTAMP } from "../../../data/sensor";
import {
SENSOR_DEVICE_CLASS_TIMESTAMP,
VALID_TIMESTAMP_STATES,
} from "../../../data/sensor";
import { HomeAssistant } from "../../../types";
import { EntitiesCardEntityConfig } from "../cards/types";
import { actionHandler } from "../common/directives/action-handler-directive";
Expand Down Expand Up @@ -71,7 +73,7 @@ class HuiSensorEntityRow extends LitElement implements LovelaceRow {
>
${stateObj.attributes.device_class ===
SENSOR_DEVICE_CLASS_TIMESTAMP &&
!UNAVAILABLE_STATES.includes(stateObj.state)
!VALID_TIMESTAMP_STATES.includes(stateObj.state)
? html`
<hui-timestamp-display
.hass=${this.hass}
Expand Down
8 changes: 5 additions & 3 deletions src/state-summary/state-card-display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import { computeDomain } from "../common/entity/compute_domain";
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 {
SENSOR_DEVICE_CLASS_TIMESTAMP,
VALID_TIMESTAMP_STATES,
} from "../data/sensor";
import "../panels/lovelace/components/hui-timestamp-display";
import { haStyle } from "../resources/styles";
import type { HomeAssistant } from "../types";
Expand Down Expand Up @@ -42,7 +44,7 @@ export class StateCardDisplay extends LitElement {
${computeDomain(this.stateObj.entity_id) === "sensor" &&
this.stateObj.attributes.device_class ===
SENSOR_DEVICE_CLASS_TIMESTAMP &&
!UNAVAILABLE_STATES.includes(this.stateObj.state)
!VALID_TIMESTAMP_STATES.includes(this.stateObj.state)
? html` <hui-timestamp-display
.hass=${this.hass}
.ts=${new Date(this.stateObj.state)}
Expand Down