@@ -76,6 +76,8 @@ async function fetchSingleRange(
7676 // ^ ^
7777 // | '--- discarded as it is fictitious
7878 // '--- point at the edge, kept
79+ //
80+ // The above does not apply to statistics data where there are no fake data points.
7981
8082 const l = Math . max ( 0 , 5000 - ( endT - startT ) ) ; // The HA API doesn't add the fake boundary if the interval requested is too small
8183 const start = new Date ( startT - 1 - l ) ;
@@ -86,12 +88,12 @@ async function fetchSingleRange(
8688 history = await fetchStatistics ( hass , entity , [ start , end ] ) ;
8789 } else {
8890 history = await fetchStates ( hass , entity , [ start , end ] ) ;
91+ if ( history . length ) {
92+ history [ 0 ] . fake_boundary_datapoint = true ;
93+ }
8994 }
9095
9196 let range : [ number , number ] = [ startT , endT ] ;
92- if ( history . length ) {
93- history [ 0 ] . fake_boundary_datapoint = true ;
94- }
9597 return {
9698 range,
9799 history,
@@ -120,7 +122,9 @@ export default class Cache {
120122 let h = ( this . histories [ entityKey ] ??= [ ] ) ;
121123 h . push ( ...states ) ;
122124 h . sort ( ( a , b ) => + a . x - + b . x ) ;
123- h = h . filter ( ( x , i ) => i == 0 || ! x . fake_boundary_datapoint ) ;
125+ if ( ! isEntityIdStatisticsConfig ( entity ) ) {
126+ h = h . filter ( ( x , i ) => i == 0 || ! x . fake_boundary_datapoint ) ;
127+ }
124128 h = h . filter ( ( _ , i ) => + h [ i - 1 ] ?. x !== + h [ i ] . x ) ;
125129 this . histories [ entityKey ] = h ;
126130 this . ranges [ entityKey ] ??= [ ] ;
0 commit comments