mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 09:46:36 +00:00
Fixes state history colors edge cases (#14626)
This commit is contained in:
parent
d1b1eecd92
commit
0d0028fced
@ -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";
|
||||
}
|
||||
|
@ -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:
|
||||
|
@ -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;
|
||||
|
@ -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";
|
||||
|
Loading…
x
Reference in New Issue
Block a user