Skip to content

Commit f5af15c

Browse files
authored
generic soc modules http, mqtt: add calculate soc option (#3036)
1 parent e666539 commit f5af15c

5 files changed

Lines changed: 24 additions & 6 deletions

File tree

packages/helpermodules/update_config.py

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

5858
class UpdateConfig:
5959

60-
DATASTORE_VERSION = 105
60+
DATASTORE_VERSION = 106
6161

6262
valid_topic = [
6363
"^openWB/bat/config/bat_control_permitted$",
@@ -2679,3 +2679,13 @@ def upgrade(topic: str, payload) -> None:
26792679
return {topic: config}
26802680
self._loop_all_received_topics(upgrade)
26812681
self._append_datastore_version(105)
2682+
2683+
def upgrade_datastore_106(self) -> None:
2684+
def upgrade(topic: str, payload) -> None:
2685+
if re.search("openWB/vehicle/[0-9]+/soc_module/config", topic) is not None:
2686+
config = decode_payload(payload)
2687+
if config.get("type") == "http" or config.get("type") == "mqtt":
2688+
config["configuration"]["calculate_soc"] = False
2689+
return {topic: config}
2690+
self._loop_all_received_topics(upgrade)
2691+
self._append_datastore_version(106)

packages/modules/vehicles/http/config.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33

44
@auto_str
55
class HttpSocConfiguration:
6-
def __init__(self, soc_url=None, range_url=None):
6+
def __init__(self, soc_url=None,
7+
range_url=None,
8+
calculate_soc: bool = False):
79
self.soc_url = soc_url
810
self.range_url = range_url
11+
self.calculate_soc = calculate_soc
912

1013

1114
@auto_str

packages/modules/vehicles/http/soc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ def fetch_soc(config: HttpSocSetup) -> CarState:
3535
def create_vehicle(vehicle_config: HttpSocSetup, vehicle: int):
3636
def updater(vehicle_update_data: VehicleUpdateData) -> CarState:
3737
return fetch_soc(vehicle_config)
38-
return ConfigurableVehicle(vehicle_config=vehicle_config, component_updater=updater, vehicle=vehicle)
38+
return ConfigurableVehicle(vehicle_config=vehicle_config,
39+
component_updater=updater,
40+
vehicle=vehicle,
41+
calc_while_charging=vehicle_config.configuration.calculate_soc)
3942

4043

4144
def http_update(soc_url: str, range_url: str, charge_point: int):

packages/modules/vehicles/mqtt/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class MqttSocConfiguration:
2-
def __init__(self):
3-
pass
2+
def __init__(self, calculate_soc: bool = False):
3+
self.calculate_soc = calculate_soc
44

55

66
class MqttSocSetup:

packages/modules/vehicles/mqtt/soc.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ def on_message(client, userdata, message):
3737
"Einstellungen beachten.")
3838
return None
3939
configurable_vehicle = ConfigurableVehicle(vehicle_config=vehicle_config,
40-
component_updater=updater, vehicle=vehicle)
40+
component_updater=updater,
41+
vehicle=vehicle,
42+
calc_while_charging=vehicle_config.configuration.calculate_soc)
4143
return configurable_vehicle
4244

4345

0 commit comments

Comments
 (0)