Skip to content
Merged
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
21 changes: 20 additions & 1 deletion packages/helpermodules/update_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

class UpdateConfig:

DATASTORE_VERSION = 85
DATASTORE_VERSION = 86

valid_topic = [
"^openWB/bat/config/configured$",
Expand Down Expand Up @@ -2307,3 +2307,22 @@ def cp_upgrade(topic: str, payload) -> Optional[dict]:
self._loop_all_received_topics(upgrade)
self._loop_all_received_topics(cp_upgrade)
self.__update_topic("openWB/system/datastore_version", 85)

def upgrade_datastore_85(self) -> None:
def upgrade(topic: str, payload) -> None:
if re.search("openWB/system/device/[0-9]+", topic) is not None:
payload = decode_payload(payload)
index = get_index(topic)
if payload.get("type") == "good_we":
for component_topic, component_payload in self.all_received_topics.items():
if re.search(f"openWB/system/device/{index}/component/[0-9]+/config",
component_topic) is not None:
config_payload = decode_payload(component_payload)
if (config_payload["type"] == "bat" and
config_payload["configuration"].get("battery_index") is None):
config_payload["configuration"].update({
"battery_index": 1,
})
return {component_topic: config_payload}
self._loop_all_received_topics(upgrade)
self.__update_topic("openWB/system/datastore_version", 86)
24 changes: 17 additions & 7 deletions packages/modules/devices/good_we/good_we/bat.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from modules.common.component_type import ComponentDescriptor
from modules.common.modbus import ModbusDataType
from modules.common.fault_state import ComponentInfo, FaultState
from modules.common.simcount import SimCounter
from modules.common.store import get_bat_value_store
from modules.devices.good_we.good_we.config import GoodWeBatSetup
from modules.devices.good_we.good_we.version import GoodWeVersion
Expand All @@ -29,20 +30,29 @@ def initialize(self) -> None:
self.version: GoodWeVersion = self.kwargs['version']
self.firmware: int = self.kwargs['firmware']
self.__tcp_client: modbus.ModbusTcpClient_ = self.kwargs['client']
self.sim_counter = SimCounter(self.__device_id, self.component_config.id, prefix="speicher")
self.store = get_bat_value_store(self.component_config.id)
self.fault_state = FaultState(ComponentInfo.from_component_config(self.component_config))

def update(self) -> None:
battery_index = getattr(self.component_config.configuration, "battery_index", 1)
with self.__tcp_client:
if self.version == GoodWeVersion.V_1_7:
power = self.__tcp_client.read_holding_registers(35183, ModbusDataType.INT_16, unit=self.__modbus_id)*-1
if battery_index == 1:
if self.version == GoodWeVersion.V_1_7:
power = self.__tcp_client.read_holding_registers(
35183, ModbusDataType.INT_16, unit=self.__modbus_id)*-1
else:
power = self.__tcp_client.read_holding_registers(
35182, ModbusDataType.INT_32, unit=self.__modbus_id)*-1
soc = self.__tcp_client.read_holding_registers(37007, ModbusDataType.UINT_16, unit=self.__modbus_id)
imported = self.__tcp_client.read_holding_registers(
35206, ModbusDataType.UINT_32, unit=self.__modbus_id) * 100
exported = self.__tcp_client.read_holding_registers(
35209, ModbusDataType.UINT_32, unit=self.__modbus_id) * 100
else:
power = self.__tcp_client.read_holding_registers(35182, ModbusDataType.INT_32, unit=self.__modbus_id)*-1
soc = self.__tcp_client.read_holding_registers(37007, ModbusDataType.UINT_16, unit=self.__modbus_id)
imported = self.__tcp_client.read_holding_registers(
35206, ModbusDataType.UINT_32, unit=self.__modbus_id) * 100
exported = self.__tcp_client.read_holding_registers(
35209, ModbusDataType.UINT_32, unit=self.__modbus_id) * 100
soc = self.__tcp_client.read_holding_registers(37007, ModbusDataType.UINT_16, unit=self.__modbus_id)
imported, exported = self.sim_counter.sim_count(power)

bat_state = BatState(
power=power,
Expand Down