Skip to content

Commit

Permalink
phase powers added
Browse files Browse the repository at this point in the history
  • Loading branch information
andlem74 committed Jul 29, 2023
1 parent 65d893c commit 23785fc
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
6 changes: 5 additions & 1 deletion packages/modules/devices/json/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@ 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):

Check failure on line 45 in packages/modules/devices/json/config.py

View workflow job for this annotation

GitHub Actions / build

line too long (122 > 120 characters)
self.jq_power = jq_power
self.jq_exported = jq_exported
self.jq_imported = jq_imported
self.jq_power_l1 = jq_power_l1
self.jq_power_l2 = jq_power_l2
self.jq_power_l3 = jq_power_l3


class JsonCounterSetup(ComponentSetup[JsonCounterConfiguration]):
Expand Down
13 changes: 11 additions & 2 deletions packages/modules/devices/json/counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ def update(self, response):
config = self.component_config.configuration

power = float(jq.compile(config.jq_power).input(response).first())
# ToDo: add current or power per phase

if config.jq_power_l1 is None or config.jq_power_l2 is None or config.jq_power_l3 is None:
powers = None
else:
powers = [float(jq.compile(config.jq_power_l1).input(response).first()),
float(jq.compile(config.jq_power_l2).input(response).first()),
float(jq.compile(config.jq_power_l3).input(response).first())
]

Check warning on line 35 in packages/modules/devices/json/counter.py

View workflow job for this annotation

GitHub Actions / build

blank line contains whitespace
if config.jq_imported is None or config.jq_exported is None:
imported, exported = self.sim_counter.sim_count(power)
else:
Expand All @@ -34,7 +42,8 @@ def update(self, response):
counter_state = CounterState(
imported=imported,
exported=exported,
power=power
power=power,
powers=powers
)
self.store.set(counter_state)

Expand Down
9 changes: 7 additions & 2 deletions packages/modules/devices/json/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,15 @@ def read_legacy_bat(ip_address: str, jq_power: str, jq_soc: str):
read_legacy(ip_address, bat.component_descriptor.configuration_factory(id=None, configuration=config))


def read_legacy_counter(ip_address: str, jq_power: str, jq_imported: str, jq_exported: str):
def read_legacy_counter(ip_address: str, jq_power: str, jq_imported: str, jq_exported: str,

Check warning on line 59 in packages/modules/devices/json/device.py

View workflow job for this annotation

GitHub Actions / build

trailing whitespace
jq_power_l1: str, jq_power_l2: str, jq_power_l3: str):
config = JsonCounterConfiguration(jq_power=jq_power,
jq_imported=None if jq_imported == "" else jq_imported,
jq_exported=None if jq_exported == "" else jq_exported)
jq_exported=None if jq_exported == "" else jq_exported,
jq_power_l1=None if jq_power_l1 == "" else jq_power_l1,
jq_power_l2=None if jq_power_l2 == "" else jq_power_l2,
jq_power_l3=None if jq_power_l3 == "" else jq_power_l3
)
read_legacy(
ip_address,
counter.component_descriptor.configuration_factory(id=None, configuration=config))
Expand Down
20 changes: 20 additions & 0 deletions packages/modules/devices/json/device_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,23 @@ def test_device(monkeypatch, mock_value_store: Mock, requests_mock: requests_moc
# evaluation
assert len(mock_value_store.set.mock_calls) == 1
assert mock_value_store.set.call_args[0][0].power == expected_power


def test_counter_powers(monkeypatch, mock_value_store: Mock, requests_mock: requests_mock.Mocker):
# setup
monkeypatch.setattr(FaultState, "store_error", Mock())
requests_mock.get("http://sample_host/sample_path", json={"power": 42, "power_l1": 11, "power_l2": 12, "power_l3": 13})

Check failure on line 48 in packages/modules/devices/json/device_test.py

View workflow job for this annotation

GitHub Actions / build

line too long (123 > 120 characters)
device_config = Json(configuration=JsonConfiguration("http://sample_host/sample_path"))

# execution
device = create_device(device_config)
device.add_component(JsonCounterSetup(configuration=JsonCounterConfiguration(jq_power=".power",
jq_power_l1=".power_l1",
jq_power_l2=".power_l2",
jq_power_l3=".power_l3")))
device.update()

# evaluation
assert len(mock_value_store.set.mock_calls) == 1
assert mock_value_store.set.call_args[0][0].power == 42
assert mock_value_store.set.call_args[0][0].powers == [11, 12, 13]

0 comments on commit 23785fc

Please sign in to comment.