Skip to content

Commit

Permalink
Steca: Fix no production
Browse files Browse the repository at this point in the history
  • Loading branch information
LKuemmel committed Aug 22, 2023
1 parent 583e333 commit 1d796f5
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
6 changes: 2 additions & 4 deletions packages/modules/devices/kostal_steca/inverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from typing import Optional, Tuple
import xml.etree.ElementTree as ET
import re
from math import isnan

from modules.common import req
from modules.common.component_state import InverterState
Expand Down Expand Up @@ -38,9 +37,8 @@ def get_values(self) -> Tuple[float, Optional[float]]:

# call for XML file and parse it for current PV power
measurements = req.get_http_session().get("http://" + self.ip_address + "/measurements.xml", timeout=2).text
power = float(ET.fromstring(measurements).find(
".//Measurement[@Type='AC_Power']").get("Value")) * -1
power = 0 if isnan(power) else power
power_raw = ET.fromstring(measurements).find(".//Measurement[@Type='AC_Power']").get("Value")
power = 0 if power_raw is None else float(power_raw) * -1

if self.component_config.configuration.variant_steca:
# call for XML file and parse it for total produced kwh
Expand Down
13 changes: 10 additions & 3 deletions packages/modules/devices/kostal_steca/inverter_test.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import pytest

from modules.devices.kostal_steca.config import KostalStecaInverterSetup
from modules.devices.kostal_steca.inverter import KostalStecaInverter

SAMPLE_IP = "1.1.1.1"


def test_get_values(requests_mock):
@pytest.mark.parametrize("measurements_file, expected_power",
[
pytest.param("measurements_production.xml", -132.8, id="WR produziert"),
pytest.param("measurements_no_production.xml", 0, id="WR produziert nicht"),
])
def test_get_values(measurements_file, expected_power, requests_mock):
# setup
inverter = KostalStecaInverter(KostalStecaInverterSetup(), SAMPLE_IP)

with open("packages/modules/devices/kostal_steca/measurements.xml", "r") as f:
with open("packages/modules/devices/kostal_steca/"+measurements_file, "r") as f:
measurements_sample = f.read()
requests_mock.get("http://" + SAMPLE_IP + "/measurements.xml", text=measurements_sample)

Expand All @@ -20,5 +27,5 @@ def test_get_values(requests_mock):
power, exported = inverter.get_values()

# evaluation
assert power == -132.8
assert power == expected_power
assert exported == 12306056
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<root>
<Device Name="PIKO 3.0-1 MP plus" Type="Inverter" Platform="Net16" HmiPlatform="HMI17" NominalPower="3000" UserPowerLimit="nan" CountryPowerLimit="nan" Serial="xyz" OEMSerial="xyz" BusAddress="1" NetBiosName="INVxyz" WebPortal="PIKO Solar Portal" ManufacturerURL="kostal-solar-electric.com" IpAddress="192.xxx.xxx.xx" DateTime="2022-04-07T08:26:12" MilliSeconds="761">
<Measurements>
<Measurement Value="234.2" Unit="V" Type="AC_Voltage"/>
<Measurement Value="0.566" Unit="A" Type="AC_Current"/>
<Measurement Unit="W" Type="AC_Power"/>
<Measurement Unit="W" Type="AC_Power_fast"/>
<Measurement Value="50.021" Unit="Hz" Type="AC_Frequency"/>
<Measurement Value="416.2" Unit="V" Type="DC_Voltage"/>
<Measurement Value="0.377" Unit="A" Type="DC_Current"/>
<Measurement Value="27.5" Unit="°C" Type="Temp"/>
<Measurement Value="415.8" Unit="V" Type="LINK_Voltage"/>
<Measurement Unit="W" Type="GridPower"/>
<Measurement Unit="W" Type="GridConsumedPower"/>
<Measurement Unit="W" Type="GridInjectedPower"/>
<Measurement Unit="W" Type="OwnConsumedPower"/>
<Measurement Value="100.0" Unit="%" Type="Derating"/>
</Measurements>
</Device>
</root>

0 comments on commit 1d796f5

Please sign in to comment.