Skip to content
Closed
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions packages/helpermodules/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -1238,15 +1238,15 @@ def __on_message_rm(self, client, userdata, msg):
elif re.search("openWB/chargepoint/template/[0-9]+$", msg.topic) is not None:
for cp in SubData.cp_data.values():
if cp.chargepoint.data.config.template == int(msg.topic.split("/")[-1]):
pub_single(f'openWB/set/chargepoint/{cp.chargepoint.num}/config/template', 0)
Pub().pub(f'openWB/set/chargepoint/{cp.chargepoint.num}/config/template', 0)
elif re.search("openWB/vehicle/template/charge_template/[0-9]+$", msg.topic) is not None:
for vehicle in SubData.ev_data.values():
if vehicle.data.charge_template == int(msg.topic.split("/")[-1]):
pub_single(f'openWB/set/vehicle/{vehicle.num}/charge_template', 0)
Pub().pub(f'openWB/set/vehicle/{vehicle.num}/charge_template', 0)
elif re.search("openWB/vehicle/template/ev_template/[0-9]+$", msg.topic) is not None:
for vehicle in SubData.ev_data.values():
if vehicle.data.ev_template == int(msg.topic.split("/")[-1]):
pub_single(f'openWB/set/vehicle/{vehicle.num}/ev_template', 0)
Pub().pub(f'openWB/set/vehicle/{vehicle.num}/ev_template', 0)
except Exception:
log.exception("Fehler in ProcessBrokerBranch")

Expand Down
10 changes: 7 additions & 3 deletions packages/helpermodules/pub.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,23 @@ def __getattr__(self, name):


def pub_single(topic, payload, hostname="localhost", port=1883, no_json=False, retain=True):
""" published eine einzelne Nachricht an einen Host, der nicht der localhost ist.
""" Sendet eine einzelne Nachricht an einen Host.

