Skip to content

Commit

Permalink
Only recalculate MaxAmpsToDivideFromGrid every 30 seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
RichieB2B committed Mar 5, 2024
1 parent c212707 commit 2e5fe0c
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/TWCManager/TWCMaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class TWCMaster:
consumptionAmpsValues = {}
debugOutputToFile = False
generationValues = {}
lastMaxAmpsToDivideFromGrid = 0
lastkWhMessage = time.time()
lastkWhPoll = 0
lastSaveFailed = 0
Expand Down Expand Up @@ -665,10 +666,13 @@ def getMaxAmpsToDivideGreenEnergy(self):
return round(amps, 2)

def getMaxAmpsToDivideFromGrid(self):
currentOffer = min(
self.getTotalAmpsInUse(),
self.getMaxAmpsToDivideAmongSlaves(),
) if self.getTotalAmpsInUse() > 0 else self.getMaxAmpsToDivideAmongSlaves()
# Only recalculate once every 30 seconds to allow things to settle
now = time.time()
if now - self.lastMaxAmpsToDivideFromGrid < 30:
logger.debug(f"getMaxAmpsToDivideFromGrid returns cashed value {self.maxAmpsToDivideFromGrid}")
return self.maxAmpsToDivideFromGrid

currentOffer = self.getTotalAmpsInUse() if self.getTotalAmpsInUse() > 0 else self.getMaxAmpsToDivideAmongSlaves()

# Get consumptions in Amps, if the EMS source supports it
consumptionA = float(self.getConsumptionAmps())
Expand All @@ -688,6 +692,9 @@ def getMaxAmpsToDivideFromGrid(self):
amps = amps / self.getRealPowerFactor(amps)
logger.debug("MaxAmpsToDivideFromGrid: +++++++++++++++: " + str(amps))

# Update time for comparing next time
self.lastMaxAmpsToDivideFromGrid = now

return round(amps, 2)


Expand Down

0 comments on commit 2e5fe0c

Please sign in to comment.