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 = (stateObj: HassEntity) => {
const value = Number(stateObj.state);
export const batteryStateColor = (state: string) => {
const value = Number(state);
if (isNaN(value)) {
return "sensor-battery-unknown";
}

View File

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

View File

@ -1,11 +1,14 @@
import { HassEntity } from "home-assistant-js-websocket";
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;
if (deviceClass === "battery") {
return batteryStateColor(stateObj);
return batteryStateColor(compareState);
}
return undefined;

View File

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