Add error handler for left side single phase pvinverter meter too

This commit is contained in:
Carsten Schmiemann 2023-07-15 11:55:14 +02:00
parent 88fbc49fcb
commit d02c67e3d3
1 changed files with 18 additions and 3 deletions

View File

@ -38,7 +38,7 @@ class NodeRedPVinverter:
self._dbusservice.add_path('/CustomName', productname)
self._dbusservice.add_path('/FirmwareVersion', 1.0)
self._dbusservice.add_path('/HardwareVersion', 0)
self._dbusservice.add_path('/Connected', 1)
self._dbusservice.add_path('/Connected', 0)
self._dbusservice.add_path('/Position', 0)
self._dbusservice.add_path('/Serial', 12345678)
self._dbusservice.add_path('/UpdateIndex', 0)
@ -66,21 +66,35 @@ class NodeRedPVinverter:
return int(value)
# if there is a pv meter disconnect or some other error, set mandatory values to None to tidy up vrm view
def _errorState(self):
self._dbusservice['/Connected'] = 0
self._dbusservice['/Ac/Voltage'] = None
self._dbusservice['/Ac/L1/Voltage'] = None
self._dbusservice['/Ac/Current'] = None
self._dbusservice['/Ac/L1/Current'] = None
self._dbusservice['/Ac/Power'] = None
self._dbusservice['/Ac/L1/Power'] = None
return True
def _getNodeRedData(self):
URL = "http://localhost:1880/meters"
meter_r = requests.get(url = URL)
# check for response
if not meter_r:
self._errorState()
raise ConnectionError("No response from NodeRed - %s" % (URL))
meter_data = meter_r.json()
# check for Json
if not meter_data:
self._errorState()
raise ValueError("Converting response to JSON failed")
# if there is no error parsing data, set connected to true
self._dbusservice['/Connected'] = 1
return meter_data
@ -91,7 +105,7 @@ class NodeRedPVinverter:
def _update(self):
try:
#get data from NodeRed 3em
#get data from NodeRed
meter_data = self._getNodeRedData()
#send data to DBus
@ -118,6 +132,7 @@ class NodeRedPVinverter:
#update lastupdate vars
self._lastUpdate = time.time()
except Exception as e:
self._errorState()
logging.critical('Error at %s', '_update', exc_info=e)
# return true, otherwise add_timeout will be removed from GObject - see docs http://library.isr.ist.utl.pt/docs/pygtk2reference/gobject-functions.html#function-gobject--timeout-add