Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed nan handling for Piko 3.6 MP #1145

Merged
merged 3 commits into from
Oct 6, 2023
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
2 changes: 2 additions & 0 deletions packages/modules/devices/kostal_steca/inverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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 @@ -39,6 +40,7 @@ def get_values(self) -> Tuple[float, Optional[float]]:
measurements = req.get_http_session().get("http://" + self.ip_address + "/measurements.xml", timeout=2).text
power_raw = ET.fromstring(measurements).find(".//Measurement[@Type='AC_Power']").get("Value")
power = 0 if power_raw is None else float(power_raw) * -1
power = 0 if isnan(power) else power

if self.component_config.configuration.variant_steca:
# call for XML file and parse it for total produced kwh
Expand Down
2 changes: 2 additions & 0 deletions packages/modules/devices/kostal_steca/inverter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
[
pytest.param("measurements_production.xml", -132.8, id="WR produziert"),
pytest.param("measurements_no_production.xml", 0, id="WR produziert nicht"),
pytest.param("measurements_no_production_piko3p6mp.xml", 0,
id="WR produziert nicht, Piko 3.6 MP"),
])
def test_get_values(measurements_file, expected_power, requests_mock):
# setup
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version='1.0' encoding='UTF-8'?><root><Device Name='PIKO 3.6 MP' Type='Inverter' Serial='755810BL006202240015' BusAddress='1' NetBiosName='INV006202240015' IpAddress='192.168.188.27' DateTime='2023-09-29T19:12:32'><Measurements><Measurement Value='231.298' Unit='V' Type='AC_Voltage'/><Measurement Value='-nan' Unit='A' Type='AC_Current'/><Measurement Value='-nan' Unit='W' Type='AC_Power'/><Measurement Value='50.014' Unit='Hz' Type='AC_Frequency'/><Measurement Value='258.676' Unit='V' Type='DC_Voltage'/><Measurement Value='-nan' Unit='A' Type='DC_Current'/><Measurement Value='-nan' Unit='W' Type='DC_Power'/><Measurement Value='-nan' Unit='&#176;C' Type='Temp'/><Measurement Value='nan' Unit='W' Type='Consumption PV'/><Measurement Value='nan' Unit='W' Type='Consumption Grid'/><Measurement Value='nan' Unit='W' Type='GridPower'/><Measurement Value='100.0' Unit='%' Type='Dearting'/></Measurements></Device></root>