From 8d8f245a718f755b337ced3a6b13a4e5a99bb414 Mon Sep 17 00:00:00 2001 From: Klaas Schoute Date: Tue, 6 Sep 2022 09:23:41 +0000 Subject: [PATCH] Add alarm_code for JS, HTML and JSON --- README.md | 1 + examples/test_output.py | 1 + omnikinverter/models.py | 6 +++++- tests/fixtures/status.html | 2 +- tests/fixtures/status.json | 6 ++++-- tests/fixtures/status_webdata.js | 2 +- tests/test_models.py | 16 ++++++++++------ 7 files changed, 23 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 680d6698..5653c3dc 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,7 @@ You can read the following data with this package: - Inverter Model - Firmware Version - Main - Firmware Version - Slave +- Alarm Code - Rated Power (W) - Current Power Production (W) - Day Energy Production (kWh) diff --git a/examples/test_output.py b/examples/test_output.py index 91672b2b..7ad2c1b7 100644 --- a/examples/test_output.py +++ b/examples/test_output.py @@ -22,6 +22,7 @@ async def main() -> None: print(f"Firmware Main: {inverter.firmware}") print(f"Firmware Slave: {inverter.firmware_slave}") print(f"Rated Power: {inverter.solar_rated_power}") + print(f"Alarm Code: {inverter.alarm_code}") print(f"Current Power: {inverter.solar_current_power}") print(f"Energy Production Today: {inverter.solar_energy_today}") print(f"Energy Production Total: {inverter.solar_energy_total}") diff --git a/omnikinverter/models.py b/omnikinverter/models.py index e69a29a8..32b8b929 100644 --- a/omnikinverter/models.py +++ b/omnikinverter/models.py @@ -20,6 +20,7 @@ class Inverter: solar_current_power: int | None solar_energy_today: float | None solar_energy_total: float | None + alarm_code: str | None = None # TCP only inverter_active: bool | None = None @@ -77,7 +78,8 @@ def validation(data_list: list[Any]) -> bool: model=get_value("i_modle"), firmware=get_value("i_ver_m"), firmware_slave=get_value("i_ver_s"), - solar_rated_power=get_value("i_pow"), + alarm_code=get_value("i_alarm"), + solar_rated_power=int(get_value("i_pow")), solar_current_power=int(get_value("i_pow_n")), solar_energy_today=float(get_value("i_eday")), solar_energy_total=float(get_value("i_eall")), @@ -117,6 +119,7 @@ def get_value(search_key: str) -> Any: model=get_value("webdata_pv_type"), firmware=get_value("webdata_msvn"), firmware_slave=get_value("webdata_ssvn"), + alarm_code=get_value("webdata_alarm"), solar_rated_power=get_value("webdata_rate_p"), solar_current_power=get_value("webdata_now_p"), solar_energy_today=get_value("webdata_today_e"), @@ -174,6 +177,7 @@ def get_value(position: int) -> Any: model=get_value(3), firmware=get_value(1), firmware_slave=get_value(2), + alarm_code=get_value(8), solar_rated_power=get_value(4), solar_current_power=get_value(5), solar_energy_today=get_value(6), diff --git a/tests/fixtures/status.html b/tests/fixtures/status.html index ed887993..5b301d63 100644 --- a/tests/fixtures/status.html +++ b/tests/fixtures/status.html @@ -1 +1 @@ -var webdata_sn = "12345678910";var webdata_msvn = "V5.07Build245";var webdata_ssvn = "";var webdata_pv_type = "Omnik2500tl ";var webdata_rate_p = "2500";var webdata_now_p = "219";var webdata_today_e = "0.23";var webdata_total_e = "6454.5";var webdata_alarm = "";var webdata_utime = "1";var cover_mid = "902000501";var cover_ver = "ME_08_0102_2.03";var cover_wmode = "";var cover_ap_ssid = "";var cover_ap_ip = "";var cover_ap_mac = "F0FE6B79BA5B";var cover_sta_ssid = "";var cover_sta_rssi = "";var cover_sta_ip = "192.168.0.106";var cover_sta_mac = "F0FE6B79BA5A";var status_a = "1";var status_b = "0";var status_c = "0"; +var webdata_sn = "12345678910";var webdata_msvn = "V5.07Build245";var webdata_ssvn = "";var webdata_pv_type = "Omnik2500tl ";var webdata_rate_p = "2500";var webdata_now_p = "219";var webdata_today_e = "0.23";var webdata_total_e = "6454.5";var webdata_alarm = "F13";var webdata_utime = "1";var cover_mid = "902000501";var cover_ver = "ME_08_0102_2.03";var cover_wmode = "";var cover_ap_ssid = "";var cover_ap_ip = "";var cover_ap_mac = "F0FE6B79BA5B";var cover_sta_ssid = "";var cover_sta_rssi = "";var cover_sta_ip = "192.168.0.106";var cover_sta_mac = "F0FE6B79BA5A";var status_a = "1";var status_b = "0";var status_c = "0"; diff --git a/tests/fixtures/status.json b/tests/fixtures/status.json index f4289d0d..2eadaa9a 100644 --- a/tests/fixtures/status.json +++ b/tests/fixtures/status.json @@ -5,8 +5,10 @@ "i_ver_m":"V1.25Build23261", "i_ver_s":"V1.40Build52927", "i_modle":"omnik2000tl2", - "i_pow":"", + "i_pow":"2000", "i_pow_n":1225, "i_eday":"10.90", - "i_eall":"8674.0" + "i_eall":"8674.0", + "i_alarm":"F23", + "i_last_t":0 } diff --git a/tests/fixtures/status_webdata.js b/tests/fixtures/status_webdata.js index 3e4f931f..09b71614 100644 --- a/tests/fixtures/status_webdata.js +++ b/tests/fixtures/status_webdata.js @@ -1 +1 @@ -var version="H4.01.38Y1.0.09W1.0.08";var m2mRssi="96%";var wanIp="192.168.0.10";var webData="12345678910,NL2-V9.8-5931,V5.3-00157,omnik2000tl2,,1010,488,105319,,4,"; +var version="H4.01.38Y1.0.09W1.0.08";var m2mRssi="96%";var wanIp="192.168.0.10";var webData="12345678910,NL2-V9.8-5931,V5.3-00157,omnik4000tl2,4000,140,30,153637,F13,0,"; diff --git a/tests/test_models.py b/tests/test_models.py index cc84f9dd..018d11cb 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -38,11 +38,12 @@ async def test_inverter_js_webdata(aresponses: ResponsesMockServer) -> None: assert inverter.serial_number == "12345678910" assert inverter.firmware == "NL2-V9.8-5931" assert inverter.firmware_slave == "V5.3-00157" - assert inverter.model == "omnik2000tl2" - assert inverter.solar_rated_power is None - assert inverter.solar_current_power == 1010 - assert inverter.solar_energy_today == 4.88 - assert inverter.solar_energy_total == 10531.9 + assert inverter.model == "omnik4000tl2" + assert inverter.alarm_code == "F13" + assert inverter.solar_rated_power == 4000 + assert inverter.solar_current_power == 140 + assert inverter.solar_energy_today == 0.3 + assert inverter.solar_energy_total == 15363.7 @pytest.mark.asyncio @@ -96,6 +97,7 @@ async def test_inverter_html(aresponses: ResponsesMockServer) -> None: assert inverter.firmware == "V5.07Build245" assert inverter.firmware_slave is None assert inverter.model == "Omnik2500tl" + assert inverter.alarm_code == "F13" assert inverter.solar_rated_power == 2500 assert inverter.solar_current_power == 219 assert inverter.solar_energy_today == 0.23 @@ -157,6 +159,7 @@ async def test_inverter_without_session(aresponses: ResponsesMockServer) -> None assert inverter.firmware == "001F" assert inverter.firmware_slave == "002F" assert inverter.model == "0079" + assert inverter.alarm_code is None assert inverter.solar_rated_power is None assert inverter.solar_current_power == 5850 assert inverter.solar_energy_today == 9.80 @@ -263,7 +266,8 @@ async def test_inverter_json(aresponses: ResponsesMockServer) -> None: assert inverter.firmware == "V1.25Build23261" assert inverter.firmware_slave == "V1.40Build52927" assert inverter.model == "omnik2000tl2" - assert inverter.solar_rated_power is None + assert inverter.alarm_code == "F23" + assert inverter.solar_rated_power == 2000 assert inverter.solar_current_power == 1225 assert inverter.solar_energy_today == 10.90 assert inverter.solar_energy_total == 8674.0