Fixes state history colors edge cases (#14626)

This commit is contained in:
Paul Bottein 2022-12-08 12:01:18 +01:00 committed by GitHub
parent d1b1eecd92
commit 0d0028fced
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 12 deletions

View File

@ -1,7 +1,5 @@
import { HassEntity } from "home-assistant-js-websocket"; export const batteryStateColor = (state: string) => {
const value = Number(state);
export const batteryStateColor = (stateObj: HassEntity) => {
const value = Number(stateObj.state);
if (isNaN(value)) { if (isNaN(value)) {
return "sensor-battery-unknown"; return "sensor-battery-unknown";
} }

View File

@ -1,7 +1,5 @@
import { HassEntity } from "home-assistant-js-websocket"; export const personColor = (state: string): string | undefined => {
switch (state) {
export const personColor = (stateObj: HassEntity): string | undefined => {
switch (stateObj.state) {
case "home": case "home":
return "person-home"; return "person-home";
default: default:

View File

@ -1,11 +1,14 @@
import { HassEntity } from "home-assistant-js-websocket"; import { HassEntity } from "home-assistant-js-websocket";
import { batteryStateColor } from "./battery_color"; import { batteryStateColor } from "./battery_color";
export const sensorColor = (stateObj: HassEntity): string | undefined => { export const sensorColor = (
stateObj: HassEntity,
compareState: string
): string | undefined => {
const deviceClass = stateObj?.attributes.device_class; const deviceClass = stateObj?.attributes.device_class;
if (deviceClass === "battery") { if (deviceClass === "battery") {
return batteryStateColor(stateObj); return batteryStateColor(compareState);
} }
return undefined; return undefined;

View File

@ -67,10 +67,10 @@ export const stateColor = (stateObj: HassEntity, state?: string) => {
case "person": case "person":
case "device_tracker": case "device_tracker":
return personColor(stateObj); return personColor(compareState);
case "sensor": case "sensor":
return sensorColor(stateObj); return sensorColor(stateObj, compareState);
case "sun": case "sun":
return compareState === "above_horizon" ? "sun-day" : "sun-night"; return compareState === "above_horizon" ? "sun-day" : "sun-night";