X-Git-Url: https://git.sven.stormbind.net/?p=sven%2Fscripts.git;a=blobdiff_plain;f=home%2Fportalmonitor.py;fp=home%2Fportalmonitor.py;h=3acd3f1766e677469fff2021e60f853af0b1253a;hp=1316b2f6807d50233c13f511c81767d56e040091;hb=a3744e93b3c458726d9eb211a22a52c0fb1c688e;hpb=8d0198c269d90ea3c1a7f60225aabb7577b7b194 diff --git a/home/portalmonitor.py b/home/portalmonitor.py index 1316b2f..3acd3f1 100755 --- a/home/portalmonitor.py +++ b/home/portalmonitor.py @@ -63,6 +63,25 @@ def getCurrentPower(userName, password, stationId): return float(power) +# use our stateFile to determine if we have a state change +# used to decide if we print something - thus generate a mail - later on +def stateCheck(newState, stateFile): + try: + with open(stateFile, "r") as f: + oldState = f.read() + except FileNotFoundError: + oldState = "NULL" + + if newState == oldState: + change = False + else: + change = True + with open(stateFile, "w") as f: + f.write(newState) + + return change + + # read configuration file conf = configparser.ConfigParser() conf.read('portalmonitor.ini') @@ -78,5 +97,9 @@ if isDaylight(conf['config'].getfloat('lat'), conf['config'].getfloat('lon'), print(f"Current Power: {currentPower}") if currentPower == 0: - print('Error: Power dropped to 0 but we should have daylight!') + if stateCheck('FAILED', conf['config']['stateFile']): + print('Error: Power dropped to 0 but we should have daylight!') sys.exit(1) + else: + if stateCheck('OK', conf['config']['stateFile']): + print(f"Resolved: Inverter reports {currentPower}W")