Skip to content

Commit

Permalink
3.0.1 update fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
britkat1980 committed Sep 21, 2024
1 parent aa30374 commit 27486a5
Show file tree
Hide file tree
Showing 13 changed files with 283 additions and 398 deletions.
Empty file removed .ppkwhtouch
Empty file.
142 changes: 71 additions & 71 deletions GivTCP/GivLUT.py

Large diffs are not rendered by default.

21 changes: 11 additions & 10 deletions GivTCP/HA_Discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ def create_device_payload(topic,SN):
if entity_type.sensorClass=="energy":
tempObj['unit_of_meas']="kWh"
tempObj['device_class']="Energy"
if "soc" in str(topic.split("/")[-1]).lower():
tempObj['state_class']="measurement"
else:
if entity_type.onlyIncrease: #"soc" in str(topic.split("/")[-1]).lower() or "today" in str(topic.split("/")[-1]).lower():
tempObj['state_class']="total_increasing"
else:
tempObj['state_class']="measurement"
if entity_type.sensorClass=="money":
if "ppkwh" in str(topic).lower() or "rate" in str(topic).lower():
tempObj['unit_of_meas']="{GBP}/kWh"
Expand Down Expand Up @@ -388,17 +388,18 @@ def removedisco(SN,messages):
for message in messages:
newmsg[message[0]]=message[1]
count=0
for msg in CheckDisco.msgs:
if SN in msg or SN in CheckDisco.msgs[msg]: # ("GivEnergy" in msg or GiV_Settings.MQTT_Topic in msg):
for topic in CheckDisco.msgs:
msg=CheckDisco.msgs[topic]
if SN in topic or SN in msg: # ("GivEnergy" in msg or GiV_Settings.MQTT_Topic in msg):
if exists('/config/GivTCP/.v3upgrade_'+str(GiV_Settings.givtcp_instance)):
logger.debug("V3 Upgrade so dropping old Discovery Messages")
client.publish(msg) #delete regardless of if it has changed
client.publish(topic,None,0,True) #delete regardless of if it has changed
else:
if msg in newmsg:
old=newmsg[msg]
new=CheckDisco.msgs[msg][2:-1] #.split('}')[:0]
if topic in newmsg:
old=newmsg[topic]
new=msg[2:-1] #.split('}')[:0]
if not old == new: #if payload is different delete old one
client.publish(msg)
client.publish(topic,None,0,True)
count+=1
logger.debug(str(count)+" discovery messages changed and removed")
time.sleep(2)
Expand Down
12 changes: 6 additions & 6 deletions GivTCP/givenergy_modbus_async/model/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ class Gateway(RegisterGetter, metaclass=DynamicDoc):
#### Additional Holding Registers

## EMS
"eco_mode": Def(C.uint16, BatteryPowerMode, HR(481), valid=(0, 1)),
"soc_force_adjust": Def(C.uint16, BatteryCalibrationStage, HR(482), valid=(0,3)),
"parallel_aio_soc": Def(C.uint16, None, HR(491)),
"parallel_aio_battery_power": Def(C.uint16, None, HR(492)),
"parallel_aio_load_power": Def(C.uint16, None, HR(493)),
"battery_nominal_capacity": Def(C.battery_capacity, None, HR(512),HR(0)),
# "eco_mode": Def(C.uint16, BatteryPowerMode, HR(481), valid=(0, 1)),
# "soc_force_adjust": Def(C.uint16, BatteryCalibrationStage, HR(482), valid=(0,3)),
# "parallel_aio_soc": Def(C.uint16, None, HR(491)),
# "parallel_aio_battery_power": Def(C.uint16, None, HR(492)),
# "parallel_aio_load_power": Def(C.uint16, None, HR(493)),
# "battery_nominal_capacity": Def(C.battery_capacity, None, HR(512),HR(0)),

}
REGISTER_LUT=dict(BaseInverter.REGISTER_LUT, **NEW_LUT)
Expand Down
4 changes: 2 additions & 2 deletions GivTCP/givenergy_modbus_async/model/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ def core_regs(cls, value):
'4': ([0, 60, 120, 180, 240,1000,1060,1120,1180,1240,1300,1360],[180,240,1000,1060,1120]), #"Hybrid - 3ph"
'5': ([2040],[2040]), #EMS
'6': ([0, 60, 120, 180, 240,1000,1060,1120,1180,1240,1300,1360],[180,240,1000,1060,1120]), #AC - 3ph
'7': ([0, 60, 120, 180,1600,1660,1720,1780,1840],[0, 60, 120, 120,180,240,300,480]), #Gateway
'7': ([0, 60, 120, 180,1600,1660,1720,1780,1840],[0, 60, 120, 120,180,240,300]), #Gateway
'8': ([0, 60, 120, 180, 240],[0, 60, 120, 120, 180, 240, 300]), #All in One
}
return regs.get(value)
Expand All @@ -663,7 +663,7 @@ def add_regs(cls, value):
'4': ([240,1000,1060,1120,1180,1240,1300,1360],[180,240,1000,1060,1120]), #"Hybrid - 3ph"
'5': ([2040],[2040]), #EMS
'6': ([1000,1060,1120,1180,1240,1300,1360],[180,240,1000,1060,1120]), #AC - 3ph
'7': ([1600,1660,1720,1780,1840],[180,240,300,480]), #Gateway
'7': ([1600,1660,1720,1780,1840],[180,240,300]), #Gateway
'8': ([240],[180,240,300]), #All in One
}
return regs.get(value)
Expand Down
1 change: 0 additions & 1 deletion GivTCP/panda.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ def outlierRemoval(CacheStack):
CacheStack[i][path[0]][path[1]][item]=cleanFlatStack[item]
elif len(path)==3:
CacheStack[i][path[0]][path[1]][path[2]][item]=cleanFlatStack[item]

