Skip to content

Commit

Permalink
Modbus 100% test coverage (again) (#100482)
Browse files Browse the repository at this point in the history
  • Loading branch information
janiversen authored Sep 16, 2023
1 parent 48dc81e commit 568974f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/components/modbus/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ async def mock_pymodbus_exception_fixture(hass, do_exception, mock_modbus):
@pytest.fixture(name="mock_pymodbus_return")
async def mock_pymodbus_return_fixture(hass, register_words, mock_modbus):
"""Trigger update call with time_changed event."""
read_result = ReadResult(register_words)
read_result = ReadResult(register_words) if register_words else None
mock_modbus.read_coils.return_value = read_result
mock_modbus.read_discrete_inputs.return_value = read_result
mock_modbus.read_input_registers.return_value = read_result
Expand Down
7 changes: 7 additions & 0 deletions tests/components/modbus/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
CALL_TYPE_WRITE_REGISTERS,
CONF_BAUDRATE,
CONF_BYTESIZE,
CONF_CLOSE_COMM_ON_ERROR,
CONF_DATA_TYPE,
CONF_DEVICE_ADDRESS,
CONF_INPUT_TYPE,
Expand Down Expand Up @@ -413,6 +414,12 @@ async def test_duplicate_entity_validator(do_config) -> None:
@pytest.mark.parametrize(
"do_config",
[
{
CONF_TYPE: TCP,
CONF_HOST: TEST_MODBUS_HOST,
CONF_PORT: TEST_PORT_TCP,
CONF_CLOSE_COMM_ON_ERROR: True,
},
{
CONF_TYPE: TCP,
CONF_HOST: TEST_MODBUS_HOST,
Expand Down
20 changes: 20 additions & 0 deletions tests/components/modbus/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,17 @@ async def test_config_wrong_struct_sensor(
False,
"-1985229329",
),
(
{
CONF_DATA_TYPE: DataType.INT32,
CONF_SCALE: 1,
CONF_OFFSET: 0,
CONF_PRECISION: 0,
},
[0x89AB],
False,
STATE_UNAVAILABLE,
),
(
{
CONF_DATA_TYPE: DataType.UINT32,
Expand Down Expand Up @@ -751,6 +762,15 @@ async def test_all_sensor(hass: HomeAssistant, mock_do_cycle, expected) -> None:
False,
["16909060", "67305985"],
),
(
{
CONF_VIRTUAL_COUNT: 2,
CONF_UNIQUE_ID: SLAVE_UNIQUE_ID,
},
[0x0102, 0x0304, 0x0403, 0x0201, 0x0403],
False,
[STATE_UNAVAILABLE, STATE_UNKNOWN, STATE_UNKNOWN],
),
(
{
CONF_SLAVE_COUNT: 3,
Expand Down

0 comments on commit 568974f

Please sign in to comment.