Skip to content

Commit d62421e

Browse files
ndrsnhsLKuemmel
andauthored
Update secondary (#2312)
* add simple update functionality * update secondaries only if activated * better check for secondaries * add current_version to cp * add current branch and current version * fix typo * set values * add possibility to subscribe * add check for branch * add CP version to broker * remove sub.py * add topic in setdata and update_config * fix --------- Co-authored-by: LKuemmel <[email protected]>
1 parent b97280a commit d62421e

File tree

9 files changed

+54
-3
lines changed

9 files changed

+54
-3
lines changed

packages/control/chargepoint/chargepoint_data.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ class Get:
9494
charging_power: Optional[float] = 0
9595
charging_voltage: Optional[float] = 0
9696
connected_vehicle: ConnectedVehicle = field(default_factory=connected_vehicle_factory)
97+
current_branch: Optional[str] = None
98+
current_commit: Optional[str] = None
9799
currents: List[float] = field(default_factory=currents_list_factory)
98100
daily_imported: float = 0
99101
daily_exported: float = 0
@@ -115,6 +117,7 @@ class Get:
115117
soc_timestamp: Optional[int] = None
116118
state_str: Optional[str] = None
117119
vehicle_id: Optional[str] = None
120+
version: Optional[str] = None
118121
voltages: List[float] = field(default_factory=voltages_list_factory)
119122

120123

packages/helpermodules/command.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,12 @@ def chargepointShutdown(self, connection_id: str, payload: dict) -> None:
687687
hostname=SubData.cp_data[payload["data"]["chargepoint"]
688688
].chargepoint.chargepoint_module.config.configuration.ip_address)
689689

690+
def secondaryChargepointUpdate(self, payload: dict) -> None:
691+
pub.pub_single("openWB/set/command/primary/todo",
692+
{"command": "systemUpdate", "data": {}},
693+
hostname=SubData.cp_data[payload["data"]["chargepoint"]
694+
].chargepoint.chargepoint_module.config.configuration.ip_address)
695+
690696
def systemReboot(self, connection_id: str, payload: dict) -> None:
691697
pub_user_message(payload, connection_id, "Neustart wird ausgeführt.", MessageType.INFO)
692698
parent_file = Path(__file__).resolve().parents[2]
@@ -728,6 +734,16 @@ def systemUpdate(self, connection_id: str, payload: dict) -> None:
728734
run_command([
729735
str(parent_file / "runs" / "update_self.sh"),
730736
SubData.system_data["system"].data["current_branch"]])
737+
if not SubData.general_data.data.extern and SubData.system_data["system"].data["secondary_auto_update"]:
738+
for cp in SubData.cp_data.values():
739+
# if chargepoint is external_openwb and not the second CP of duo and version is Release
740+
if (
741+
cp.chargepoint.chargepoint_module.config.type == 'external_openwb' and
742+
cp.chargepoint.chargepoint_module.config.configuration.duo_num == 0 and
743+
cp.chargepoint.data.get.current_branch == "Release"
744+
):
745+
time.sleep(2)
746+
self.secondaryChargepointUpdate({"data": {"chargepoint": f"cp{cp.chargepoint.num}"}})
731747

732748
def systemFetchVersions(self, connection_id: str, payload: dict) -> None:
733749
log.info("Fetch versions requested")

packages/helpermodules/setdata.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,10 @@ def process_chargepoint_get_topics(self, msg):
631631
elif ("/get/evse_current" in msg.topic or
632632
"/get/max_evse_current" in msg.topic):
633633
self._validate_value(msg, float, [(0, 0), (6, 32), (600, 3200)])
634+
elif ("/get/version" in msg.topic or
635+
"/get/current_branch" in msg.topic or
636+
"/get/current_commit" in msg.topic):
637+
self._validate_value(msg, str)
634638
elif ("/get/error_timestamp" in msg.topic or
635639
"/get/rfid_timestamp" in msg.topic):
636640
self._validate_value(msg, float)
@@ -1086,6 +1090,8 @@ def process_system_topic(self, msg: mqtt.MQTTMessage):
10861090
self._validate_value(msg, "json")
10871091
elif "openWB/set/system/mqtt/valid_partner_ids" == msg.topic:
10881092
self._validate_value(msg, str, collection=list)
1093+
elif "openWB/set/system/secondary_auto_update" == msg.topic:
1094+
self._validate_value(msg, bool)
10891095
elif "configurable" in msg.topic:
10901096
self._validate_value(msg, None)
10911097
elif "device" in msg.topic:

