Skip to content

Commit

Permalink
since paths is used as constant I moved it
Browse files Browse the repository at this point in the history
  • Loading branch information
0x7878 committed Nov 11, 2024
1 parent d21f513 commit 6c2c3a7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 42 deletions.
39 changes: 39 additions & 0 deletions constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,44 @@
'''Global constants'''

# region formatting helping functions (used in constant)
def _kwh(_p, value: float) -> str:
return f"{round(value, 2)}KWh"

def _a(_p, value: float) -> str:
return f"{round(value, 1)}A"

def _w(_p, value: float) -> str:
return f"{round(value, 1)}W"

def _v(_p, value: float) -> str:
return f"{round(value, 1)}V"
# endregion

DTUVARIANT_AHOY = "ahoy"
DTUVARIANT_OPENDTU = "opendtu"
DTUVARIANT_TEMPLATE = "template"


VICTRON_PATHS = {
"/Ac/Energy/Forward": {
"initial": None,
"textformat": _kwh,
}, # energy produced by pv inverter
"/Ac/Power": {"initial": None, "textformat": _w},
"/Ac/L1/Voltage": {"initial": None, "textformat": _v},
"/Ac/L2/Voltage": {"initial": None, "textformat": _v},
"/Ac/L3/Voltage": {"initial": None, "textformat": _v},
"/Ac/L1/Current": {"initial": None, "textformat": _a},
"/Ac/L2/Current": {"initial": None, "textformat": _a},
"/Ac/L3/Current": {"initial": None, "textformat": _a},
"/Ac/L1/Power": {"initial": None, "textformat": _w},
"/Ac/L2/Power": {"initial": None, "textformat": _w},
"/Ac/L3/Power": {"initial": None, "textformat": _w},
"/Ac/L1/Energy/Forward": {"initial": None, "textformat": _kwh},
"/Ac/L2/Energy/Forward": {"initial": None, "textformat": _kwh},
"/Ac/L3/Energy/Forward": {"initial": None, "textformat": _kwh},
"/Ac/Out/L1/I": {"initial": None, "textformat": _a},
"/Ac/Out/L1/V": {"initial": None, "textformat": _v},
"/Ac/Out/L1/P": {"initial": None, "textformat": _w},
"/Dc/0/Voltage": {"initial": None, "textformat": _v},
}
40 changes: 0 additions & 40 deletions dbus_opendtu.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,43 +58,6 @@ def initialize():
logging.warning("NumberOfTemplates not set, using default")
number_of_templates = 0

# region formatting
def _kwh(_p, value: float) -> str:
return f"{round(value, 2)}KWh"

def _a(_p, value: float) -> str:
return f"{round(value, 1)}A"

def _w(_p, value: float) -> str:
return f"{round(value, 1)}W"

def _v(_p, value: float) -> str:
return f"{round(value, 1)}V"
# endregion

paths = {
"/Ac/Energy/Forward": {
"initial": None,
"textformat": _kwh,
}, # energy produced by pv inverter
"/Ac/Power": {"initial": None, "textformat": _w},
"/Ac/L1/Voltage": {"initial": None, "textformat": _v},
"/Ac/L2/Voltage": {"initial": None, "textformat": _v},
"/Ac/L3/Voltage": {"initial": None, "textformat": _v},
"/Ac/L1/Current": {"initial": None, "textformat": _a},
"/Ac/L2/Current": {"initial": None, "textformat": _a},
"/Ac/L3/Current": {"initial": None, "textformat": _a},
"/Ac/L1/Power": {"initial": None, "textformat": _w},
"/Ac/L2/Power": {"initial": None, "textformat": _w},
"/Ac/L3/Power": {"initial": None, "textformat": _w},
"/Ac/L1/Energy/Forward": {"initial": None, "textformat": _kwh},
"/Ac/L2/Energy/Forward": {"initial": None, "textformat": _kwh},
"/Ac/L3/Energy/Forward": {"initial": None, "textformat": _kwh},
"/Ac/Out/L1/I": {"initial": None, "textformat": _a},
"/Ac/Out/L1/V": {"initial": None, "textformat": _v},
"/Ac/Out/L1/P": {"initial": None, "textformat": _w},
"/Dc/0/Voltage": {"initial": None, "textformat": _v},
}


def register_service():
Expand All @@ -107,7 +70,6 @@ def register_service():
servicename = get_config_value(config, "Servicename", "INVERTER", 0, "com.victronenergy.pvinverter")
service = DbusService(
servicename=servicename,
paths=paths,
actual_inverter=0,
)

Expand All @@ -127,7 +89,6 @@ def register_service():
)
DbusService(
servicename=servicename,
paths=paths,
actual_inverter=actual_inverter + 1,
)

Expand All @@ -142,7 +103,6 @@ def register_service():
)
service = DbusService(
servicename=servicename,
paths=paths,
actual_inverter=actual_template,
istemplate=True,
)
Expand Down
3 changes: 1 addition & 2 deletions dbus_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class DbusService:
def __init__(
self,
servicename,
paths,
actual_inverter,
istemplate=False,
):
Expand Down Expand Up @@ -95,7 +94,7 @@ def __init__(
)

self._dbusservice = VeDbusService(f"{servicename}.http_{self.deviceinstance}", dbus_conn)
self._paths = paths
self._paths = constants.VICTRON_PATHS

# Create the management objects, as specified in the ccgx dbus-api document
self._dbusservice.add_path("/Mgmt/ProcessName", __file__)
Expand Down

0 comments on commit 6c2c3a7

Please sign in to comment.