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
33 changes: 19 additions & 14 deletions packages/modules/devices/generic/json/bat.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,36 @@ def __init__(self, component_config: JsonBatSetup, **kwargs: Any) -> None:
self.component_config = component_config
self.kwargs: KwargsDict = kwargs

def _compile_jq_filters(self) -> None:
config = self.component_config.configuration
self.jq_power = jq.compile(config.jq_power)
self.jq_soc = jq.compile(config.jq_soc) if config.jq_soc else None
self.jq_currents = [jq.compile(c) for c in config.jq_currents] if all(config.jq_currents) else []
self.jq_imported = jq.compile(config.jq_imported) if config.jq_imported else None
self.jq_exported = jq.compile(config.jq_exported) if config.jq_exported else None

def initialize(self) -> None:
self.__device_id: int = self.kwargs['device_id']
self.sim_counter = SimCounter(self.__device_id, self.component_config.id, prefix="speicher")
self.store = get_bat_value_store(self.component_config.id)
self._compile_jq_filters()
self.fault_state = FaultState(ComponentInfo.from_component_config(self.component_config))

def update(self, response) -> None:
config = self.component_config.configuration
currents = (
[float(j.input(response).first()) for j in self.jq_currents]
if len(self.jq_currents) == 3 else None
)

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(self.jq_power.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())
else:
soc = 0
soc = float(self.jq_soc.input(response).first()) if self.jq_soc else 0

if config.jq_imported is not None and config.jq_exported is not None:
imported = float(jq.compile(config.jq_imported).input(response).first())
exported = float(jq.compile(config.jq_exported).input(response).first())
else:
if self.jq_imported is None or self.jq_exported is None:
imported, exported = self.sim_counter.sim_count(power)
else:
imported = float(self.jq_imported.input(response).first())
exported = float(self.jq_exported.input(response).first())