Parameter
---------
topic : str
Topic, an das gepusht werden soll
Topic, an das gesendet werden soll
payload : int, str, list, float
Payload, der gepusht werden soll. Nicht als json, da ISSS kein json-Payload verwendet.
Payload, der gesendet werden soll. Nicht als json, da ISSS kein json-Payload verwendet.
hostname: str
IP des Hosts
no_json: bool
Kompatibilität mit ISSS, die ramdisk verwenden.
"""
if hostname == "localhost":
Pub().pub(topic, payload, qos=0, retain=retain)
return

if no_json:
publish.single(topic, payload, hostname=hostname, port=port, retain=retain)
else:
Expand Down
8 changes: 4 additions & 4 deletions packages/helpermodules/setdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from control import data
from helpermodules import hardware_configuration, subdata
from helpermodules.broker import BrokerClient
from helpermodules.pub import Pub, pub_single
from helpermodules.pub import Pub
from helpermodules.utils.topic_parser import decode_payload, get_index, get_index_position
from helpermodules.update_config import UpdateConfig
import dataclass_utils
Expand Down Expand Up @@ -1183,9 +1183,9 @@ def process_legacy_smart_home_topic(self, msg):
if ("openWB/set/LegacySmartHome/config" in msg.topic or "openWB/set/LegacySmartHome/Devices" in msg.topic):
index = get_index(msg.topic)
if "openWB/set/LegacySmartHome/config" in msg.topic:
pub_single(msg.topic.replace('openWB/set/', 'openWB/', 1), msg.payload.decode("utf-8"),
retain=True, no_json=True, port=1886)
pub_single(msg.topic, "", no_json=True, port=1886)
Pub().pub(msg.topic.replace('openWB/set/', 'openWB/', 1), msg.payload.decode("utf-8"),
retain=True, no_json=True)
Pub().pub(msg.topic, "", no_json=True)
with open(self._get_ramdisk_path()/"rereadsmarthomedevices", 'w') as f:
f.write(str(1))
if f"openWB/set/LegacySmartHome/config/set/Devices/{index}/mode" in msg.topic:
Expand Down
43 changes: 17 additions & 26 deletions packages/modules/chargepoints/external_openwb/chargepoint_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,10 @@ def set_current(self, current: float) -> None:
current = 0
with SingleComponentUpdateContext(self.fault_state, update_always=False):
with self.client_error_context:
if self.config.configuration.duo_num == 0:
pub.pub_single("openWB/set/internal_chargepoint/0/data/set_current", current,
hostname=self.config.configuration.ip_address)
pub.pub_single("openWB/set/isss/Current", current,
hostname=self.config.configuration.ip_address)
else:
pub.pub_single("openWB/set/internal_chargepoint/1/data/set_current", current,
hostname=self.config.configuration.ip_address)
pub.pub_single("openWB/set/isss/Lp2Current", current,
hostname=self.config.configuration.ip_address)
pub.pub_single(f"openWB/set/internal_chargepoint/{self.config.configuration.duo_num}/data/set_current",
current, hostname=self.config.configuration.ip_address)
pub.pub_single(f"openWB/set/isss/{'' if self.config.configuration.duo_num == 0 else 'Lp2'}Current",
current, hostname=self.config.configuration.ip_address)

def get_values(self) -> None:
def parse_received_topics(value: str):
Expand All @@ -59,14 +53,11 @@ def parse_received_topics(value: str):
{"heartbeat": timecheck.create_timestamp(), "parent_ip": my_ip_address},
hostname=ip_address)
pub.pub_single("openWB/set/isss/heartbeat", 0, hostname=ip_address)
pub.pub_single("openWB/set/isss/parentWB", my_ip_address,
hostname=ip_address, no_json=True)
if (self.config.configuration.duo_num == 1):
pub.pub_single("openWB/set/internal_chargepoint/1/data/parent_cp", str(num), hostname=ip_address)
pub.pub_single("openWB/set/isss/parentCPlp2", str(num), hostname=ip_address)
else:
pub.pub_single("openWB/set/internal_chargepoint/0/data/parent_cp", str(num), hostname=ip_address)
pub.pub_single("openWB/set/isss/parentCPlp1", str(num), hostname=ip_address)
pub.pub_single("openWB/set/isss/parentWB", my_ip_address, hostname=ip_address, no_json=True)
pub.pub_single(f"openWB/set/internal_chargepoint/{self.config.configuration.duo_num}/data/parent_cp",
str(num), hostname=ip_address)
pub.pub_single(f"openWB/set/isss/parentCPlp{self.config.configuration.duo_num + 1}",
str(num), hostname=ip_address)

def on_connect(client, userdata, flags, rc):
client.subscribe(f"openWB/internal_chargepoint/{self.config.configuration.duo_num}/get/#")
Expand Down Expand Up @@ -152,14 +143,14 @@ def interrupt_cp(self, duration: int) -> None:
with SingleComponentUpdateContext(self.fault_state, update_always=False):
with self.client_error_context:
ip_address = self.config.configuration.ip_address
if (self.config.configuration.duo_num == 1):
pub.pub_single("openWB/set/internal_chargepoint/1/data/cp_interruption_duration",
duration, hostname=ip_address)
pub.pub_single("openWB/set/isss/Cpulp2", duration, hostname=ip_address)
else:
pub.pub_single("openWB/set/internal_chargepoint/0/data/cp_interruption_duration",
duration, hostname=ip_address)
pub.pub_single("openWB/set/isss/Cpulp1", duration, hostname=ip_address)
pub.pub_single(
"openWB/set/internal_chargepoint/"
f"{self.config.configuration.duo_num}/data/cp_interruption_duration",
duration,
hostname=ip_address
)
pub.pub_single(f"openWB/set/isss/Cpulp{self.config.configuration.duo_num + 1}",
duration, hostname=ip_address)
time.sleep(duration)

def clear_rfid(self) -> None:
Expand Down
15 changes: 8 additions & 7 deletions packages/modules/common/fault_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import traceback
from typing import Optional, Callable, TypeVar

from helpermodules import exceptions, pub
from helpermodules import exceptions
from helpermodules.pub import Pub
from helpermodules.constants import NO_ERROR
from modules.common import component_type
from modules.common.component_setup import ComponentSetup
Expand Down Expand Up @@ -52,13 +53,13 @@ def store_error(self) -> None:
topic_prefix = f"openWB/set/{topic}"
else:
topic_prefix = f"openWB/set/{topic}/{self.component_info.id}"
pub.Pub().pub(f"{topic_prefix}/get/fault_str", self.fault_str)
pub.Pub().pub(f"{topic_prefix}/get/fault_state", self.fault_state.value)
Pub().pub(f"{topic_prefix}/get/fault_str", self.fault_str)
Pub().pub(f"{topic_prefix}/get/fault_state", self.fault_state.value)
if self.component_info.type == "internal_chargepoint":
pub.pub_single(f"openWB/set/chargepoint/{self.component_info.hierarchy_id}/get/fault_str",
self.fault_str)
pub.pub_single(f"openWB/set/chargepoint/{self.component_info.hierarchy_id}/get/fault_state",
self.fault_state.value)
Pub().pub(f"openWB/set/chargepoint/{self.component_info.hierarchy_id}/get/fault_str",
self.fault_str)
Pub().pub(f"openWB/set/chargepoint/{self.component_info.hierarchy_id}/get/fault_state",
self.fault_state.value)
except Exception:
log.exception("Fehler im Modul fault_state")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
import time
from typing import Optional
from helpermodules import timecheck
from helpermodules import pub

from helpermodules.logger import clear_in_memory_log_handler
from helpermodules.pub import Pub, pub_single
from helpermodules.pub import Pub
from helpermodules.subdata import SubData
from modules.chargepoints.internal_openwb.config import InternalChargepointMode
from modules.common.component_context import SingleComponentUpdateContext
Expand Down Expand Up @@ -55,11 +54,11 @@ def update_state(self, data: InternalChargepoint, heartbeat_expired: bool) -> No
" noch aktiv. Es muss erst gewartet werden, bis die CP-Unterbrechung abgeschlossen ist.")
return
self.cp_module.set_current(set_current)
pub_single(f"openWB/set/chargepoint/{self.hierarchy_id}/set/current", payload=set_current)
Pub().pub(f"openWB/set/chargepoint/{self.hierarchy_id}/set/current", payload=set_current)
if data.trigger_phase_switch:
log.debug("Switch Phases from "+str(self.old_phases_to_use) + " to " + str(data.phases_to_use))
self.__thread_phase_switch(data.phases_to_use)
pub.pub_single(
Pub().pub(
f"openWB/set/internal_chargepoint/{self.cp_module.local_charge_point_num}/data/trigger_phase_switch",
False)

Expand Down Expand Up @@ -209,8 +208,8 @@ def __init__(self,
self.update_state = UpdateState(self.module, hierarchy_id)
self.old_plug_state = False
if global_data.parent_ip != "localhost":
pub_single(f"openWB/set/chargepoint/{hierarchy_id}/get/state_str",
payload="Statusmeldungen bitte auf der Primary-openWB einsehen.")
Pub().pub(f"openWB/set/chargepoint/{hierarchy_id}/get/state_str",
payload="Statusmeldungen bitte auf der Primary-openWB einsehen.")

def update(self, global_data: GlobalHandlerData, data: InternalChargepointData, rfid_data: RfidData) -> bool:
def __thread_active(thread: Optional[Thread]) -> bool:
Expand Down
4 changes: 2 additions & 2 deletions packages/modules/internal_chargepoint_handler/rfid.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging

from evdev import InputDevice, ecodes, list_devices, categorize
from helpermodules import pub
from helpermodules.pub import Pub
log = logging.getLogger(__name__)


Expand Down Expand Up @@ -128,7 +128,7 @@ async def _read_events(self, device: InputDevice):
if data.scancode in (ecodes.KEY_ENTER, ecodes.KEY_KPENTER):
if len(key_string) > 0:
log.debug(f"RFID-String: {key_string}")
pub.pub_single("openWB/set/internal_chargepoint/last_tag", key_string)
Pub().pub("openWB/set/internal_chargepoint/last_tag", key_string)
key_string = ""
else:
log.debug(f"new key: {data.scancode} - {ecodes.KEY[data.scancode]}")
Expand Down
7 changes: 4 additions & 3 deletions packages/modules/io_devices/add_on/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
from typing import Dict, Optional, Tuple

from helpermodules import pub
from helpermodules.pub import Pub, pub_single
from helpermodules.broker import BrokerClient
from helpermodules.utils.topic_parser import decode_payload
from modules.common.abstract_device import DeviceDescriptor
Expand All @@ -22,9 +22,10 @@ def read() -> Tuple[bool, bool]:
def write(analog_output: Optional[Dict[str, int]], digital_output: Optional[Dict[str, bool]]):
if config.configuration.host is None:
raise ValueError("No host configured")
pub.pub_single("openWB/set/internal_io/states/set/digital_output", digital_output,
if config.configuration.host != "localhost":
pub_single("openWB/set/internal_io/states/set/digital_output", digital_output,
hostname=config.configuration.host)
pub.pub_single("openWB/set/internal_io/states/set/digital_output", digital_output)
Pub().pub("openWB/set/internal_io/states/set/digital_output", digital_output)

return ConfigurableIo(config=config, component_reader=read, component_writer=write)

Expand Down
6 changes: 3 additions & 3 deletions packages/modules/io_devices/eebus/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from dataclass_utils._dataclass_asdict import asdict
from helpermodules import timecheck
from helpermodules.broker import BrokerClient
from helpermodules.pub import pub_single
from helpermodules.pub import Pub
from helpermodules.utils.run_command import run_command
from helpermodules.utils._thread_handler import is_thread_alive, thread_handler
from helpermodules.utils.topic_parser import decode_payload
Expand Down Expand Up @@ -61,7 +61,7 @@ def run():
if e.returncode == 2:
msg = ("Zertifikat oder Key ungültig. Wenn das Zertifikat abgelaufen ist, bitte in "
"den Einstellungen ein neues Zertifikat generieren und den SKI beim VNB "
"akutalisieren.")
"aktualisieren.")
control_command_log.error(msg)
thread_exception = ValueError(msg)
else:
Expand Down Expand Up @@ -178,4 +178,4 @@ def create_pub_cert_ski(id: int):
config.configuration.cert_info = cert_info
with open(f"{cert_path}/ski-{id}", "w") as ski_file:
ski_file.write(cert_info.client_ski)
pub_single(f"openWB/set/system/io/{config.id}/config", asdict(config))
Pub().pub(f"openWB/set/system/io/{config.id}/config", asdict(config))