-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,23 +6,21 @@ | |
import platform | ||
import sys | ||
import logging | ||
import time | ||
from vedbus import VeDbusService # pylint: disable=E0401 | ||
import requests # for http GET #pylint: disable=E0401 | ||
from requests.auth import HTTPDigestAuth # pylint: disable=E0401 | ||
|
||
# victron imports: | ||
import dbus # pylint: disable=E0401 | ||
from requests.auth import HTTPDigestAuth #pylint: disable=E0401 | ||
import time | ||
|
||
# our imports: | ||
import constants | ||
# TODO: This should be refactored to use helper (utils) as a module # pylint: disable=W0511 | ||
from helpers import * # pylint: disable=W0401,W0614 | ||
from helpers import * | ||
|
||
# victron imports: | ||
import dbus #pylint: disable=E0401 | ||
|
||
if sys.version_info.major == 2: | ||
import gobject # pylint: disable=E0401 | ||
import gobject #pylint: disable=E0401 | ||
else: | ||
from gi.repository import GLib as gobject # pylint: disable=E0401 | ||
from gi.repository import GLib as gobject #pylint: disable=E0401 | ||
|
||
sys.path.insert( | ||
1, | ||
|
@@ -31,6 +29,7 @@ | |
"/opt/victronenergy/dbus-systemcalc-py/ext/velib_python", | ||
), | ||
) | ||
from vedbus import VeDbusService #pylint: disable=E0401 | ||
|
||
class PvInverterRegistry(type): | ||
'''Run a registry for all PV Inverter''' | ||
|
@@ -132,6 +131,11 @@ def __init__( | |
# Set Mode to 2 to show it as ON | ||
# 2=On;4=Off;5=Eco | ||
self._dbusservice.add_path("/Mode", 2) | ||
#set the SystemState flaf to 9=Inverting | ||
#/SystemState/State -> 0: Off | ||
# -> 1: Low power | ||
# -> 9: Inverting | ||
self._dbusservice.add_path("/State", 9) | ||
|
||
# add path values to dbus | ||
for path, settings in self._paths.items(): | ||
|
@@ -204,10 +208,6 @@ def _read_config_template(self, template_number): | |
self.custtotal_factor = config[f"TEMPLATE{template_number}"]["CUST_Total_Mult"] | ||
self.custvoltage = config[f"TEMPLATE{template_number}"]["CUST_Voltage"].split( | ||
"/") | ||
self.custdcvoltage = config[f"TEMPLATE{template_number}"]["CUST_DCVoltage"].split( | ||
"/") | ||
self.custcurrent = config[f"TEMPLATE{template_number}"]["CUST_Current"].split( | ||
"/") | ||
self.custapipath = config[f"TEMPLATE{template_number}"]["CUST_API_PATH"] | ||
self.serial = str(config[f"TEMPLATE{template_number}"]["CUST_SN"]) | ||
self.pollinginterval = int( | ||
|
@@ -228,6 +228,22 @@ def _read_config_template(self, template_number): | |
self.digestauth = is_true(get_config_value( | ||
config, "DigestAuth", "TEMPLATE", template_number, False)) | ||
|
||
try: | ||
self.custcurrent= config[f"TEMPLATE{template_number}"]["CUST_Current"].split( | ||
"/") | ||
except Exception: # pylint: disable=broad-except | ||
# set to undefined because get_nested will solve this to 0 | ||
self.custcurrent = "[undefined]" | ||
logging.debug("CUST_Current not set") | ||
|
||
try: | ||
self.custdcvoltage = config[f"TEMPLATE{template_number}"]["CUST_DCVoltage"].split( | ||
"/") | ||
except Exception: # pylint: disable=broad-except | ||
# set to undefined because get_nested will solve this to 0 | ||
self.custdcvoltage = "[undefined]" | ||
logging.debug("CUST_DCVoltage not set") | ||
|
||
try: | ||
self.max_age_ts = int(config["DEFAULT"]["MagAgeTsLastSuccess"]) | ||
except ValueError as ex: | ||
|
@@ -425,7 +441,7 @@ def fetch_ahoy_record_data(self): | |
def fetch_url(self, url, try_number=1): | ||
'''Fetch JSON data from url. Throw an exception on any error. Only return on success.''' | ||
try: | ||
logging.debug("calling %s with timeout=%f", url, self.httptimeout) | ||
logging.debug("calling %s with timeout=%s", url, self.httptimeout) | ||
if self.digestauth: | ||
logging.debug("using Digest access authentication...") | ||
json_str = requests.get(url=url, auth=HTTPDigestAuth( | ||
|
@@ -601,7 +617,7 @@ def get_values_for_inverter(self): | |
voltage = get_ahoy_field_by_name( | ||
meter_data, self.pvinverternumber, "U_AC") | ||
dc_voltage = get_ahoy_field_by_name( | ||
meter_data, self.pvinverternumber, "U_DC") | ||
meter_data, self.pvinverternumber, "U_DC", False) | ||
current = get_ahoy_field_by_name( | ||
meter_data, self.pvinverternumber, "I_AC") | ||
|
||
|
@@ -651,13 +667,17 @@ def set_dbus_values(self): | |
self._dbusservice["/Ac/Out/L1/V"] = voltage | ||
self._dbusservice["/Ac/Out/L1/I"] = current | ||
self._dbusservice["/Dc/0/Voltage"] = dc_voltage | ||
state = None | ||
if current > 0: | ||
|
||
try: | ||
float_current = float(current) | ||
except ValueError: | ||
float_current = 0 | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
if float_current > 0: | ||
state = 9 | ||
This comment has been minimized.
Sorry, something went wrong.
dsteinkopf
Collaborator
|
||
else: | ||
state = 0 | ||
self._dbusservice["/State"] = state | ||
|
||
logging.debug("Inverter #%d Voltage (/Ac/Out/L1/V): %s", | ||
self.pvinverternumber, voltage) | ||
logging.debug("Inverter #%d Current (/Ac/Out/L1/I): %s", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ def get_nested(meter_data, path): | |
value = 0 | ||
return value | ||
|
||
def get_ahoy_field_by_name(meter_data, actual_inverter, fieldname): | ||
def get_ahoy_field_by_name(meter_data, actual_inverter, fieldname, ch0_fld_names = True): | ||
This comment has been minimized.
Sorry, something went wrong.
dsteinkopf
Collaborator
|
||
'''get the value by name instead of list index''' | ||
# fetch value from record call: | ||
# - but there seem to be more than one value per type and Inverter, and we don't know which one to take | ||
|
@@ -51,10 +51,21 @@ def get_ahoy_field_by_name(meter_data, actual_inverter, fieldname): | |
# return val | ||
# raise ValueError(f"Fieldname {fieldname} not found in meter_data.") | ||
|
||
ac_data_field_names = meter_data["ch0_fld_names"] | ||
data_index = ac_data_field_names.index(fieldname) | ||
ac_channel_index = 0 | ||
return meter_data["inverter"][actual_inverter]["ch"][ac_channel_index][data_index] | ||
data = None | ||
|
||
if(ch0_fld_names): | ||
data_field_names = meter_data["ch0_fld_names"] | ||
data_index = data_field_names.index(fieldname) | ||
ac_channel_index = 0 | ||
data = meter_data["inverter"][actual_inverter]["ch"][ac_channel_index][data_index] | ||
else: | ||
data_field_names = meter_data["fld_names"] | ||
data_index = data_field_names.index(fieldname) | ||
# TODO - check if this channel has to be adjusted | ||
dc_channel_index = 0 + 1 # 1 = DC1, 2 = DC2 etc. | ||
This comment has been minimized.
Sorry, something went wrong.
dsteinkopf
Collaborator
|
||
data = meter_data["inverter"][actual_inverter]["ch"][dc_channel_index][data_index] | ||
|
||
return data | ||
|
||
def is_true(val): | ||
'''helper function to test for different true values''' | ||
|
I am not quite sure if this is a good idea.
This might have to do with #72. But maybe I don't have enogh overview at the moment.