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
5 changes: 3 additions & 2 deletions packages/helpermodules/setdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,8 +693,7 @@ def process_pv_topic(self, msg: mqtt.MQTTMessage):
elif "/get/power" in msg.topic:
self._validate_value(msg, float)
elif "/get/currents" in msg.topic:
self._validate_value(
msg, float, collection=list)
self._validate_value(msg, float, collection=list)
else:
self.__unknown_topic(msg)
else:
Expand Down Expand Up @@ -743,6 +742,8 @@ def process_bat_topic(self, msg: mqtt.MQTTMessage):
"/get/daily_exported" in msg.topic or
"/get/daily_imported" in msg.topic):
self._validate_value(msg, float, [(0, float("inf"))])
elif "/get/currents" in msg.topic:
self._validate_value(msg, float, collection=list)
elif "/get/soc" in msg.topic:
self._validate_value(msg, float, [(0, 100)])
elif "/get/fault_state" in msg.topic:
Expand Down
7 changes: 7 additions & 0 deletions packages/modules/common/component_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def __init__(
exported: float = 0,
power: float = 0,
soc: float = 0,
currents: Optional[List[float]] = None,
):
"""Args:
imported: total imported energy in Wh
Expand All @@ -67,6 +68,12 @@ def __init__(
self.exported = exported
self.power = power
self.soc = soc
if _check_none(currents):
currents = [0.0]*3
else:
if not ((sum(currents) < 0 and power < 0) or (sum(currents) > 0 and power > 0)):
log.debug("currents sign wrong "+str(currents))
self.currents = currents


@auto_str
Expand Down
1 change: 1 addition & 0 deletions packages/modules/common/store/_battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def set(self, bat_state: BatState):

def update(self):
try:
pub_to_broker("openWB/set/bat/"+str(self.num)+"/get/currents", self.state.currents, 2)
pub_to_broker("openWB/set/bat/"+str(self.num)+"/get/power", self.state.power, 2)
pub_to_broker("openWB/set/bat/"+str(self.num)+"/get/soc", self.state.soc, 0)
pub_to_broker("openWB/set/bat/"+str(self.num)+"/get/imported", self.state.imported, 2)
Expand Down
8 changes: 7 additions & 1 deletion packages/modules/devices/generic/http/bat.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
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.generic.http.api import create_request_function
from modules.devices.generic.http.api import create_request_function, create_request_function_array
from modules.devices.generic.http.config import HttpBatSetup


Expand All @@ -29,6 +29,11 @@ def initialize(self) -> None:
self.store = get_bat_value_store(self.component_config.id)
self.fault_state = FaultState(ComponentInfo.from_component_config(self.component_config))

self.__get_currents = create_request_function_array(self.kwargs['url'], [
self.component_config.configuration.current_l1_path,
self.component_config.configuration.current_l2_path,
self.component_config.configuration.current_l3_path,
])
self.__get_power = create_request_function(self.kwargs['url'], self.component_config.configuration.power_path)
self.__get_imported = create_request_function(
self.kwargs['url'], self.component_config.configuration.imported_path)
Expand All @@ -44,6 +49,7 @@ def update(self, session: Session) -> None:
imported, exported = self.sim_counter.sim_count(power)

bat_state = BatState(
currents=self.__get_currents(session),
power=power,
exported=exported,
imported=imported,
Expand Down
11 changes: 10 additions & 1 deletion packages/modules/devices/generic/http/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,18 @@ def __init__(self,

@auto_str
class HttpBatConfiguration:
def __init__(self, power_path=None, soc_path=None, imported_path=None, exported_path=None):
def __init__(self, power_path=None,
soc_path=None,
current_l1_path=None,
current_l2_path=None,
current_l3_path=None,
imported_path=None,
exported_path=None):
self.power_path = power_path
self.soc_path = soc_path
self.current_l1_path = current_l1_path
self.current_l2_path = current_l2_path
self.current_l3_path = current_l3_path
self.imported_path = imported_path
self.exported_path = exported_path

Expand Down
6 changes: 6 additions & 0 deletions packages/modules/devices/generic/json/bat.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ def initialize(self) -> None:
def update(self, response) -> None:
config = self.component_config.configuration

currents = [0] * 3
for i, c in enumerate(config.jq_currents):
if c is not None:
currents[i] = float(jq.compile(c).input(response).first())

power = float(jq.compile(config.jq_power).input(response).first())
if config.jq_soc != "":
soc = float(jq.compile(config.jq_soc).input(response).first())
Expand All @@ -42,6 +47,7 @@ def update(self, response) -> None:
imported, exported = self.sim_counter.sim_count(power)

bat_state = BatState(
currents=currents,
power=power,
soc=soc,
imported=imported,
Expand Down
4 changes: 4 additions & 0 deletions packages/modules/devices/generic/json/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ def __init__(self,

class JsonBatConfiguration:
def __init__(self,
jq_current_l1: Optional[str] = None,
jq_current_l2: Optional[str] = None,
jq_current_l3: Optional[str] = None,
jq_imported: Optional[str] = None,
jq_exported: Optional[str] = None,
jq_soc: str = "",
jq_power: str = ""):
self.jq_currents = (jq_current_l1, jq_current_l2, jq_current_l3)
self.jq_imported = jq_imported
self.jq_exported = jq_exported
self.jq_soc = jq_soc
Expand Down
2 changes: 2 additions & 0 deletions packages/modules/devices/generic/mqtt/bat.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def initialize(self) -> None:
self.store = get_bat_value_store(self.component_config.id)

def update(self, received_topics: Dict) -> None:
currents = received_topics.get(f"openWB/mqtt/bat/{self.component_config.id}/get/currents")
power = received_topics.get(f"openWB/mqtt/bat/{self.component_config.id}/get/power")
soc = received_topics.get(f"openWB/mqtt/bat/{self.component_config.id}/get/soc")
if (received_topics.get(f"openWB/mqtt/bat/{self.component_config.id}/get/imported") and
Expand All @@ -36,6 +37,7 @@ def update(self, received_topics: Dict) -> None:
imported, exported = self.sim_counter.sim_count(power)

bat_state = BatState(
currents=currents,
power=power,
soc=soc,
imported=imported,
Expand Down
10 changes: 10 additions & 0 deletions packages/modules/devices/openwb/openwb_flex/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.fault_state import ComponentInfo, FaultState
from modules.common.lovato import Lovato
from modules.common.mpm3pm import Mpm3pm
from modules.common.sdm import Sdm120
from modules.common.sdm import Sdm630_72
from modules.common.simcount import SimCounter
Expand Down Expand Up @@ -49,7 +50,16 @@ def update(self):
imported = self.__client.get_imported()
exported = self.__client.get_exported()

voltages = self.__client.get_voltages()
powers, power = self.__client.get_power()

if isinstance(self.__client, Mpm3pm):
currents = [powers[i] / voltages[i] for i in range(3)]
else:
currents = self.__client.get_currents()

bat_state = BatState(
currents=currents,
imported=imported,
exported=exported,
power=power
Expand Down