mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Fix entity active states (#14341)
* fix media player state * Fix active states * Consider idle media player as active * improve custom cases
This commit is contained in:
parent
185d2f1d52
commit
c6386284d1
@ -1,33 +1,30 @@
|
|||||||
import { HassEntity } from "home-assistant-js-websocket";
|
import { HassEntity } from "home-assistant-js-websocket";
|
||||||
import { OFF_STATES } from "../../data/entity";
|
import { OFF_STATES, UNAVAILABLE } from "../../data/entity";
|
||||||
import { computeDomain } from "./compute_domain";
|
import { computeDomain } from "./compute_domain";
|
||||||
|
|
||||||
const NORMAL_UNKNOWN_DOMAIN = ["button", "input_button", "scene"];
|
|
||||||
const NORMAL_OFF_DOMAIN = ["script"];
|
|
||||||
|
|
||||||
export function stateActive(stateObj: HassEntity, state?: string): boolean {
|
export function stateActive(stateObj: HassEntity, state?: string): boolean {
|
||||||
const domain = computeDomain(stateObj.entity_id);
|
const domain = computeDomain(stateObj.entity_id);
|
||||||
const compareState = state !== undefined ? state : stateObj?.state;
|
const compareState = state !== undefined ? state : stateObj?.state;
|
||||||
|
|
||||||
if (
|
if (["button", "input_button", "scene"].includes(domain)) {
|
||||||
OFF_STATES.includes(compareState) &&
|
return compareState !== UNAVAILABLE;
|
||||||
!(NORMAL_UNKNOWN_DOMAIN.includes(domain) && compareState === "unknown") &&
|
}
|
||||||
!(NORMAL_OFF_DOMAIN.includes(domain) && compareState === "script")
|
|
||||||
) {
|
if (OFF_STATES.includes(compareState)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Custom cases
|
// Custom cases
|
||||||
switch (domain) {
|
switch (domain) {
|
||||||
case "cover":
|
case "cover":
|
||||||
return compareState === "open" || compareState === "opening";
|
return !["close", "closing"].includes(compareState);
|
||||||
case "device_tracker":
|
case "device_tracker":
|
||||||
case "person":
|
case "person":
|
||||||
return compareState !== "not_home";
|
return compareState !== "not_home";
|
||||||
case "media-player":
|
case "media_player":
|
||||||
return compareState !== "idle" && compareState !== "standby";
|
return compareState !== "standby";
|
||||||
case "vacuum":
|
case "vacuum":
|
||||||
return compareState === "on" || compareState === "cleaning";
|
return !["idle", "docked", "paused"].includes(compareState);
|
||||||
case "plant":
|
case "plant":
|
||||||
return compareState === "problem";
|
return compareState === "problem";
|
||||||
default:
|
default:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user