diff --git a/tests/components/modbus/conftest.py b/tests/components/modbus/conftest.py index 460b1eb5dd3..d7e4556f746 100644 --- a/tests/components/modbus/conftest.py +++ b/tests/components/modbus/conftest.py @@ -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 diff --git a/tests/components/modbus/test_init.py b/tests/components/modbus/test_init.py index f9c7fb42b2d..5f8c0554e6d 100644 --- a/tests/components/modbus/test_init.py +++ b/tests/components/modbus/test_init.py @@ -40,6 +40,7 @@ from homeassistant.components.modbus.const import ( CALL_TYPE_WRITE_REGISTERS, CONF_BAUDRATE, CONF_BYTESIZE, + CONF_CLOSE_COMM_ON_ERROR, CONF_DATA_TYPE, CONF_DEVICE_ADDRESS, CONF_INPUT_TYPE, @@ -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, diff --git a/tests/components/modbus/test_sensor.py b/tests/components/modbus/test_sensor.py index 46c38873a93..0f79a125c86 100644 --- a/tests/components/modbus/test_sensor.py +++ b/tests/components/modbus/test_sensor.py @@ -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, @@ -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,