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 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" 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" 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