diff --git a/README.md b/README.md index 81760039..97293287 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ A python package with which you can read the data from your Omnik Inverter. Keep | Bosswerk | BW-MI300 | HTML | | Bosswerk | BW-MI600 | HTML | | Sofar | 3600TLM | HTML | +| Sofar | 2200TL | JS | | Huayu | HY-600-Pro | HTML | ## Installation diff --git a/omnikinverter/models.py b/omnikinverter/models.py index e69a29a8..af184d9a 100644 --- a/omnikinverter/models.py +++ b/omnikinverter/models.py @@ -155,7 +155,7 @@ def get_value(position: int) -> Any: if matches[position] != "": if position in [4, 5, 6, 7]: if position in [4, 5]: - return int(matches[position]) + return int(matches[position].replace(" ", "")) if position == 6: energy_value = float(matches[position]) / 100 diff --git a/tests/fixtures/status_devicearray_sofar220tl.js b/tests/fixtures/status_devicearray_sofar220tl.js new file mode 100644 index 00000000..32927daf --- /dev/null +++ b/tests/fixtures/status_devicearray_sofar220tl.js @@ -0,0 +1 @@ +var version= "H4.01.51MW.2.01W1.0.64(2018-01-251-D)";var m2mRssi= "39%";var wanIp= "";var myDeviceArray=new Array();myDeviceArray[0]="1234567890 ,V450,,SOFAR2200TL,2 000,400,567,123070,,1,"; diff --git a/tests/test_models.py b/tests/test_models.py index cc84f9dd..6ba1b442 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -218,6 +218,36 @@ async def test_inverter_js_devicearray(aresponses: ResponsesMockServer) -> None: assert inverter.solar_energy_total == 5200.2 +@pytest.mark.asyncio +async def test_inverter_js_devicearray_sofar2200tl( + aresponses: ResponsesMockServer, +) -> None: + """Test request from an SOFAR 2200TL Inverter - JS DeviceArray source.""" + aresponses.add( + "example.com", + "/js/status.js", + "GET", + aresponses.Response( + status=200, + headers={"Content-Type": "application/x-javascript"}, + text=load_fixtures("status_devicearray_sofar220tl.js"), + ), + ) + + async with aiohttp.ClientSession() as session: + client = OmnikInverter(host="example.com", session=session) + inverter: Inverter = await client.inverter() + assert inverter + assert inverter.serial_number == "1234567890" + assert inverter.firmware == "V450" + assert inverter.firmware_slave is None + assert inverter.model == "SOFAR2200TL" + assert inverter.solar_rated_power == 2000 + assert inverter.solar_current_power == 400 + assert inverter.solar_energy_today == 5.67 + assert inverter.solar_energy_total == 12307.0 + + @pytest.mark.asyncio async def test_device_js_devicearray(aresponses: ResponsesMockServer) -> None: """Test request from a Device - JS DeviceArray source."""