Skip to content

Commit 6c977cc

Browse files
committed
update config
1 parent 758865f commit 6c977cc

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

packages/helpermodules/update_config.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757

5858
class UpdateConfig:
5959

60-
DATASTORE_VERSION = 123
60+
DATASTORE_VERSION = 124
6161

6262
valid_topic = [
6363
"^openWB/bat/config/bat_control_activated$",
@@ -3120,3 +3120,15 @@ def upgrade(topic: str, payload) -> Optional[dict]:
31203120
return {topic: configuration_payload}
31213121
self._loop_all_received_topics(upgrade)
31223122
self._append_datastore_version(123)
3123+
3124+
def upgrade_datastore_124(self) -> None:
3125+
def upgrade(topic: str, payload) -> Optional[dict]:
3126+
if re.search("^openWB/vehicle/[0-9]+/soc_module/config$", topic) is not None:
3127+
configuration_payload = decode_payload(payload)
3128+
if configuration_payload.get("type") == "json":
3129+
json_config = configuration_payload.get("configuration", {})
3130+
if "odometer_pattern" not in json_config:
3131+
json_config["odometer_pattern"] = None
3132+
return {topic: configuration_payload}
3133+
self._loop_all_received_topics(upgrade)
3134+
self._append_datastore_version(124)

packages/helpermodules/update_config_test.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,35 @@ def test_upgrade_datastore_94(index_test_template, expected_index):
5858
assert plan_ids == expected_index
5959

6060

61+
def test_upgrade_datastore_124_adds_missing_odometer_pattern_for_json_soc_module():
62+
update_con = UpdateConfig()
63+
update_con.all_received_topics = {
64+
"openWB/system/datastore_version": list(range(124)),
65+
"openWB/vehicle/0/soc_module/config": {
66+
"type": "json",
67+
"configuration": {
68+
"url": "https://example.invalid/soc",
69+
"soc_pattern": ".soc",
70+
}
71+
},
72+
"openWB/vehicle/1/soc_module/config": {
73+
"type": "homeassistant",
74+
"configuration": {
75+
"url": "http://ha.local"
76+
}
77+
}
78+
}
79+
80+
update_con.upgrade_datastore_124()
81+
82+
json_config = update_con.all_received_topics["openWB/vehicle/0/soc_module/config"]["configuration"]
83+
assert "odometer_pattern" in json_config
84+
assert json_config["odometer_pattern"] is None
85+
86+
ha_config = update_con.all_received_topics["openWB/vehicle/1/soc_module/config"]["configuration"]
87+
assert "odometer_pattern" not in ha_config
88+
89+
6190
@pytest.mark.parametrize("name", [
6291
"happy_path",
6392
"missing_prices_dict",

0 commit comments

Comments
 (0)