From 6c2c3a725745e7b0457cd77a450669d452fa833a Mon Sep 17 00:00:00 2001 From: 0x7878 <17197791+0x7878@users.noreply.github.com> Date: Mon, 11 Nov 2024 16:20:16 +0000 Subject: [PATCH] since paths is used as constant I moved it --- constants.py | 39 +++++++++++++++++++++++++++++++++++++++ dbus_opendtu.py | 40 ---------------------------------------- dbus_service.py | 3 +-- 3 files changed, 40 insertions(+), 42 deletions(-) diff --git a/constants.py b/constants.py index 7abbbdf..7203ca9 100644 --- a/constants.py +++ b/constants.py @@ -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}, +} \ No newline at end of file diff --git a/dbus_opendtu.py b/dbus_opendtu.py index 7ce244e..dc5bc71 100644 --- a/dbus_opendtu.py +++ b/dbus_opendtu.py @@ -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(): @@ -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, ) @@ -127,7 +89,6 @@ def register_service(): ) DbusService( servicename=servicename, - paths=paths, actual_inverter=actual_inverter + 1, ) @@ -142,7 +103,6 @@ def register_service(): ) service = DbusService( servicename=servicename, - paths=paths, actual_inverter=actual_template, istemplate=True, ) diff --git a/dbus_service.py b/dbus_service.py index bc7df0f..91ea68a 100644 --- a/dbus_service.py +++ b/dbus_service.py @@ -52,7 +52,6 @@ class DbusService: def __init__( self, servicename, - paths, actual_inverter, istemplate=False, ): @@ -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__)