mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +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 = (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";
|
||||||
}
|
}
|
||||||
|
@ -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:
|
||||||
|
@ -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;
|
||||||
|
@ -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";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user