1+ import logging
12import time
23
34from control import data
45from helpermodules import pub , timecheck
6+ from helpermodules .broker import BrokerClient
57from helpermodules .utils .error_handling import CP_ERROR , ErrorTimerContext
8+ from helpermodules .utils .topic_parser import decode_payload
69from modules .chargepoints .external_openwb .config import OpenWBSeries
710from modules .common .abstract_chargepoint import AbstractChargepoint
811from modules .common .abstract_device import DeviceDescriptor
912from modules .common .component_context import SingleComponentUpdateContext
13+ from modules .common .component_state import ChargepointState
1014from modules .common .fault_state import ComponentInfo , FaultState
15+ from modules .common .store ._chargepoint import get_chargepoint_value_store
16+
17+ log = logging .getLogger (__name__ )
1118
1219
1320class ChargepointModule (AbstractChargepoint ):
@@ -18,6 +25,7 @@ def __init__(self, config: OpenWBSeries) -> None:
1825 "Ladepunkt" , "chargepoint" ))
1926 self .client_error_context = ErrorTimerContext (
2027 f"openWB/set/chargepoint/{ self .config .id } /get/error_timestamp" , CP_ERROR , hide_exception = True )
28+ self .store = get_chargepoint_value_store (self .config .id )
2129
2230 def set_current (self , current : float ) -> None :
2331 if self .client_error_context .error_counter_exceeded ():
@@ -56,6 +64,49 @@ def get_values(self) -> None:
5664 else :
5765 pub .pub_single ("openWB/set/internal_chargepoint/0/data/parent_cp" , str (num ), hostname = ip_address )
5866 pub .pub_single ("openWB/set/isss/parentCPlp1" , str (num ), hostname = ip_address )
67+
68+ def on_connect (client , userdata , flags , rc ):
69+ client .subscribe (f"openWB/internal_chargepoint/{ self .config .configuration .duo_num } /get/#" )
70+
71+ def on_message (client , userdata , message ):
72+ received_topics .update ({message .topic : decode_payload (message .payload )})
73+
74+ received_topics = {}
75+ BrokerClient (f"subscribeSeriesChargepoint{ self .config .id } " ,
76+ on_connect ,
77+ on_message ,
78+ host = self .config .configuration .ip_address ,
79+ port = 1883 ).start_finite_loop ()
80+
81+ if received_topics :
82+ log .debug (f"Empfange MQTT Daten für Ladepunkt { self .config .id } : { received_topics } " )
83+ topic_prefix = f"openWB/internal_chargepoint/{ self .config .configuration .duo_num } /get/"
84+ chargepoint_state = ChargepointState (
85+ power = received_topics .get (f"{ topic_prefix } power" ),
86+ phases_in_use = received_topics .get (f"{ topic_prefix } phases_in_use" ),
87+ imported = received_topics .get (f"{ topic_prefix } imported" ),
88+ exported = received_topics .get (f"{ topic_prefix } exported" ),
89+ serial_number = received_topics .get (f"{ topic_prefix } serial_number" ),
90+ powers = received_topics .get (f"{ topic_prefix } powers" ),
91+ voltages = received_topics .get (f"{ topic_prefix } voltages" ),
92+ currents = received_topics .get (f"{ topic_prefix } currents" ),
93+ power_factors = received_topics .get (f"{ topic_prefix } power_factors" ),
94+ plug_state = received_topics .get (f"{ topic_prefix } plug_state" ),
95+ charge_state = received_topics .get (f"{ topic_prefix } charge_state" ),
96+ rfid = received_topics .get (f"{ topic_prefix } rfid" ),
97+ rfid_timestamp = received_topics .get (f"{ topic_prefix } rfid_timestamp" ),
98+ frequency = received_topics .get (f"{ topic_prefix } frequency" ),
99+ soc = received_topics .get (f"{ topic_prefix } soc" ),
100+ soc_timestamp = received_topics .get (f"{ topic_prefix } soc_timestamp" ),
101+ vehicle_id = received_topics .get (f"{ topic_prefix } vehicle_id" ),
102+ evse_current = received_topics .get (f"{ topic_prefix } evse_current" ),
103+ max_evse_current = received_topics .get (f"{ topic_prefix } max_evse_current" ),
104+ )
105+ self .store .set (chargepoint_state )
106+ else :
107+ self .fault_state .warning (f"Keine MQTT-Daten für Ladepunkt { self .config .name } empfangen. Noch keine "
108+ "Daten nach dem Start oder Ladepunkt nicht erreichbar." )
109+
59110 self .client_error_context .reset_error_counter ()
60111
61112 def switch_phases (self , phases_to_use : int , duration : int ) -> None :
0 commit comments