From 7c060c065888ccdd4599e9d38507702f0029ac7d Mon Sep 17 00:00:00 2001 From: WillCodeForCats <48533968+WillCodeForCats@users.noreply.github.com> Date: Tue, 18 Aug 2026 13:29:34 -0700 Subject: [PATCH 1/5] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index f0ccd54e..f8c2f2a0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .DS_Store solaredge-modbus-multi.bbprojectd /megalinter-reports +*.pyc From cc44c498f8901b3699c00d173b120083a75abefc Mon Sep 17 00:00:00 2001 From: WillCodeForCats <48533968+WillCodeForCats@users.noreply.github.com> Date: Tue, 18 Aug 2026 13:34:03 -0700 Subject: [PATCH 2/5] Fix incorrect use of 'or' comparison for ipaddress --- custom_components/solaredge_modbus_multi/helpers.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/custom_components/solaredge_modbus_multi/helpers.py b/custom_components/solaredge_modbus_multi/helpers.py index 92b4e0f0..7ca394e9 100644 --- a/custom_components/solaredge_modbus_multi/helpers.py +++ b/custom_components/solaredge_modbus_multi/helpers.py @@ -51,9 +51,7 @@ def update_accum(self, accum_value: int) -> None: def host_valid(host): """Return True if hostname or IP address is valid.""" try: - if ipaddress.ip_address(host).version == (4 or 6): - return True - + return ipaddress.ip_address(host).version in (4, 6) except ValueError: return DOMAIN_REGEX.match(host) From 708eaade84240663bf8415ae8a8a793c84d657ae Mon Sep 17 00:00:00 2001 From: WillCodeForCats <48533968+WillCodeForCats@users.noreply.github.com> Date: Tue, 18 Aug 2026 13:38:03 -0700 Subject: [PATCH 3/5] Add pytest-homeassistant-custom-component --- requirements-test.txt | 2 ++ tests/conftest.py | 3 +++ 2 files changed, 5 insertions(+) create mode 100644 tests/conftest.py diff --git a/requirements-test.txt b/requirements-test.txt index 582ad801..2a2093f4 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,2 +1,4 @@ pytest>=8.0.0 awesomeversion>=25.5.0 +pymodbus>=3.8.3 +pytest-homeassistant-custom-component>=0.13.0 diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 00000000..79a6b013 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,3 @@ +"""Activate pytest-homeassistant-custom-component for all tests.""" + +pytest_plugins = "pytest_homeassistant_custom_component" From 1f06b143b76394cc2151cca154e2d09f85ae615a Mon Sep 17 00:00:00 2001 From: WillCodeForCats <48533968+WillCodeForCats@users.noreply.github.com> Date: Tue, 18 Aug 2026 13:38:11 -0700 Subject: [PATCH 4/5] Update pyproject.toml --- pyproject.toml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index a8b297ce..5224e1ac 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,3 +4,8 @@ line-length = 88 [tool.ruff.lint] extend-select = ["I"] ignore = ["E701"] + +[tool.pytest.ini_options] +testpaths = ["tests"] +pythonpath = ["."] +asyncio_mode = "auto" From b76ee18f7be8fa134136789e566e23cf7e53ae82 Mon Sep 17 00:00:00 2001 From: WillCodeForCats <48533968+WillCodeForCats@users.noreply.github.com> Date: Tue, 18 Aug 2026 13:42:01 -0700 Subject: [PATCH 5/5] Create test_sensor_scale_factor.py --- tests/test_sensor_scale_factor.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tests/test_sensor_scale_factor.py diff --git a/tests/test_sensor_scale_factor.py b/tests/test_sensor_scale_factor.py new file mode 100644 index 00000000..e4f5df64 --- /dev/null +++ b/tests/test_sensor_scale_factor.py @@ -0,0 +1,19 @@ +"""Tests for SolarEdgeSensorBase.scale_factor in sensor.py.""" + +import pytest + +from custom_components.solaredge_modbus_multi.sensor import SolarEdgeSensorBase + + +@pytest.mark.parametrize( + "value, sf, expected", + [ + (100, -2, 1.0), + (500, 1, 5000), + (0, -3, 0.0), + (-250, -1, -25.0), + (1, 0, 1), + ], +) +def test_scale_factor(value, sf, expected): + assert SolarEdgeSensorBase.scale_factor(None, value, sf) == expected