mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Handle "idle" state of alert entity (#14779)
This commit is contained in:
parent
25a5bd568a
commit
b4d6fc3c20
@ -106,6 +106,7 @@ const ENTITIES: HassEntity[] = [
|
|||||||
// Alert
|
// Alert
|
||||||
createEntity("alert.off", "off"),
|
createEntity("alert.off", "off"),
|
||||||
createEntity("alert.on", "on"),
|
createEntity("alert.on", "on"),
|
||||||
|
createEntity("alert.idle", "idle"),
|
||||||
// Automation
|
// Automation
|
||||||
createEntity("automation.off", "off"),
|
createEntity("automation.off", "off"),
|
||||||
createEntity("automation.on", "on"),
|
createEntity("automation.on", "on"),
|
||||||
|
10
src/common/entity/color/alert_color.ts
Normal file
10
src/common/entity/color/alert_color.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
export const alertColor = (state?: string): string | undefined => {
|
||||||
|
switch (state) {
|
||||||
|
case "on":
|
||||||
|
return "alert";
|
||||||
|
case "off":
|
||||||
|
return "alert-off";
|
||||||
|
default:
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
};
|
@ -1,5 +1,5 @@
|
|||||||
import { HassEntity } from "home-assistant-js-websocket";
|
import { HassEntity } from "home-assistant-js-websocket";
|
||||||
import { OFF_STATES, UNAVAILABLE } from "../../data/entity";
|
import { OFF, UNAVAILABLE, UNAVAILABLE_STATES } from "../../data/entity";
|
||||||
import { computeDomain } from "./compute_domain";
|
import { computeDomain } from "./compute_domain";
|
||||||
|
|
||||||
export function stateActive(stateObj: HassEntity, state?: string): boolean {
|
export function stateActive(stateObj: HassEntity, state?: string): boolean {
|
||||||
@ -10,7 +10,15 @@ export function stateActive(stateObj: HassEntity, state?: string): boolean {
|
|||||||
return compareState !== UNAVAILABLE;
|
return compareState !== UNAVAILABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (OFF_STATES.includes(compareState)) {
|
if (UNAVAILABLE_STATES.includes(compareState)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The "off" check is relevant for most domains, but there are exceptions
|
||||||
|
// such as "alert" where "off" is still a somewhat active state and
|
||||||
|
// therefore gets a custom color and "idle" is instead the state that
|
||||||
|
// matches what most other domains consider inactive.
|
||||||
|
if (compareState === OFF && domain !== "alert") {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,6 +26,9 @@ export function stateActive(stateObj: HassEntity, state?: string): boolean {
|
|||||||
switch (domain) {
|
switch (domain) {
|
||||||
case "alarm_control_panel":
|
case "alarm_control_panel":
|
||||||
return compareState !== "disarmed";
|
return compareState !== "disarmed";
|
||||||
|
case "alert":
|
||||||
|
// "on" and "off" are active, as "off" just means alert was acknowledged but is still active
|
||||||
|
return compareState !== "idle";
|
||||||
case "cover":
|
case "cover":
|
||||||
return !["closed", "closing"].includes(compareState);
|
return !["closed", "closing"].includes(compareState);
|
||||||
case "device_tracker":
|
case "device_tracker":
|
||||||
@ -37,7 +48,7 @@ export function stateActive(stateObj: HassEntity, state?: string): boolean {
|
|||||||
return compareState === "active";
|
return compareState === "active";
|
||||||
case "camera":
|
case "camera":
|
||||||
return compareState === "streaming";
|
return compareState === "streaming";
|
||||||
default:
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
import { HassEntity } from "home-assistant-js-websocket";
|
import { HassEntity } from "home-assistant-js-websocket";
|
||||||
import { UNAVAILABLE } from "../../data/entity";
|
import { UNAVAILABLE } from "../../data/entity";
|
||||||
import { alarmControlPanelColor } from "./color/alarm_control_panel_color";
|
import { alarmControlPanelColor } from "./color/alarm_control_panel_color";
|
||||||
|
import { alertColor } from "./color/alert_color";
|
||||||
import { binarySensorColor } from "./color/binary_sensor_color";
|
import { binarySensorColor } from "./color/binary_sensor_color";
|
||||||
import { climateColor } from "./color/climate_color";
|
import { climateColor } from "./color/climate_color";
|
||||||
import { lockColor } from "./color/lock_color";
|
import { lockColor } from "./color/lock_color";
|
||||||
@ -12,7 +13,6 @@ import { computeDomain } from "./compute_domain";
|
|||||||
import { stateActive } from "./state_active";
|
import { stateActive } from "./state_active";
|
||||||
|
|
||||||
const STATIC_ACTIVE_COLORED_DOMAIN = new Set([
|
const STATIC_ACTIVE_COLORED_DOMAIN = new Set([
|
||||||
"alert",
|
|
||||||
"automation",
|
"automation",
|
||||||
"calendar",
|
"calendar",
|
||||||
"camera",
|
"camera",
|
||||||
@ -65,6 +65,9 @@ export const stateColor = (stateObj: HassEntity, state?: string) => {
|
|||||||
case "alarm_control_panel":
|
case "alarm_control_panel":
|
||||||
return alarmControlPanelColor(compareState);
|
return alarmControlPanelColor(compareState);
|
||||||
|
|
||||||
|
case "alert":
|
||||||
|
return alertColor(compareState);
|
||||||
|
|
||||||
case "binary_sensor":
|
case "binary_sensor":
|
||||||
return binarySensorColor(stateObj, compareState);
|
return binarySensorColor(stateObj, compareState);
|
||||||
|
|
||||||
|
@ -145,6 +145,7 @@ documentContainer.innerHTML = `<custom-style>
|
|||||||
--rgb-state-alarm-pending-color: var(--rgb-orange-color);
|
--rgb-state-alarm-pending-color: var(--rgb-orange-color);
|
||||||
--rgb-state-alarm-triggered-color: var(--rgb-red-color);
|
--rgb-state-alarm-triggered-color: var(--rgb-red-color);
|
||||||
--rgb-state-alert-color: var(--rgb-red-color);
|
--rgb-state-alert-color: var(--rgb-red-color);
|
||||||
|
--rgb-state-alert-off-color: var(--rgb-orange-color);
|
||||||
--rgb-state-automation-color: var(--rgb-amber-color);
|
--rgb-state-automation-color: var(--rgb-amber-color);
|
||||||
--rgb-state-binary-sensor-alerting-color: var(--rgb-red-color);
|
--rgb-state-binary-sensor-alerting-color: var(--rgb-red-color);
|
||||||
--rgb-state-binary-sensor-color: var(--rgb-amber-color);
|
--rgb-state-binary-sensor-color: var(--rgb-amber-color);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user