File tree Expand file tree Collapse file tree 2 files changed +18
-34
lines changed Expand file tree Collapse file tree 2 files changed +18
-34
lines changed Original file line number Diff line number Diff line change @@ -29,20 +29,12 @@ async function fetchStates(
2929 minimal_response_query +
3030 `end_time=${ end . toISOString ( ) } ` ;
3131 let list : History | undefined ;
32- let succeeded = false ;
33- let retries = 0 ;
34- while ( ! succeeded ) {
35- try {
36- const lists : History [ ] = ( await hass . callApi ( "GET" , uri ) ) || [ ] ;
37- list = lists [ 0 ] ;
38- succeeded = true ;
39- } catch ( e : any ) {
40- console . error ( e ) ;
41- retries ++ ;
42- if ( retries > 5 )
43- throw new Error ( `Error fetching ${ entity . entity } : ${ e . msg } ` ) ;
44- await sleep ( 100 ) ;
45- }
32+ try {
33+ const lists : History [ ] = ( await hass . callApi ( "GET" , uri ) ) || [ ] ;
34+ list = lists [ 0 ] ;
35+ } catch ( e : any ) {
36+ console . error ( e ) ;
37+ throw new Error ( `Error fetching ${ entity . entity } : ${ e . msg } ` ) ;
4638 }
4739 if ( ! list ) list = [ ] ; //throw new Error(`Error fetching ${entity.entity}`); // shutup typescript
4840 return {
Original file line number Diff line number Diff line change @@ -9,26 +9,18 @@ async function fetchStatistics(
99 [ start , end ] : [ Date , Date ]
1010) : Promise < HistoryInRange > {
1111 let statistics : StatisticValue [ ] | null = null ;
12- let succeeded = false ;
13- let retries = 0 ;
14- while ( ! succeeded ) {
15- try {
16- const statsP = hass . callWS < Statistics > ( {
17- type : "recorder/statistics_during_period" ,
18- start_time : start . toISOString ( ) ,
19- end_time : end . toISOString ( ) ,
20- statistic_ids : [ entity . entity ] ,
21- period : entity . period ,
22- } ) ;
23- statistics = ( await statsP ) [ entity . entity ] ;
24- succeeded = true ;
25- } catch ( e : any ) {
26- console . error ( e ) ;
27- retries ++ ;
28- if ( retries > 5 )
29- throw new Error ( `Error fetching ${ entity . entity } : ${ e . msg } ` ) ;
30- await sleep ( 100 ) ;
31- }
12+ try {
13+ const statsP = hass . callWS < Statistics > ( {
14+ type : "recorder/statistics_during_period" ,
15+ start_time : start . toISOString ( ) ,
16+ end_time : end . toISOString ( ) ,
17+ statistic_ids : [ entity . entity ] ,
18+ period : entity . period ,
19+ } ) ;
20+ statistics = ( await statsP ) [ entity . entity ] ;
21+ } catch ( e : any ) {
22+ console . error ( e ) ;
23+ throw new Error ( `Error fetching ${ entity . entity } : ${ e . msg } ` ) ;
3224 }
3325 if ( ! statistics ) statistics = [ ] ; //throw new Error(`Error fetching ${entity.entity}`);
3426 return {
You can’t perform that action at this time.
0 commit comments