File tree Expand file tree Collapse file tree 3 files changed +11
-22
lines changed Expand file tree Collapse file tree 3 files changed +11
-22
lines changed Original file line number Diff line number Diff line change 1- import type { Condition } from "../../panels/lovelace/common/validate-condition" ;
1+ import type {
2+ Condition ,
3+ TimeCondition ,
4+ } from "../../panels/lovelace/common/validate-condition" ;
25
36/**
47 * Extract media queries from conditions recursively
@@ -20,19 +23,13 @@ export function extractMediaQueries(conditions: Condition[]): string[] {
2023 */
2124export function extractTimeConditions (
2225 conditions : Condition [ ]
23- ) : { after ?: string ; before ?: string ; weekdays ?: string [ ] } [ ] {
24- return conditions . reduce <
25- { after ?: string ; before ?: string ; weekdays ?: string [ ] } [ ]
26- > ( ( array , c ) => {
26+ ) : TimeCondition [ ] {
27+ return conditions . reduce < TimeCondition [ ] > ( ( array , c ) => {
2728 if ( "conditions" in c && c . conditions ) {
2829 array . push ( ...extractTimeConditions ( c . conditions ) ) ;
2930 }
3031 if ( c . condition === "time" ) {
31- array . push ( {
32- after : c . after ,
33- before : c . before ,
34- weekdays : c . weekdays ,
35- } ) ;
32+ array . push ( c ) ;
3633 }
3734 return array ;
3835 } , [ ] ) ;
Original file line number Diff line number Diff line change @@ -52,12 +52,7 @@ export function setupTimeListeners(
5252
5353 timeConditions . forEach ( ( timeCondition ) => {
5454 const scheduleUpdate = ( ) => {
55- const delay = calculateNextTimeUpdate (
56- hass ,
57- timeCondition . after ,
58- timeCondition . before ,
59- timeCondition . weekdays
60- ) ;
55+ const delay = calculateNextTimeUpdate ( hass , timeCondition ) ;
6156
6257 if ( delay === undefined ) return ;
6358
Original file line number Diff line number Diff line change @@ -8,20 +8,17 @@ import {
88import type { HomeAssistant } from "../../types" ;
99import { TimeZone } from "../../data/translation" ;
1010import { parseTimeString } from "../datetime/check_time" ;
11+ import type { TimeCondition } from "../../panels/lovelace/common/validate-condition" ;
1112
1213/**
1314 * Calculate milliseconds until next time boundary for a time condition
1415 * @param hass Home Assistant object
15- * @param after Optional time string (HH:MM) for after condition
16- * @param before Optional time string (HH:MM) for before condition
17- * @param weekdays Optional array of weekdays to match
16+ * @param timeCondition Time condition to calculate next update for
1817 * @returns Milliseconds until next boundary, or undefined if no boundaries
1918 */
2019export function calculateNextTimeUpdate (
2120 hass : HomeAssistant ,
22- after ?: string ,
23- before ?: string ,
24- weekdays ?: string [ ]
21+ { after, before, weekdays } : TimeCondition
2522) : number | undefined {
2623 const timezone =
2724 hass . locale . time_zone === TimeZone . server
You can’t perform that action at this time.
0 commit comments