mirror of
https://github.com/home-assistant/frontend.git
synced 2025-11-27 19:57:24 +00:00
* Add time-based conditional visibility for cards * Move clearTimeout outside of scheduleUpdate * Add time string validation * Add time string validation * Remove runtime validation as config shouldnt allow bad values * Fix for midnight crossing * Cap timeout to 32-bit signed integer * Add listener tests * Additional tests * Format
37 lines
929 B
TypeScript
37 lines
929 B
TypeScript
import type {
|
|
Condition,
|
|
TimeCondition,
|
|
} from "../../panels/lovelace/common/validate-condition";
|
|
|
|
/**
|
|
* Extract media queries from conditions recursively
|
|
*/
|
|
export function extractMediaQueries(conditions: Condition[]): string[] {
|
|
return conditions.reduce<string[]>((array, c) => {
|
|
if ("conditions" in c && c.conditions) {
|
|
array.push(...extractMediaQueries(c.conditions));
|
|
}
|
|
if (c.condition === "screen" && c.media_query) {
|
|
array.push(c.media_query);
|
|
}
|
|
return array;
|
|
}, []);
|
|
}
|
|
|
|
/**
|
|
* Extract time conditions from conditions recursively
|
|
*/
|
|
export function extractTimeConditions(
|
|
conditions: Condition[]
|
|
): TimeCondition[] {
|
|
return conditions.reduce<TimeCondition[]>((array, c) => {
|
|
if ("conditions" in c && c.conditions) {
|
|
array.push(...extractTimeConditions(c.conditions));
|
|
}
|
|
if (c.condition === "time") {
|
|
array.push(c);
|
|
}
|
|
return array;
|
|
}, []);
|
|
}
|