return CacheStack

def find(field_name, d, current_path=''):
Expand Down
21 changes: 10 additions & 11 deletions GivTCP/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ def processInverterInfo(plant: Plant):
multi_output_old = regCacheStack[-1]
else:
regCacheStack = [0]
multi_output_old = []
multi_output_old = {}

# If System Time is wrong (default date) use last good time or local time if all else fails
if GEInv.system_time.year == 2000:
Expand Down Expand Up @@ -867,10 +867,10 @@ def processInverterInfo(plant: Plant):
# if int(GiV_Settings.numBatteries) > 0: # only do this if there are batteries
if GEInv.battery_percent != 0 or GEInv.soc_force_adjust !=0: #if we're in calibration mode accept any value
power_output['SOC'] = GEInv.battery_percent
elif GEInv.battery_percent == 0 and 'multi_output_old' in locals():
elif GEInv.battery_percent == 0 and len(multi_output_old)>0:
power_output['SOC'] = multi_output_old['Power']['Power']['SOC']
logger.debug("\"Battery SOC\" reported as: "+str(GEInv.battery_percent)+"% so using previous value")
elif GEInv.battery_percent == 0 and not 'multi_output_old' in locals():
elif GEInv.battery_percent == 0 and len(multi_output_old)==0:
power_output['SOC'] = 1
logger.debug("\"Battery SOC\" reported as: "+str(GEInv.battery_percent)+"% and no previous value so setting to 1%")
else:
Expand Down Expand Up @@ -1251,10 +1251,10 @@ def processGatewayInfo(plant: Plant):


### Is this bit right? If not parallel then are there multiple aios to check? Can you have multiple AIOs not in parallel mode?
if GEInv.parallel_aio_soc>0:
power_output['SOC']=GEInv.parallel_aio_soc
power_output['SOC_kWh'] = round((int(power_output['SOC'])*(inverterModel.batterycapacity))/100,2)
else:
if GEInv.parallel_aio_num>1:
# power_output['SOC']=GEInv.parallel_aio_soc
# power_output['SOC_kWh'] = round((int(power_output['SOC'])*(inverterModel.batterycapacity))/100,2)
#else:
# Calc based on individual SOCs
count=0
total=0
Expand Down Expand Up @@ -2152,7 +2152,6 @@ def dataSmoother2(dataNew, dataOld, lastUpdate, invtype,inv_time):
else:
max=lookup.max
## Make sure its a number...
newData=float(newData)

now = inv_time
then = datetime.datetime.fromisoformat(lastUpdate)
Expand All @@ -2178,14 +2177,14 @@ def dataSmoother2(dataNew, dataOld, lastUpdate, invtype,inv_time):
## Finally smooth data if its not already Zero (avoid div by Zero)
if oldData != 0:
### Run checks against the conditions in GivLUT ###
if "Power" in name:
if "power" in name.lower():
if newData==12179:
return oldData
if lookup.smooth: # apply smoothing if required
if newData != oldData: # Only if its not the same
timeDelta = (now-then).total_seconds()
dataDelta = abs(newData-oldData)/oldData #Should it be a ratio or an abs value as low values easily meet the threshold
if "Power" in name:
if "power" in name.lower():
if abs(newData-oldData)>abssmooth:
if checkRawcache(newData,name,abssmooth): #If new data is persistently outside bounds then use new value
return(newData)
Expand All @@ -2194,7 +2193,7 @@ def dataSmoother2(dataNew, dataOld, lastUpdate, invtype,inv_time):
return(oldData)
else:
if dataDelta > smoothRate and timeDelta < 60:
logger.debug(str(name)+" jumped too far in a single read: "+str(oldData)+"->"+str(newData)+" so using previous value")
logger.info(str(name)+" jumped too far in a single read: "+str(oldData)+"->"+str(newData)+" so using previous value")
return(oldData)

return(newData)
Expand Down
Loading

0 comments on commit 27486a5

Please sign in to comment.