Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid KeyException #591

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions custom_components/solax_modbus/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,44 +200,44 @@ def value_function_pv_power_total(initval, descr, datadict):
return datadict.get('pv_power_1', 0) + datadict.get('pv_power_2',0) + datadict.get('pv_power_3',0)

def value_function_battery_output(initval, descr, datadict):
val = datadict["battery_power_charge"]
val = datadict.get('battery_power_charge', 0)
if val<0: return abs(val)
else: return 0

def value_function_battery_input(initval, descr, datadict):
val = datadict["battery_power_charge"]
val = datadict.get('battery_power_charge', 0)
if val>0: return val
else: return 0

def value_function_battery_output_solis(initval, descr, datadict):
inout = datadict["battery_charge_direction"]
val = datadict["battery_power"]
inout = datadict.get('battery_charge_direction', 0)
val = datadict.get('battery_power', 0)
if inout == 1: return abs(val)
else: return 0

def value_function_battery_input_solis(initval, descr, datadict):
inout = datadict["battery_charge_direction"]
val = datadict["battery_power"]
inout = datadict.get('battery_charge_direction', 0)
val = datadict.get('battery_power', 0)
if inout == 0: return val
else: return 0

def value_function_grid_import(initval, descr, datadict):
val = datadict["measured_power"]
val = datadict.get('measured_power', 0)
if val<0: return abs(val)
else: return 0

def value_function_grid_export(initval, descr, datadict):
val = datadict["measured_power"]
val = datadict.get('measured_power', 0)
if val>0: return val
else: return 0

def value_function_house_load(initval, descr, datadict):
return ( datadict['inverter_load'] - datadict['measured_power'] )
return ( datadict.get('inverter_load', 0) - datadict.get('measured_power', 0) )

def value_function_house_load_alt(initval, descr, datadict):
return ( datadict.get('pv_power_1', 0) + datadict.get('pv_power_2', 0) + datadict.get('pv_power_3', 0)
- datadict['battery_power_charge']
- datadict['measured_power'] )
- datadict.get('battery_power_charge', 0)
- datadict.get('measured_power', 0) )

def value_function_sync_rtc(initval, descr, datadict):
now = datetime.now()
Expand Down
Loading