Add additional binary device classes to inversion list (#10152)

This commit is contained in:
Philip Allgaier 2021-10-16 14:49:57 +02:00 committed by GitHub
parent 825ea93dba
commit 588f5bd6b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,22 +12,19 @@ import { HomeAssistant } from "../../types";
import "./ha-chart-base";
import type { TimeLineData } from "./timeline-chart/const";
/** Binary sensor device classes for which the static colors for on/off need to be inverted.
* List the ones were "off" = good or normal state = should be rendered "green".
/** Binary sensor device classes for which the static colors for on/off are NOT inverted.
* List the ones were "on" = good or normal state => should be rendered "green".
* Note: It is now a "not inverted" list (compared to the past) since we now have more inverted ones.
*/
const BINARY_SENSOR_DEVICE_CLASS_COLOR_INVERTED = new Set([
"battery",
"door",
"garage_door",
"gas",
"lock",
"motion",
"opening",
"problem",
"safety",
"smoke",
"tamper",
"window",
const BINARY_SENSOR_DEVICE_CLASS_COLOR_NOT_INVERTED = new Set([
"battery_charging",
"connectivity",
"light",
"moving",
"plug",
"power",
"presence",
"update",
]);
const STATIC_STATE_COLORS = new Set([
@ -48,7 +45,7 @@ const invertOnOff = (entityState?: HassEntity) =>
entityState &&
computeDomain(entityState.entity_id) === "binary_sensor" &&
"device_class" in entityState.attributes &&
BINARY_SENSOR_DEVICE_CLASS_COLOR_INVERTED.has(
!BINARY_SENSOR_DEVICE_CLASS_COLOR_NOT_INVERTED.has(
entityState.attributes.device_class!
);