@@ -615,7 +615,7 @@ SMAHomeManager.prototype = {
615
615
. then ( ( producedWatts ) => {
616
616
const estimatedMsOffset = performance . now ( ) - before ;
617
617
const [ timestamp , netWatts ] = this . _parseDatagram ( msg , rinfo ) ;
618
- this . _processMeasurement ( producedWatts , netWatts , timestamp ) ;
618
+ this . _processMeasurement ( producedWatts , netWatts , timestamp , estimatedMsOffset ) ;
619
619
} )
620
620
} . bind ( this ) ) ;
621
621
@@ -628,7 +628,7 @@ SMAHomeManager.prototype = {
628
628
// 2. Updates HomeKit.
629
629
//
630
630
// (Should be called in regular intervals, 1 s assumed.)
631
- _processMeasurement : function ( producedWattsFromInverter , netWattsFromEnergyManager , timestampFromEnergyManager ) {
631
+ _processMeasurement : function ( producedWattsFromInverter , netWattsFromEnergyManager , timestampFromEnergyManager , estimatedMsOffsetInverter ) {
632
632
// Capture the observations in a "measurement" object.
633
633
const importWatts = netWattsFromEnergyManager > 0 ? netWattsFromEnergyManager : 0 ;
634
634
const exportWatts = netWattsFromEnergyManager < 0 ? - netWattsFromEnergyManager : 0 ;
@@ -639,6 +639,10 @@ SMAHomeManager.prototype = {
639
639
production : producedWattsFromInverter ,
640
640
consumption : importWatts + producedWattsFromInverter - exportWatts ,
641
641
} ;
642
+ if ( estimatedMsOffsetInverter > 1000 || measurement . consumption < 0 ) {
643
+ this . log . warn ( `Inverter took ${ estimatedMsOffsetInverter } ms to respond, resulting in an invalid measurement. Dropping measurement.` ) ;
644
+ return ;
645
+ }
642
646
643
647
// Store measurement and compute next measurement index.
644
648
var currentIndex = this . nextMeasurementIndex ;
0 commit comments