packages/helpermodules/update_config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ class UpdateConfig:
107107
"^openWB/chargepoint/[0-9]+/control_parameter/timestamp_switch_on_off$",
108108
"^openWB/chargepoint/[0-9]+/get/charge_state$",
109109
"^openWB/chargepoint/[0-9]+/get/currents$",
110+
"^openWB/chargepoint/[0-9]+/get/current_branch$",
111+
"^openWB/chargepoint/[0-9]+/get/current_commit$",
110112
"^openWB/chargepoint/[0-9]+/get/evse_current$",
111113
"^openWB/chargepoint/[0-9]+/get/fault_state$",
112114
"^openWB/chargepoint/[0-9]+/get/fault_str$",
@@ -122,6 +124,7 @@ class UpdateConfig:
122124
"^openWB/chargepoint/[0-9]+/get/powers$",
123125
"^openWB/chargepoint/[0-9]+/get/power_factors$",
124126
"^openWB/chargepoint/[0-9]+/get/vehicle_id$",
127+
"^openWB/chargepoint/[0-9]+/get/version$",
125128
"^openWB/chargepoint/[0-9]+/get/voltages$",
126129
"^openWB/chargepoint/[0-9]+/get/serial_number$",
127130
"^openWB/chargepoint/[0-9]+/get/soc$",
@@ -464,6 +467,7 @@ class UpdateConfig:
464467
"^openWB/system/mqtt/bridge/[0-9]+$",
465468
"^openWB/system/mqtt/valid_partner_ids$",
466469
"^openWB/system/release_train$",
470+
"^openWB/system/secondary_auto_update$",
467471
"^openWB/system/time$",
468472
"^openWB/system/update_in_progress$",
469473
"^openWB/system/usage_terms_acknowledged$",
@@ -560,6 +564,7 @@ class UpdateConfig:
560564
("openWB/system/ip_address", "unknown"),
561565
("openWB/system/mqtt/valid_partner_ids", []),
562566
("openWB/system/release_train", "master"),
567+
("openWB/system/secondary_auto_update", True),
563568
("openWB/system/serial_number", get_serial_number()),
564569
)
565570
invalid_topic = (

packages/modules/common/component_state.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,10 @@ def __init__(self,
174174
soc_timestamp: Optional[int] = None,
175175
evse_current: Optional[float] = None,
176176
vehicle_id: Optional[str] = None,
177-
max_evse_current: Optional[int] = None):
177+
max_evse_current: Optional[int] = None,
178+
current_branch: Optional[str] = None,
179+
current_commit: Optional[str] = None,
180+
version: Optional[str] = None):
178181
self.currents, self.powers, self.voltages = _calculate_powers_and_currents(currents, powers, voltages)
179182
self.frequency = frequency
180183
self.imported = imported
@@ -200,6 +203,9 @@ def __init__(self,
200203
self.evse_current = evse_current
201204
self.max_evse_current = max_evse_current
202205
self.vehicle_id = vehicle_id
206+
self.current_branch = current_branch
207+
self.current_commit = current_commit
208+
self.version = version
203209

204210

205211
@auto_str

packages/modules/common/store/_chargepoint.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ def update(self):
5252
pub_to_broker("openWB/set/chargepoint/" + str(self.num) + "/get/evse_current", self.state.evse_current)
5353
pub_to_broker("openWB/set/chargepoint/" + str(self.num) + "/get/vehicle_id", self.state.vehicle_id)
5454
pub_to_broker("openWB/set/chargepoint/" + str(self.num) + "/get/max_evse_current", self.state.max_evse_current)
55+
pub_to_broker("openWB/set/chargepoint/" + str(self.num) + "/get/version", self.state.version)
56+
pub_to_broker("openWB/set/chargepoint/" + str(self.num) + "/get/current_branch", self.state.current_branch)
57+
pub_to_broker("openWB/set/chargepoint/" + str(self.num) + "/get/current_commit", self.state.current_commit)
5558

5659

5760
def get_chargepoint_value_store(id: int) -> ValueStore[ChargepointState]:

packages/modules/common/store/_chargepoint_internal.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ def update(self):
3333
"/get/evse_current", self.state.evse_current, 2)
3434
pub_to_broker("openWB/set/internal_chargepoint/" + str(self.num) +
3535
"/get/max_evse_current", self.state.max_evse_current, 2)
36+
pub_to_broker("openWB/set/internal_chargepoint/" + str(self.num) + "/get/version", self.state.version)
37+
pub_to_broker("openWB/set/internal_chargepoint/" + str(self.num) +
38+
"/get/current_branch", self.state.current_branch)
39+
pub_to_broker("openWB/set/internal_chargepoint/" + str(self.num) +
40+
"/get/current_commit", self.state.current_commit)
3641

3742

3843
def get_internal_chargepoint_value_store(id: int) -> ValueStore[ChargepointState]:

packages/modules/internal_chargepoint_handler/chargepoint_module.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from modules.common.fault_state import ComponentInfo, FaultState
1111
from modules.common.store import get_internal_chargepoint_value_store, get_chargepoint_value_store
1212
from modules.internal_chargepoint_handler.clients import ClientHandler
13+
from helpermodules.subdata import SubData
1314

1415
log = logging.getLogger(__name__)
1516

@@ -54,6 +55,9 @@ def __init__(self, local_charge_point_num: int,
5455
self._client.evse_client.activate_precise_current()
5556
self._precise_current = self._client.evse_client.is_precise_current_active()
5657
self.max_evse_current = self._client.evse_client.get_max_current()
58+
self.version = SubData.system_data["system"].data["version"]
59+
self.current_branch = SubData.system_data["system"].data["current_branch"]
60+
self.current_commit = SubData.system_data["system"].data["current_commit"]
5761

5862
def set_current(self, current: float) -> None:
5963
with SingleComponentUpdateContext(self.fault_state, update_always=False):
@@ -116,7 +120,10 @@ def store_state(chargepoint_state: ChargepointState) -> None:
116120
rfid=last_tag,
117121
evse_current=self.set_current_evse,
118122
serial_number=serial_number,
119-
max_evse_current=self.max_evse_current
123+
max_evse_current=self.max_evse_current,
124+
version=self.version,
125+
current_branch=self.current_branch,
126+
current_commit=self.current_commit
120127
)
121128
if self.client_error_context.error_counter_exceeded():
122129
chargepoint_state = ChargepointState()

packages/modules/internal_chargepoint_handler/update_values_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
@pytest.mark.parametrize(
2626
"old_chargepoint_state, published_topics",
27-
[(None, 44),
27+
[(None, 50),
2828
(OLD_CHARGEPOINT_STATE, 2)]
2929
3030
)

0 commit comments

Comments
 (0)