bat_state = BatState(
currents=currents,
Expand Down
23 changes: 20 additions & 3 deletions packages/modules/devices/generic/json/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,29 @@ def __init__(self,


class JsonCounterConfiguration:
def __init__(self, jq_power: str = "", jq_exported: Optional[str] = None, jq_imported: Optional[str] = None,
def __init__(self,
jq_power: str = "",
jq_exported: Optional[str] = None,
jq_imported: Optional[str] = None,
jq_power_l1: Optional[str] = None,
jq_power_l2: Optional[str] = None,
jq_power_l3: Optional[str] = None,
jq_power_factor_l1: Optional[str] = None,
jq_power_factor_l2: Optional[str] = None,
jq_power_factor_l3: Optional[str] = None,
jq_current_l1: Optional[str] = None,
jq_current_l2: Optional[str] = None,
jq_current_l3: Optional[str] = None):
jq_current_l3: Optional[str] = None,
jq_voltage_l1: Optional[str] = None,
jq_voltage_l2: Optional[str] = None,
jq_voltage_l3: Optional[str] = None):
self.jq_power = jq_power
self.jq_exported = jq_exported
self.jq_imported = jq_imported
self.jq_powers = (jq_power_l1, jq_power_l2, jq_power_l3)
self.jq_power_factors = (jq_power_factor_l1, jq_power_factor_l2, jq_power_factor_l3)
self.jq_currents = (jq_current_l1, jq_current_l2, jq_current_l3)
self.jq_voltages = (jq_voltage_l1, jq_voltage_l2, jq_voltage_l3)


class JsonCounterSetup(ComponentSetup[JsonCounterConfiguration]):
Expand All @@ -72,9 +83,15 @@ def __init__(self,


class JsonInverterConfiguration:
def __init__(self, jq_power: str = "", jq_exported: Optional[str] = None):
def __init__(self,
jq_power: str = "",
jq_exported: Optional[str] = None,
jq_current_l1: Optional[str] = None,
jq_current_l2: Optional[str] = None,
jq_current_l3: Optional[str] = None):
self.jq_power = jq_power
self.jq_exported = jq_exported
self.jq_currents = (jq_current_l1, jq_current_l2, jq_current_l3)


class JsonInverterSetup(ComponentSetup[JsonInverterConfiguration]):
Expand Down
50 changes: 36 additions & 14 deletions packages/modules/devices/generic/json/counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,61 @@ def __init__(self, component_config: JsonCounterSetup, **kwargs: Any) -> None:
self.component_config = component_config
self.kwargs: KwargsDict = kwargs

def _compile_jq_filters(self) -> None:
config = self.component_config.configuration
self.jq_power = jq.compile(config.jq_power)
self.jq_powers = [jq.compile(p) for p in config.jq_powers] if all(config.jq_powers) else None
self.jq_power_factors = [
jq.compile(pf) for pf in config.jq_power_factors] if all(config.jq_power_factors) else None
self.jq_currents = [jq.compile(c) for c in config.jq_currents] if all(config.jq_currents) else None
self.jq_voltages = [jq.compile(v) for v in config.jq_voltages] if all(config.jq_voltages) else None
self.jq_imported = jq.compile(config.jq_imported) if config.jq_imported else None
self.jq_exported = jq.compile(config.jq_exported) if config.jq_exported else None

def initialize(self) -> None:
self.__device_id: int = self.kwargs['device_id']
self.sim_counter = SimCounter(self.__device_id, self.component_config.id, prefix="bezug")
self.store = get_counter_value_store(self.component_config.id)
self._compile_jq_filters()
self.fault_state = FaultState(ComponentInfo.from_component_config(self.component_config))

def update(self, response) -> None:
config = self.component_config.configuration
power = float(self.jq_power.input(response).first())

power = float(jq.compile(config.jq_power).input(response).first())
powers = (
[float(j.input(response).first()) for j in self.jq_powers]
if self.jq_powers is not None else None
)

if all(config.jq_powers):
powers = [float(jq.compile(p).input(response).first()) for p in config.jq_powers]
else:
powers = None
currents = (
[float(j.input(response).first()) for j in self.jq_currents]
if self.jq_currents is not None else None
)

if all(config.jq_currents):
currents = [float(jq.compile(c).input(response).first()) for c in config.jq_currents]
else:
currents = None
power_factors = (
[float(j.input(response).first()) for j in self.jq_power_factors]
if self.jq_power_factors is not None else None
)

voltages = (
[float(j.input(response).first()) for j in self.jq_voltages]
if self.jq_voltages is not None else None
)

if config.jq_imported is None or config.jq_exported is None:
if self.jq_imported is None or self.jq_exported is None:
imported, exported = self.sim_counter.sim_count(power)
else:
imported = float(jq.compile(config.jq_imported).input(response).first())
exported = float(jq.compile(config.jq_exported).input(response).first())
imported = float(self.jq_imported.input(response).first())
exported = float(self.jq_exported.input(response).first())

counter_state = CounterState(
imported=imported,
exported=exported,
power=power,
powers=powers,
currents=currents
currents=currents,
power_factors=power_factors,
voltages=voltages
)
self.store.set(counter_state)

Expand Down
24 changes: 18 additions & 6 deletions packages/modules/devices/generic/json/inverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,38 @@ def __init__(self, component_config: JsonInverterSetup, **kwargs: Any) -> None:
self.component_config = component_config
self.kwargs: KwargsDict = kwargs

def _compile_jq_filters(self) -> None:
config = self.component_config.configuration
self.jq_power = jq.compile(config.jq_power)
self.jq_exported = jq.compile(config.jq_exported) if config.jq_exported else None
self.jq_currents = [jq.compile(c) for c in config.jq_currents] if all(config.jq_currents) else None

def initialize(self) -> None:
self.__device_id: int = self.kwargs['device_id']
self.sim_counter = SimCounter(self.__device_id, self.component_config.id, prefix="pv")
self.store = get_inverter_value_store(self.component_config.id)
self._compile_jq_filters()
self.fault_state = FaultState(ComponentInfo.from_component_config(self.component_config))

def update(self, response) -> None:
config = self.component_config.configuration

power = float(jq.compile(config.jq_power).input(response).first())
power = float(self.jq_power.input(response).first())
if power >= 0:
power = power * -1
if config.jq_exported is None:

currents = (
[float(j.input(response).first()) for j in self.jq_currents]
if self.jq_currents is not None else None
)

if self.jq_exported is None:
_, exported = self.sim_counter.sim_count(power)
else:
exported = float(jq.compile(config.jq_exported).input(response).first())
exported = float(self.jq_exported.input(response).first())

inverter_state = InverterState(
power=power,
exported=exported
exported=exported,
currents=currents
)
self.store.set(inverter_state)

Expand Down