Skip to content

Commit

Permalink
Merge pull request snaptec#2470 from LKuemmel/json
Browse files Browse the repository at this point in the history
JSON: fix missing queries
  • Loading branch information
LKuemmel authored Oct 27, 2022
2 parents bd00aab + 50bb28b commit 805508e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/modules/json/bat.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def update(self, response) -> None:
else:
soc = 0

if config.jq_imported != "" and config.jq_exported != "":
if config.jq_imported is not None and config.jq_exported is not None:
imported = jq.compile(config.jq_imported).input(response).first()
exported = jq.compile(config.jq_exported).input(response).first()
else:
Expand Down
11 changes: 8 additions & 3 deletions packages/modules/json/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import Optional
from modules.common.component_setup import ComponentSetup


Expand All @@ -19,7 +20,11 @@ def __init__(self,


class JsonBatConfiguration:
def __init__(self, jq_imported=None, jq_exported=None, jq_soc=None, jq_power=None,):
def __init__(self,
jq_imported: Optional[str] = None,
jq_exported: Optional[str] = None,
jq_soc: str = "",
jq_power: str = ""):
self.jq_imported = jq_imported
self.jq_exported = jq_exported
self.jq_soc = jq_soc
Expand All @@ -36,7 +41,7 @@ def __init__(self,


class JsonCounterConfiguration:
def __init__(self, jq_power=None, jq_exported=None, jq_imported=None,):
def __init__(self, jq_power: str = "", jq_exported: Optional[str] = None, jq_imported: Optional[str] = None):
self.jq_power = jq_power
self.jq_exported = jq_exported
self.jq_imported = jq_imported
Expand All @@ -52,7 +57,7 @@ def __init__(self,


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

Expand Down
2 changes: 1 addition & 1 deletion packages/modules/json/counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def update(self, response):

power = jq.compile(config.jq_power).input(response).first()
# ToDo: add current or power per phase
if config.jq_imported == "" or config.jq_exported == "":
if config.jq_exported is None or config.jq_exported is None:
imported, exported = self.__sim_counter.sim_count(power)
else:
imported = jq.compile(config.jq_imported).input(response).first()
Expand Down
6 changes: 4 additions & 2 deletions packages/modules/json/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,16 @@ def read_legacy_bat(ip_address: str, jq_power: str, jq_soc: str):


def read_legacy_counter(ip_address: str, jq_power: str, jq_imported: str, jq_exported: str):
config = JsonCounterConfiguration(jq_power=jq_power, jq_imported=jq_imported, jq_exported=jq_exported)
config = JsonCounterConfiguration(jq_power=jq_power,
jq_imported=None if jq_imported == "" else jq_imported,
jq_exported=None if jq_exported == "" else jq_exported)
read_legacy(
ip_address,
counter.component_descriptor.configuration_factory(id=None, configuration=config))


def read_legacy_inverter(ip_address: str, jq_power: str, jq_exported: str, num: int):
config = JsonInverterConfiguration(jq_power=jq_power, jq_exported=jq_exported)
config = JsonInverterConfiguration(jq_power=jq_power, jq_exported=None if jq_exported == "" else jq_exported)
read_legacy(ip_address, inverter.component_descriptor.configuration_factory(id=num, configuration=config))


Expand Down
2 changes: 1 addition & 1 deletion packages/modules/json/inverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def update(self, response) -> None:
power = float(jq.compile(config.jq_power).input(response).first())
if power >= 0:
power = power * -1
if config.jq_exported == "":
if config.jq_exported is None:
_, exported = self.__sim_counter.sim_count(power)
else:
exported = jq.compile(config.jq_exported).input(response).first()
Expand Down

0 comments on commit 805508e

Please sign in to comment.