diff --git a/packages/modules/devices/generic/json/bat.py b/packages/modules/devices/generic/json/bat.py index 4b2cef9477..5dfc5fe74a 100644 --- a/packages/modules/devices/generic/json/bat.py +++ b/packages/modules/devices/generic/json/bat.py @@ -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, diff --git a/packages/modules/devices/generic/json/config.py b/packages/modules/devices/generic/json/config.py index 430dc0ded8..85228ccaf8 100644 --- a/packages/modules/devices/generic/json/config.py +++ b/packages/modules/devices/generic/json/config.py @@ -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]): @@ -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]): diff --git a/packages/modules/devices/generic/json/counter.py b/packages/modules/devices/generic/json/counter.py index fd925b4558..d8688097d2 100644 --- a/packages/modules/devices/generic/json/counter.py +++ b/packages/modules/devices/generic/json/counter.py @@ -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) diff --git a/packages/modules/devices/generic/json/inverter.py b/packages/modules/devices/generic/json/inverter.py index 7201562bd6..57e9d24440 100644 --- a/packages/modules/devices/generic/json/inverter.py +++ b/packages/modules/devices/generic/json/inverter.py @@ -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)